Skip to content

Commit

Permalink
merge develop into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr0nox committed Oct 21, 2024
1 parent 3fb0b8f commit 8fd3a91
Show file tree
Hide file tree
Showing 241 changed files with 5,583 additions and 3,779 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/complete-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
node-version: "18"

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

- name: Rename Jar
run: mv cli/target/jplag-*-jar-with-dependencies.jar cli/target/jplag.jar
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- "**/pom.xml"
- "**.java"
- "**.g4"
- "report-viewer/**"
pull_request:
types: [opened, synchronize, reopened]
paths:
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ jobs:
with:
node-version: "18"

- name: Set version of Report Viewer
shell: bash
run: |
VERSION=$(grep "<revision>" pom.xml | grep -oPm1 "(?<=<revision>)[^-|<]+")
MAJOR=$(echo $VERSION | cut -d '.' -f 1)
MINOR=$(echo $VERSION | cut -d '.' -f 2)
PATCH=$(echo $VERSION | cut -d '.' -f 3)
json=$(cat report-viewer/src/version.json)
json=$(echo "$json" | jq --arg MAJOR "$MAJOR" --arg MINOR "$MINOR" --arg PATCH "$PATCH" '.report_viewer_version |= { "major": $MAJOR | tonumber, "minor": $MINOR | tonumber, "patch": $PATCH | tonumber }')
echo "$json" > report-viewer/src/version.json
echo "Version of Report Viewer:"
cat report-viewer/src/version.json
- name: Build JPlag
run: mvn -Pwith-report-viewer -U -B clean package assembly:single

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/report-viewer-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
npm run build-demo
- name: Deploy 🚀
uses: JamesIves/[email protected].1
uses: JamesIves/[email protected].8
with:
branch: gh-pages
folder: report-viewer/dist
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/report-viewer-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
npm run build-dev
- name: Deploy 🚀
uses: JamesIves/[email protected].1
uses: JamesIves/[email protected].8
with:
branch: gh-pages
folder: report-viewer/dist
Expand Down
43 changes: 0 additions & 43 deletions .github/workflows/report-viewer.yml

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Advanced
-d, --debug Store on-parsable files in error folder.
-m, --similarity-threshold=<similarityThreshold>
Comparison similarity threshold [0.0-1.0]: All comparisons above this threshold will be saved (default: 0.0).
--overwrite Existing result files will be overwritten.
-p, --suffixes=<suffixes>[,<suffixes>...]
comma-separated list of all filename suffixes that are included.
-P, --port=<port> The port used for the internal report viewer (default: 1996).
Expand All @@ -130,7 +131,7 @@ Subsequence Match Merging
--neighbor-length=<minimumNeighborLength>
Minimal length of neighboring matches to be merged (between 1 and minTokenMatch, default: 2).
Subcommands (supported languages):
Languages:
c
cpp
csharp
Expand Down
2 changes: 1 addition & 1 deletion cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.1</version>
<executions>
<execution>
<id>npm install</id>
Expand Down
10 changes: 7 additions & 3 deletions cli/src/main/java/de/jplag/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import de.jplag.JPlag;
import de.jplag.JPlagResult;
import de.jplag.cli.logger.CliProgressBarProvider;
import de.jplag.cli.logger.CollectedLogger;
import de.jplag.cli.logger.CollectedLoggerFactory;
import de.jplag.cli.picocli.CliInputHandler;
import de.jplag.exceptions.ExitException;
Expand Down Expand Up @@ -42,14 +43,16 @@ public CLI(String[] args) {
}

