Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal Report Viewer: host and use the the report viewer locally #1176

Merged
merged 55 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
fd89367
Testing local report viewer
dfuchss Jul 5, 2023
739fa34
Update to Java JDK 20
dfuchss Jul 16, 2023
6807daf
Merge branch 'develop' into feature/internal-web-viewer
dfuchss Jul 16, 2023
a52b059
Merge branch 'develop' into feature/internal-web-viewer
tsaglam Sep 29, 2023
5d2c8df
Implemented routing for internal report viewer.
TwoOfTwelve Oct 12, 2023
7e2d1bd
Implemented server side for local mode.
TwoOfTwelve Oct 12, 2023
e27f632
Fixed 404 response codes for local mode.
TwoOfTwelve Oct 12, 2023
3085de0
frontend logic for local mode
Kr0nox Oct 12, 2023
0defe37
Removed accidental changes from package.json
TwoOfTwelve Oct 12, 2023
5a27848
remove unneeded dependencies
Kr0nox Oct 16, 2023
3a5b0be
Merge remote-tracking branch 'origin/develop' into feature/internal-w…
Kr0nox Oct 16, 2023
853ff7f
Changed local report viewer to return index html for every path, that…
TwoOfTwelve Oct 18, 2023
c794eff
Merge remote-tracking branch 'origin/feature/internal-web-viewer' int…
TwoOfTwelve Oct 18, 2023
4c8ea19
Fixed small error for local mode.
TwoOfTwelve Oct 18, 2023
30ac721
fix new tabs on comparison
Kr0nox Oct 21, 2023
288716f
Moved compiling the report-viewer into a profile.
TwoOfTwelve Oct 31, 2023
d65afab
Merge remote-tracking branch 'origin/feature/internal-web-viewer' int…
TwoOfTwelve Oct 31, 2023
e9f902d
fix tests
Kr0nox Nov 8, 2023
e36eb01
Merge remote-tracking branch 'origin/develop' into feature/internal-w…
Kr0nox Nov 30, 2023
4f055d0
fix report viewer build
Kr0nox Nov 30, 2023
daede42
fix new tabs
Kr0nox Nov 30, 2023
71d094c
Added javadoc to internal report viewer and moved the resource declar…
TwoOfTwelve Dec 1, 2023
a207694
Added logging for not existing resource url.
TwoOfTwelve Dec 5, 2023
dc58ad6
Merge branch 'develop' into feature/internal-web-viewer
dfuchss Dec 6, 2023
31b818b
Changed port to 1996.
TwoOfTwelve Dec 11, 2023
aadeae3
Merge remote-tracking branch 'origin/feature/internal-web-viewer' int…
TwoOfTwelve Dec 11, 2023
f9d32d2
Merge remote-tracking branch 'origin/develop' into feature/internal-w…
Kr0nox Dec 11, 2023
10a9453
Added port option for internal report viewer
TwoOfTwelve Dec 12, 2023
3c84512
Merge remote-tracking branch 'origin/feature/internal-web-viewer' int…
TwoOfTwelve Dec 12, 2023
e4fa97f
Merge remote-tracking branch 'origin/develop' into feature/internal-w…
dfuchss Dec 14, 2023
86f0716
Build report viewer only if needed.
dfuchss Dec 14, 2023
b69cd36
Merge branch 'develop' into feature/internal-web-viewer
TwoOfTwelve Jan 23, 2024
52bf30b
fix prettier
Kr0nox Jan 23, 2024
1dcc4b5
fix loading index html file
Kr0nox Jan 23, 2024
4b9c925
file name in tab
Kr0nox Jan 23, 2024
d4920db
fix anonymous propagation
Kr0nox Jan 23, 2024
7956543
Fixed some minor code style issues in the internal report viewer.
TwoOfTwelve Feb 6, 2024
ab6ae74
Merge branch 'develop' into feature/internal-web-viewer
TwoOfTwelve Feb 6, 2024
34c177b
Merge remote-tracking branch 'origin/feature/internal-web-viewer' int…
TwoOfTwelve Feb 6, 2024
ccaddce
add example zip name again
Kr0nox Feb 6, 2024
7b724bb
add node js link to docs
Kr0nox Feb 6, 2024
70a449f
Written tests for internal server.
TwoOfTwelve Feb 9, 2024
24fba7e
Merge remote-tracking branch 'origin/feature/internal-web-viewer' int…
TwoOfTwelve Feb 9, 2024
889cc05
Improved clarity for HttpRequestMethod
TwoOfTwelve Feb 9, 2024
0464d4f
Merge remote-tracking branch 'origin/develop' into feature/internal-w…
Kr0nox Feb 13, 2024
93b6655
Added port lookup.
TwoOfTwelve Feb 13, 2024
1f27130
spotless
TwoOfTwelve Feb 13, 2024
6fe98ad
Merge remote-tracking branch 'origin/develop' into feature/internal-w…
Kr0nox Feb 14, 2024
13d40b6
Clean up logging for internal server and remove unnecessary index.html
TwoOfTwelve Feb 14, 2024
c198274
Fixed error due to renaming of enum constant.
TwoOfTwelve Feb 14, 2024
c3fcf62
Added more tests for RoutingTree
TwoOfTwelve Feb 16, 2024
00d7d8c
Fixed log message if port is not available.
TwoOfTwelve Feb 16, 2024
cec3c6d
Sonarcloud issues
TwoOfTwelve Feb 20, 2024
54d8474
Merge remote-tracking branch 'origin/develop' into feature/internal-w…
TwoOfTwelve Feb 20, 2024
d4303bc
Code style and documentation
TwoOfTwelve Feb 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Build

