Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into report-viewer/ench…
Browse files Browse the repository at this point in the history
…ance-table

# Conflicts:
#	report-viewer/src/views/ClusterView.vue
  • Loading branch information
Kr0nox committed Nov 28, 2023
2 parents 12acc19 + b0d63cd commit 7ca88f8
Show file tree
Hide file tree
Showing 127 changed files with 24,786 additions and 1,428 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ jobs:
run: cp -r ./docs/. ./wiki

- name: Deploy 🚀
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
repository: wiki
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 17
java-version: 21
distribution: 'temurin'

- name: Run Tests
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'
- name: Set maven settings.xml
uses: whelk-io/maven-settings-xml-action@v21
Expand All @@ -32,7 +32,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'
- name: Build JPlag
run: mvn -U -B clean package assembly:single
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/report-viewer-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Checkout 🛎️
uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "18"

Expand Down
15 changes: 1 addition & 14 deletions .github/workflows/report-viewer-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,10 @@ jobs:
- name: Checkout 🛎️
uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
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)
sed -i "/major/s/.*/ \"major\": $MAJOR,/" report-viewer/src/version.json
sed -i "/minor/s/.*/ \"minor\": $MINOR,/" report-viewer/src/version.json
sed -i "/patch/s/.*/ \"patch\": $PATCH/" report-viewer/src/version.json
echo "Version of Report Viewer:"
cat report-viewer/src/version.json
- name: Install and Build 🔧
working-directory: report-viewer
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/report-viewer-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Checkout 🛎️
uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "18"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/report-viewer-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Checkout 🛎️
uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "18"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/report-viewer-prettier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Checkout 🛎️
uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "18"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/report-viewer-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Checkout 🛎️
uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "18"

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/report-viewer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Checkout 🛎️
uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "18"

Expand All @@ -24,9 +24,9 @@ jobs:
MAJOR=$(echo $VERSION | cut -d '.' -f 1)
MINOR=$(echo $VERSION | cut -d '.' -f 2)
PATCH=$(echo $VERSION | cut -d '.' -f 3)
sed -i "/major/s/.*/ \"major\": $MAJOR,/" report-viewer/src/version.json
sed -i "/minor/s/.*/ \"minor\": $MINOR,/" report-viewer/src/version.json
sed -i "/patch/s/.*/ \"patch\": $PATCH/" report-viewer/src/version.json
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
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 @@ -28,7 +28,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
java-version: 21

- name: Cache SonarCloud packages
uses: actions/cache@v3
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 @@ -51,7 +51,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
java-version: 21

- name: Cache SonarCloud packages
uses: actions/cache@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/spotless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 17
java-version: 21
distribution: 'temurin'

- name: Check with Spotless
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ In the following, a list of all supported languages with their supported languag