/**
* Executes the cli
* Executes the cli.
* @throws ExitException If anything on the side of JPlag goes wrong
* @throws IOException If any files did not work
*/
public void executeCli() throws ExitException, IOException {
logger.debug("Your version of JPlag is {}", JPlag.JPLAG_VERSION);
JPlagVersionChecker.printVersionNotification();

if (!this.inputHandler.parse()) {
CollectedLogger.setLogLevel(this.inputHandler.getCliOptions().advanced.logLevel);
ProgressBarLogger.setProgressBarProvider(new CliProgressBarProvider());

switch (this.inputHandler.getCliOptions().mode) {
Expand Down Expand Up @@ -84,7 +87,7 @@ public boolean executeCliAndHandleErrors() {
}

/**
* Runs JPlag and returns the file the result has been written to
* Runs JPlag and returns the file the result has been written to.
* @return The file containing the result
* @throws ExitException If JPlag threw an exception
* @throws FileNotFoundException If the file could not be written
Expand All @@ -103,11 +106,12 @@ public File runJPlag() throws ExitException, FileNotFoundException {
}

/**
* Runs the report viewer using the given file as the default result.zip
* Runs the report viewer using the given file as the default result.zip.
* @param zipFile The zip file to pass to the viewer. Can be null, if no result should be opened by default
* @throws IOException If something went wrong with the internal server
*/
public void runViewer(File zipFile) throws IOException {
finalizeLogger(); // Prints the errors. The later finalizeLogger will print any errors logged after this point.
JPlagRunner.runInternalServer(zipFile, this.inputHandler.getCliOptions().advanced.port);
}

Expand Down
4 changes: 2 additions & 2 deletions cli/src/main/java/de/jplag/cli/JPlagOptionsBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import de.jplag.options.JPlagOptions;

/**
* Handles the building of JPlag options from the cli options
* Handles the building of JPlag options from the cli options.
*/
public class JPlagOptionsBuilder {
private static final Logger logger = LoggerFactory.getLogger(JPlagOptionsBuilder.class);
Expand All @@ -25,7 +25,7 @@ public class JPlagOptionsBuilder {
private final CliOptions cliOptions;

/**
* @param cliInputHandler The cli handler containing the parsed cli options
* @param cliInputHandler The cli handler containing the parsed cli options.
*/
public JPlagOptionsBuilder(CliInputHandler cliInputHandler) {
this.cliInputHandler = cliInputHandler;
Expand Down
8 changes: 6 additions & 2 deletions cli/src/main/java/de/jplag/cli/JPlagRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private JPlagRunner() {
}

/**
* Executes JPlag
* Executes JPlag.
* @param options The options to pass to JPlag
* @return The result returned by JPlag
* @throws ExitException If JPlag throws an error
Expand All @@ -43,7 +43,11 @@ public static void runInternalServer(File zipFile, int port) throws IOException
ReportViewer reportViewer = new ReportViewer(zipFile, port);
int actualPort = reportViewer.start();
logger.info("ReportViewer started on port http://localhost:{}", actualPort);
Desktop.getDesktop().browse(URI.create("http://localhost:" + actualPort + "/"));
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
Desktop.getDesktop().browse(URI.create("http://localhost:" + actualPort + "/"));
} else {
logger.info("Could not open browser. You can open the Report Viewer here: http://localhost:{}/", actualPort);
}

System.out.println("Press Enter key to exit...");
System.in.read();
Expand Down
91 changes: 91 additions & 0 deletions cli/src/main/java/de/jplag/cli/JPlagVersionChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package de.jplag.cli;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Optional;

import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.json.JsonReader;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.jplag.JPlag;
import de.jplag.reporting.reportobject.model.Version;

/**
* Handles the check for newer versions.
*/
public class JPlagVersionChecker {
private static final String API_URL = "https://api.github.com/repos/jplag/JPlag/releases";
private static final Logger logger = LoggerFactory.getLogger(JPlagVersionChecker.class);
private static final String EXPECTED_VERSION_FORMAT = "v\\d\\.\\d\\.\\d+";
private static final String WARNING_UNABLE_TO_FETCH = "Unable to fetch version information. New version notification will not work.";
private static final String NEWER_VERSION_AVAILABLE = "There is a newer version ({}) available. You can download the newest version here: https://github.com/jplag/JPlag/releases";
private static final String UNEXPECTED_ERROR = "There was an unexpected error, when checking for new versions. Please report this on: https://github.com/jplag/JPlag/issues";

private JPlagVersionChecker() {

}

/**
* Prints a warning if a newer version is available on GitHub.
*/
public static void printVersionNotification() {
Optional<Version> newerVersion = checkForNewVersion();
newerVersion.ifPresent(version -> logger.warn(NEWER_VERSION_AVAILABLE, version));
}

private static Optional<Version> checkForNewVersion() {
try {
JsonArray array = fetchApi();
Version newest = getNewestVersion(array);
Version current = JPlag.JPLAG_VERSION;

if (newest.compareTo(current) > 0) {
return Optional.of(newest);
}
} catch (IOException | URISyntaxException e) {
logger.info(WARNING_UNABLE_TO_FETCH);
} catch (Exception e) {
logger.warn(UNEXPECTED_ERROR, e);
}

return Optional.empty();
}

private static JsonArray fetchApi() throws IOException, URISyntaxException {
URL url = new URI(API_URL).toURL();
URLConnection connection = url.openConnection();

try (JsonReader reader = Json.createReader(connection.getInputStream())) {
return reader.readArray();
}
}

private static Version getNewestVersion(JsonArray apiResult) {
return apiResult.stream().map(JsonObject.class::cast).map(version -> version.getString("name"))
.filter(versionName -> versionName.matches(EXPECTED_VERSION_FORMAT)).limit(1).map(JPlagVersionChecker::parseVersion).findFirst()
.orElse(JPlag.JPLAG_VERSION);
}

/**
* Parses the version name.
* @param versionName The version name. The expected format is: v[major].[minor].[patch]
* @return The parsed version
*/
private static Version parseVersion(String versionName) {
String withoutPrefix = versionName.substring(1);
String[] parts = withoutPrefix.split("\\.");
return parseVersionParts(parts);
}

private static Version parseVersionParts(String[] parts) {
return new Version(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2]));
}
}
4 changes: 2 additions & 2 deletions cli/src/main/java/de/jplag/cli/OutputFileGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import de.jplag.reporting.reportobject.ReportObjectFactory;

/**
* Manages the creation of output files
* Manages the creation of output files.
*/
public final class OutputFileGenerator {
private static final Logger logger = LoggerFactory.getLogger(OutputFileGenerator.class);
Expand All @@ -40,7 +40,7 @@ public static void generateCsvOutput(JPlagResult result, File outputRoot, CliOpt
}

/**
* Generates the JPLag result zip
* Generates the JPLag result zip.
* @param result The JPlag result
* @param outputFile The output file
* @throws FileNotFoundException If the file cannot be written
Expand Down
19 changes: 14 additions & 5 deletions cli/src/main/java/de/jplag/cli/logger/CliProgressBarProvider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package de.jplag.cli.logger;

import java.util.Set;

import org.slf4j.event.Level;

import de.jplag.logging.ProgressBar;
import de.jplag.logging.ProgressBarProvider;
import de.jplag.logging.ProgressBarType;
Expand All @@ -11,16 +15,21 @@
* A ProgressBar provider, that used the tongfei progress bar library underneath, to show progress bars on the cli.
*/
public class CliProgressBarProvider implements ProgressBarProvider {
private static final Set<Level> allowedLogLevels = Set.of(Level.INFO);

@Override
public ProgressBar initProgressBar(ProgressBarType type, int totalSteps) {
if (type.isIdleBar()) {
IdleBar idleBar = new IdleBar(type.getDefaultText());
idleBar.start();
return idleBar;
} else {
if (allowedLogLevels.contains(CollectedLogger.getLogLevel())) {
if (type.isIdleBar()) {
IdleBar idleBar = new IdleBar(type.getDefaultText());
idleBar.start();
return idleBar;
}
me.tongfei.progressbar.ProgressBar progressBar = new ProgressBarBuilder().setTaskName(type.getDefaultText()).setInitialMax(totalSteps)
.setStyle(ProgressBarStyle.ASCII).build();
return new TongfeiProgressBar(progressBar);
} else {
return new VoidProgressBar();
}
}
}
Loading

0 comments on commit 8fd3a91

Please sign in to comment.