on:
push:
push:
paths:
- ".github/workflows/maven.yml"
- "**/pom.xml"
Expand All @@ -14,7 +14,7 @@ on:
- "**/pom.xml"
- "**.java"
- "**.g4"

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

Expand Down Expand Up @@ -43,17 +43,21 @@ jobs:
with:
java-version: 21
distribution: 'temurin'


- uses: actions/setup-node@v4
with:
node-version: "18"
Kr0nox marked this conversation as resolved.
Show resolved Hide resolved

- name: Run Tests
run: mvn verify -B -U

- name: Build Assembly
run: mvn clean package assembly:single
run: mvn -Pwith-report-viewer clean package assembly:single

- name: Upload Assembly
uses: actions/upload-artifact@v4
with:
name: "JPlag"
path: "jplag.cli/target/jplag-*-jar-with-dependencies.jar"


6 changes: 5 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ jobs:
with:
java-version: '21'
distribution: 'temurin'
- uses: actions/setup-node@v4
with:
node-version: "18"
Kr0nox marked this conversation as resolved.
Show resolved Hide resolved

- name: Build JPlag
run: mvn -U -B clean package assembly:single
run: mvn -Pwith-report-viewer -U -B clean package assembly:single

- name: Attach CLI to Release on GitHub
uses: softprops/action-gh-release@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sonarcloud-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sonarcloud-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Build and analyze (PR)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/spotless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
- "**/pom.xml"
- "**.java"
- "**.g4"

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

Expand Down Expand Up @@ -43,9 +43,9 @@ jobs:
with:
java-version: 21
distribution: 'temurin'

- name: Check with Spotless
run: mvn clean spotless:check



