-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/refactorRLang
# Conflicts: # languages/rlang/src/main/java/de/jplag/rlang/RLanguage.java # languages/rlang/src/main/java/de/jplag/rlang/RParserAdapter.java
- Loading branch information
Showing
156 changed files
with
3,656 additions
and
2,381 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
cli/src/main/java/de/jplag/cli/logger/DelayablePrinter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package de.jplag.cli.logger; | ||
|
||
import java.io.PrintStream; | ||
import java.util.PriorityQueue; | ||
import java.util.Queue; | ||
|
||
/** | ||
* Prints strings to stdout. Provides the option to delay the actual printing. | ||
*/ | ||
public class DelayablePrinter { | ||
private final Queue<String> outputQueue; | ||
private PrintStream targetStream; | ||
|
||
private boolean isDelayed; | ||
|
||
private static final class InstanceHolder { | ||
private static final DelayablePrinter instance = new DelayablePrinter(); | ||
} | ||
|
||
/** | ||
* Threadsafe singleton getter | ||
* @return The singleton instance | ||
*/ | ||
public static DelayablePrinter getInstance() { | ||
return InstanceHolder.instance; | ||
} | ||
|
||
private DelayablePrinter() { | ||
this.outputQueue = new PriorityQueue<>(); | ||
this.targetStream = System.out; | ||
this.isDelayed = false; | ||
} | ||
|
||
/** | ||
* Prints the given string to the terminal appending a line-break | ||
* @param output The string to print | ||
*/ | ||
public synchronized void println(String output) { | ||
this.outputQueue.offer(output); | ||
this.printQueue(); | ||
} | ||
|
||
/** | ||
* Stops printing to the terminal until {@link #resume()} is called | ||
*/ | ||
public synchronized void delay() { | ||
this.isDelayed = true; | ||
} | ||
|
||
/** | ||
* Resumes printing if {@link #delay()} was called | ||
*/ | ||
public synchronized void resume() { | ||
this.isDelayed = false; | ||
this.printQueue(); | ||
} | ||
|
||
/** | ||
* Changes the output stream messages are written to | ||
*/ | ||
public void setOutputStream(PrintStream printStream) { | ||
this.targetStream = printStream; | ||
} | ||
|
||
private synchronized void printQueue() { | ||
if (!this.isDelayed) { | ||
while (!this.outputQueue.isEmpty()) { | ||
this.targetStream.println(this.outputQueue.poll()); | ||
} | ||
this.targetStream.flush(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.