| Language | Version | CLI Argument Name | [state](https://github.com/jplag/JPlag/wiki/2.-Supported-Languages) | parser |
|------------------------------------------------------------|---------------------------------------------------------------------------------------:|-------------------|:-------------------------------------------------------------------:|:---------:|
| [Java](https://www.java.com) | 17 | java | mature | JavaC |
| [Java](https://www.java.com) | 21 | java | mature | JavaC |
| [C/C++](https://isocpp.org) | 11 | cpp | legacy | JavaCC |
| [C/C++](https://isocpp.org) | 14 | cpp2 | beta | ANTLR 4 |
| [C#](https://docs.microsoft.com/en-us/dotnet/csharp/) | 6 | csharp | beta | ANTLR 4 |
Expand All @@ -40,7 +40,7 @@ In the following, a list of all supported languages with their supported languag
| Text (naive) | - | text | legacy | CoreNLP |

## Download and Installation
You need Java SE 17 to run or build JPlag.
You need Java SE 21 to run or build JPlag.

### Downloading a release
* Download a [released version](https://github.com/jplag/jplag/releases).
Expand Down
21 changes: 12 additions & 9 deletions core/src/main/java/de/jplag/GreedyStringTiling.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.jplag;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
Expand All @@ -22,9 +23,8 @@
public class GreedyStringTiling {

private final int minimumMatchLength;
private final int minimumNeighborLength;
private JPlagOptions options;
private ConcurrentMap<TokenType, Integer> tokenTypeValues;
private final JPlagOptions options;
private final ConcurrentMap<TokenType, Integer> tokenTypeValues;
private final Map<Submission, Set<Token>> baseCodeMarkings = new IdentityHashMap<>();

private final Map<Submission, int[]> cachedTokenValueLists = new IdentityHashMap<>();
Expand All @@ -33,8 +33,8 @@ public class GreedyStringTiling {
public GreedyStringTiling(JPlagOptions options) {
this.options = options;
// Ensures 1 <= neighborLength <= minimumTokenMatch
this.minimumNeighborLength = Math.min(Math.max(options.mergingOptions().minimumNeighborLength(), 1), options.minimumTokenMatch());
this.minimumMatchLength = options.mergingOptions().enabled() ? this.minimumNeighborLength : options.minimumTokenMatch();
int minimumNeighborLength = Math.min(Math.max(options.mergingOptions().minimumNeighborLength(), 1), options.minimumTokenMatch());
this.minimumMatchLength = options.mergingOptions().enabled() ? minimumNeighborLength : options.minimumTokenMatch();
this.tokenTypeValues = new ConcurrentHashMap<>();
this.tokenTypeValues.put(SharedTokenType.FILE_END, 0);
}
Expand Down Expand Up @@ -78,12 +78,15 @@ public final JPlagComparison generateBaseCodeMarking(Submission submission, Subm
public final JPlagComparison compare(Submission firstSubmission, Submission secondSubmission) {
Submission smallerSubmission;
Submission largerSubmission;
if (firstSubmission.getTokenList().size() > secondSubmission.getTokenList().size()) {
smallerSubmission = secondSubmission;
largerSubmission = firstSubmission;
} else {
Comparator<Submission> submissionComparator = Comparator.comparing((Submission it) -> it.getTokenList().size())
.thenComparing(Submission::getName);

if (submissionComparator.compare(firstSubmission, secondSubmission) <= 0) {
smallerSubmission = firstSubmission;
largerSubmission = secondSubmission;
} else {
smallerSubmission = secondSubmission;
largerSubmission = firstSubmission;
}
return compareInternal(smallerSubmission, largerSubmission);
}
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/de/jplag/Submission.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ private static File createErrorDirectory(String... subdirectoryNames) {

try {
tokenList = language.parse(new HashSet<>(files));
if (logger.isDebugEnabled()) {
for (Token token : tokenList) {
logger.debug(String.join(" | ", token.getType().toString(), Integer.toString(token.getLine()), token.getSemantics().toString()));
}
}
} catch (ParsingException e) {
logger.warn("Failed to parse submission {} with error {}", this, e.getMessage(), e);
tokenList = null;
Expand All @@ -272,7 +277,7 @@ private static File createErrorDirectory(String... subdirectoryNames) {
*/
void normalize() {
List<Integer> originalOrder = getOrder(tokenList);
TokenStringNormalizer.normalize(tokenList);
tokenList = TokenStringNormalizer.normalize(tokenList);
List<Integer> normalizedOrder = getOrder(tokenList);

logger.debug("original line order: {}", originalOrder);
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/de/jplag/SubmissionSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ private void parseSubmissions(List<Submission> submissions) {

int tooShort = 0;
for (Submission submission : submissions) {
logger.info("Parsing submission {}", submission.getName());
boolean ok;

logger.trace("------ Parsing submission: " + submission.getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.jplag.normalization;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
Expand All @@ -20,13 +21,15 @@ private TokenStringNormalizer() {
}

/**
* Normalizes the token string it receives in place. Tokens representing dead code have been eliminated and tokens
* representing subsequent independent statements have been put in a fixed order. Works by first constructing a
* Normalization Graph and then turning it back into a token string.
* Performs token string normalization. Tokens representing dead code have been eliminated and tokens representing
* subsequent independent statements have been put in a fixed order. Works by first constructing a Normalization Graph
* and then turning it back into a token string.
* @param tokens The original token string, remains unaltered.
* @return The normalized token string.
*/
public static void normalize(List<Token> tokens) {
public static List<Token> normalize(List<Token> tokens) {
SimpleDirectedGraph<Statement, MultipleEdge> normalizationGraph = new NormalizationGraphConstructor(tokens).get();
tokens.clear();
List<Token> normalizedTokens = new ArrayList<>(tokens.size());
spreadKeep(normalizationGraph);
PriorityQueue<Statement> roots = normalizationGraph.vertexSet().stream() //
.filter(v -> !Graphs.vertexHasPredecessors(normalizationGraph, v)) //
Expand All @@ -36,7 +39,7 @@ public static void normalize(List<Token> tokens) {
do {
Statement statement = roots.poll();
if (statement.semantics().keep()) {
tokens.addAll(statement.tokens());
normalizedTokens.addAll(statement.tokens());
}
for (Statement successor : Graphs.successorListOf(normalizationGraph, statement)) {
normalizationGraph.removeEdge(statement, successor);
Expand All @@ -47,6 +50,7 @@ public static void normalize(List<Token> tokens) {
} while (!roots.isEmpty());
roots = newRoots;
}
return normalizedTokens;
}

/**
Expand Down
13 changes: 7 additions & 6 deletions core/src/test/java/de/jplag/NewJavaFeaturesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import org.junit.jupiter.api.Test;

import de.jplag.exceptions.ExitException;
import de.jplag.java.JavaLanguage;

public class NewJavaFeaturesTest extends TestBase {

private static final int EXPECTED_MATCHES = 6; // might change if you add files to the submissions
private static final double EXPECTED_SIMILARITY = 0.96; // might change if you add files to the submissions
private static final String EXPECTED_JAVA_VERSION = "17"; // might change with newer JPlag versions
private static final int EXPECTED_MATCHES = 8; // might change if you add files to the submissions
private static final int NUMBER_OF_TEST_FILES = 8;
private static final double EXPECTED_SIMILARITY = 0.971; // might change if you add files to the submissions

private static final String EXCLUSION_FILE_NAME = "blacklist.txt";
private static final String ROOT_DIRECTORY = "NewJavaFeatures";
Expand All @@ -28,15 +29,15 @@ public void testJavaFeatureDuplicates() throws ExitException {
// pre-condition
String actualJavaVersion = System.getProperty(JAVA_VERSION_KEY);
boolean isCiRun = System.getenv(CI_VARIABLE) != null;
boolean isCorrectJavaVersion = actualJavaVersion.startsWith(EXPECTED_JAVA_VERSION);
assumeTrue(isCorrectJavaVersion || isCiRun, VERSION_MISMATCH_MESSAGE.formatted(actualJavaVersion, EXPECTED_JAVA_VERSION));
boolean isCorrectJavaVersion = actualJavaVersion.startsWith(String.valueOf(JavaLanguage.JAVA_VERSION));
assumeTrue(isCorrectJavaVersion || isCiRun, VERSION_MISMATCH_MESSAGE.formatted(actualJavaVersion, JavaLanguage.JAVA_VERSION));

JPlagResult result = runJPlagWithExclusionFile(ROOT_DIRECTORY, EXCLUSION_FILE_NAME);

// Ensure test input did not change:
assertEquals(2, result.getNumberOfSubmissions(), String.format(CHANGE_MESSAGE, "Submissions"));
for (Submission submission : result.getSubmissions().getSubmissions()) {
assertEquals(6, submission.getFiles().size(), String.format(CHANGE_MESSAGE, "Files"));
assertEquals(NUMBER_OF_TEST_FILES, submission.getFiles().size(), String.format(CHANGE_MESSAGE, "Files"));
}
assertEquals(1, result.getAllComparisons().size(), String.format(CHANGE_MESSAGE, "Comparisons"));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public class Java21 {
private static final record Circle(int radius) {
}

private static final record Rect(int width, int height) {
}

private static final record Both(Circle circle, Rect rect) {
}

private static final record Square(int length) {
}

public void main() {
Shape s = new Circle();
switch (s) {
case Cricle(int r) -> System.out.println(r);
case Shape s -> System.out.println(c);
case Both(Circle c, Rect(int w, int _)) -> System.out.println("something");
case Square -> {
int l = ((Square) s).length;
System.out.println(STR."Square with length \{Math.abs(l)}");
}
}


if (s instanceof Circle(int r)) {

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public class Java21 {
private static final record Circle(int radius) {
}

private static final record Rect(int width, int height) {
}

private static final record Both(Circle circle, Rect rect) {
}

private static final record Square(int length) {
}

public void main() {
Shape s = new Circle();
switch (s) {
case Cricle(int r) -> System.out.println(r);
case Shape s -> System.out.println(c);
case Both(Circle c, Rect(int _, int w)) -> System.out.println("something");
case Square -> {
int l = ((Square) s).length;
System.out.println(STR."Square with length \{Math.abs(l)}");
}
}


if (s instanceof Circle(int r)) {

}
}
}
Loading

0 comments on commit 7ca88f8

Please sign in to comment.