3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ JPlag is released on [Maven Central](https://search.maven.org/search?q=de.jplag)
1. Download or clone the code from this repository.
2. Run `mvn clean package` from the root of the repository to compile and build all submodules.
Run `mvn clean package assembly:single` instead if you need the full jar which includes all dependencies.
5. You will find the generated JARs in the subdirectory `cli/target`.
Run `mvn -Pwith-report-viewer clean package assembly:single` to build the full jar with the report viewer. In this case, you'll need [Node.js](https://nodejs.org/en/download) installed.
TwoOfTwelve marked this conversation as resolved.
Show resolved Hide resolved
3. You will find the generated JARs in the subdirectory `cli/target`.

## Usage
JPlag can either be used via the CLI or directly via its Java API. For more information, see the [usage information in the wiki](https://github.com/jplag/JPlag/wiki/1.-How-to-Use-JPlag). If you are using the CLI, you can display your results via [jplag.github.io](https://jplag.github.io/JPlag/). No data will leave your computer!
Expand Down
53 changes: 53 additions & 0 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<version>${revision}</version>
</parent>
<artifactId>cli</artifactId>

<dependencies>
<!-- IMPORTANT: For Coverage testing, you have to add dependencies to the coverage-report project ! -->

Expand Down Expand Up @@ -161,4 +162,56 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>with-report-viewer</id>
<build>
<resources>
<resource>
<targetPath>report-viewer</targetPath>
<directory>../report-viewer/dist</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<id>npm install</id>
<goals>
<goal>exec</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<executable>npm</executable>
<workingDirectory>../report-viewer</workingDirectory>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>npm build</id>
<goals>
<goal>exec</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<executable>npm</executable>
<workingDirectory>../report-viewer</workingDirectory>
<arguments>
<argument>run</argument>
<argument>build</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
38 changes: 31 additions & 7 deletions cli/src/main/java/de/jplag/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import static picocli.CommandLine.Model.UsageMessageSpec.SECTION_KEY_OPTION_LIST;
import static picocli.CommandLine.Model.UsageMessageSpec.SECTION_KEY_SYNOPSIS;

import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.HashSet;
Expand All @@ -22,6 +25,7 @@
import de.jplag.JPlagResult;
import de.jplag.Language;
import de.jplag.cli.logger.CollectedLoggerFactory;
import de.jplag.cli.server.ReportViewer;
import de.jplag.clustering.ClusteringOptions;
import de.jplag.clustering.Preprocessing;
import de.jplag.exceptions.ExitException;
Expand Down Expand Up @@ -77,14 +81,13 @@ public static void main(String[] args) {
ParseResult parseResult = cli.parseOptions(args);

if (!parseResult.isUsageHelpRequested() && !(parseResult.subcommand() != null && parseResult.subcommand().isUsageHelpRequested())) {
JPlagOptions options = cli.buildOptionsFromArguments(parseResult);
JPlagResult result = JPlag.run(options);
ReportObjectFactory reportObjectFactory = new ReportObjectFactory(new File(cli.getResultFolder() + ".zip"));
reportObjectFactory.createAndSaveReport(result);

OutputFileGenerator.generateCsvOutput(result, new File(cli.getResultFolder()), cli.options);
switch (cli.options.mode) {
case RUN -> cli.runJPlag(parseResult);
case VIEWER -> cli.runViewer(null);
case RUN_AND_VIEW -> cli.runViewer(cli.runJPlag(parseResult));
}
}
} catch (ExitException | FileNotFoundException exception) {
} catch (ExitException | IOException exception) {
logger.error(exception.getMessage()); // do not pass exception here to keep log clean
finalizeLogger();
System.exit(1);
Expand Down Expand Up @@ -115,6 +118,27 @@ public CLI() {
this.commandLine.setAllowSubcommandsAsOptionParameters(true);
}

public File runJPlag(ParseResult parseResult) throws ExitException, FileNotFoundException {
JPlagOptions options = buildOptionsFromArguments(parseResult);
JPlagResult result = JPlag.run(options);
File target = new File(getResultFolder() + ".zip");
ReportObjectFactory reportObjectFactory = new ReportObjectFactory(target);
reportObjectFactory.createAndSaveReport(result);
OutputFileGenerator.generateCsvOutput(result, new File(getResultFolder()), this.options);
return target;
}

public void runViewer(File zipFile) throws IOException {
ReportViewer reportViewer = new ReportViewer(zipFile, this.options.advanced.port);
int port = reportViewer.start();
logger.info("ReportViewer started on port http://localhost:{}", port);
Desktop.getDesktop().browse(URI.create("http://localhost:" + port + "/"));

System.out.println("Press Enter key to exit...");
System.in.read();
reportViewer.stop();
}

private List<CommandSpec> buildSubcommands() {
return LanguageLoader.getAllAvailableLanguages().values().stream().map(language -> {
CommandSpec command = CommandSpec.create().name(language.getIdentifier());
Expand Down
6 changes: 6 additions & 0 deletions cli/src/main/java/de/jplag/cli/CliOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public class CliOptions implements Runnable {
"--result-directory"}, description = "Name of the directory in which the comparison results will be stored (default: ${DEFAULT-VALUE})%n")
public String resultFolder = "results";

@Option(names = {"--mode"}, description = "The mode to run jplag in")
TwoOfTwelve marked this conversation as resolved.
Show resolved Hide resolved
public JPlagMode mode = JPlagMode.RUN;

@ArgGroup(heading = "Advanced%n", exclusive = false)
public Advanced advanced = new Advanced();

Expand Down Expand Up @@ -89,6 +92,9 @@ public static class Advanced {
+ "be saved (default: ${DEFAULT-VALUE})%n")
public double similarityThreshold = JPlagOptions.DEFAULT_SIMILARITY_THRESHOLD;

@Option(names = {"-P", "--port"}, description = "The port used for the internal report viewer.")
TwoOfTwelve marked this conversation as resolved.
Show resolved Hide resolved
public int port = 1996;

@Option(names = "--csv-export", description = "If present, a csv export will be generated in addition to the zip file.")
public boolean csvExport = false;
}
Expand Down
19 changes: 19 additions & 0 deletions cli/src/main/java/de/jplag/cli/JPlagMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.jplag.cli;

/**
* The mode JPlag runs in. This influences which steps JPlag will execute
TwoOfTwelve marked this conversation as resolved.
Show resolved Hide resolved
*/
public enum JPlagMode {
TwoOfTwelve marked this conversation as resolved.
Show resolved Hide resolved
/**
* Only run JPlag and create a results.zip
*/
RUN,
/**
* Only start the report viewer
*/
VIEWER,
TwoOfTwelve marked this conversation as resolved.
Show resolved Hide resolved
/**
* Run JPlag and open the result in report viewer
*/
RUN_AND_VIEW
}
41 changes: 41 additions & 0 deletions cli/src/main/java/de/jplag/cli/server/ContentType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package de.jplag.cli.server;

/**
* Data types used by JPlag in the context of http. Contains the according mime type.
*/
public enum ContentType {
HTML("text/html; charset=utf-8", ".html"),
JS("application/javascript; charset=utf-8", ".js"),
CSS("text/css; charset=utf-8", ".css"),
PNG("image/png", ".png"),
PLAIN("text/plain; charset=utf-8", null),
ZIP("application/zip", ".zip");

private final String value;

private final String nameSuffix;

ContentType(String value, String nameSuffix) {
this.value = value;
this.nameSuffix = nameSuffix;
}

public String getValue() {
return value;
}

/**
* Guesses the type from the given path using the suffix after the last '.'.
* @param path The path to guess from
* @return The guessed type
*/
public static ContentType fromPath(String path) {
String suffix = path.substring(path.lastIndexOf('.'));
for (ContentType value : ContentType.values()) {
if (suffix.equals(value.nameSuffix)) {
return value;
}
}
return ContentType.PLAIN;
}
}
32 changes: 32 additions & 0 deletions cli/src/main/java/de/jplag/cli/server/HttpRequestMethod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.jplag.cli.server;

/**
* Wraps the http request methods used by JPlag. Request methods determine the capabilities of a http request.
*/
public enum HttpRequestMethod {
GET("GET"),
POST("POST");

private final String name;

/**
* @param name The name of the request method
*/
HttpRequestMethod(String name) {
this.name = name;
}

public String getName() {
return name;
}

public static HttpRequestMethod fromName(String name) {
for (HttpRequestMethod value : HttpRequestMethod.values()) {
if (value.name.equals(name)) {
return value;
}
}

return null;
}
}
Loading
Loading