Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into update-dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	report-viewer/package-lock.json
#	report-viewer/package.json
  • Loading branch information
Kr0nox committed Apr 9, 2024
2 parents e1b4d6e + 11b0347 commit 8861ede
Show file tree
Hide file tree
Showing 47 changed files with 993 additions and 789 deletions.
157 changes: 157 additions & 0 deletions .github/workflows/complete-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Builds JPlag and then runs Datasets and Report Viewer e2e tests on multiple OS
name: Complete e2e Test

on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened]
paths:
- ".github/workflows/complete-e2e.yml"
- "report-viewer/**"
- "**/pom.xml"
- "**.java"
- "**.g4"

jobs:
pre_job:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@master
with:
concurrent_skipping: 'same_content_newer'
skip_after_successful_duplicate: 'true'

build_jar:
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'

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

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

- name: Rename Jar
run: mv cli/target/jplag-*-jar-with-dependencies.jar cli/target/jplag.jar

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

run_jplag:
needs: build_jar
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
dataset: [
{zip: "progpedia.zip", name: "progpedia", folder: "ACCEPTED", language: "java", cliArgs: "-bc base"},
{zip: "fileSingleRoot.zip", name: "fileSingleRoot", folder: "fileSingleRoot", language: "java", cliArgs: ""},
{zip: "folderSingleRoot.zip", name: "folderSingleRoot", folder: "folderSingleRoot", language: "java", cliArgs: ""},
{zip: "fileMultiRoot.zip", name: "fileMultiRoot", folder: "f0", language: "java", cliArgs: "--new f1"},
{zip: "folderMultiRoot.zip", name: "folderMultiRoot", folder: "f0", language: "java", cliArgs: "--new f1"},
{zip: "mixedMultiRoot.zip", name: "mixedBaseFile", folder: "f0", language: "java", cliArgs: "--new f1"},
{zip: "mixedMultiRoot.zip", name: "mixedBaseFolder", folder: "f1", language: "java", cliArgs: "--new f0"}
]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'

- name: Get JAR
uses: actions/download-artifact@v4
with:
name: JPlag

- name: Copy and unzip dataset windows
if: ${{ matrix.os == 'windows-latest' }}
run: |
Expand-Archive -LiteralPath .github/workflows/files/${{ matrix.dataset.zip }} -DestinationPath ./
- name: Copy and unzip dataset macos and ubuntu
if: ${{ matrix.os == 'macos-latest' || matrix.os == 'ubuntu-latest'}}
run: |
unzip .github/workflows/files/${{ matrix.dataset.zip }}
- name: Run JPlag
run: |
java -jar jplag.jar ${{ matrix.dataset.folder }} -l ${{ matrix.dataset.language }} -r ${{ matrix.dataset.name }}-report ${{ matrix.dataset.cliArgs }}
- name: Upload result
uses: actions/upload-artifact@v4
with:
name: "${{ matrix.dataset.name }}-${{ matrix.os }}"
path: "${{ matrix.dataset.name }}-report.zip"
retention-days: 30

e2e_test:
needs: run_jplag
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Checkout
uses: actions/checkout@v4

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

- name: Install and Build
working-directory: report-viewer
run: |
npm install
npm run build
- name: Install playwright
working-directory: report-viewer
run: npx playwright install --with-deps

- name: Download JPlag Reports
uses: actions/download-artifact@v4
with:
pattern: "*-${{ matrix.os }}"
path: "report-viewer/tests/e2e/assets"
merge-multiple: true

- name: Run tests
working-directory: report-viewer
run: |
npm run test:e2e
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: "test-results-${{ matrix.os }}"
path: |
report-viewer/test-results
report-viewer/playwright-report
retention-days: 30
Binary file added .github/workflows/files/fileMultiRoot.zip
Binary file not shown.
Binary file added .github/workflows/files/fileSingleRoot.zip
Binary file not shown.
Binary file added .github/workflows/files/folderMultiRoot.zip
Binary file not shown.
Binary file added .github/workflows/files/folderSingleRoot.zip
Binary file not shown.
Binary file added .github/workflows/files/mixedMultiRoot.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Deploy to Maven Central & GitHub
on:
workflow_dispatch:
release:
types: [created]
types: [created, published]
jobs:
publish-maven-central:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
run: mvn -Pwith-report-viewer -U -B clean package assembly:single

- name: Attach CLI to Release on GitHub
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: cli/target/jplag-*-jar-with-dependencies.jar
Expand Down
58 changes: 0 additions & 58 deletions .github/workflows/report-viewer-e2e.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/de.jplag/jplag/badge.svg)](https://maven-badges.herokuapp.com/maven-central/de.jplag/jplag)
[![License](https://img.shields.io/github/license/jplag/jplag.svg)](https://github.com/jplag/jplag/blob/main/LICENSE)
[![GitHub commit activity](https://img.shields.io/github/commit-activity/y/jplag/JPlag)](https://github.com/jplag/JPlag/pulse)
[![SonarCloud Coverage](https://sonarcloud.io/api/project_badges/measure?project=jplag_JPlag&metric=coverage)](https://sonarcloud.io/component_measures/metric/coverage/list?id=jplag_JPlag)
[![SonarCloud Coverage](https://sonarcloud.io/api/project_badges/measure?project=jplag_JPlag&metric=coverage)](https://sonarcloud.io/component_measures?metric=Coverage&view=list&id=jplag_JPlag)
[![Report Viewer](https://img.shields.io/badge/report%20viewer-online-b80025)](https://jplag.github.io/JPlag/)
[![Java Version](https://img.shields.io/badge/java-SE%2021-yellowgreen)](#download-and-installation)

Expand Down
4 changes: 2 additions & 2 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<dependency>
<groupId>me.tongfei</groupId>
<artifactId>progressbar</artifactId>
<version>0.10.0</version>
<version>0.10.1</version>
</dependency>
</dependencies>
<build>
Expand Down Expand Up @@ -183,7 +183,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<version>3.2.0</version>
<executions>
<execution>
<id>npm install</id>
Expand Down
42 changes: 25 additions & 17 deletions core/src/main/java/de/jplag/reporting/FilePathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

public final class FilePathUtil {
private static final String ZIP_PATH_SEPARATOR = "/"; // Paths in zip files are always separated by a slash
private static final String WINDOWS_PATH_SEPARATOR = "\\";

private FilePathUtil() {
// private constructor to prevent instantiation
Expand All @@ -21,30 +20,39 @@ private FilePathUtil() {
* @param submissionToIdFunction Function to map names to ids
* @return Relative path
*/
public static String getRelativeSubmissionPath(File file, Submission submission, Function<Submission, String> submissionToIdFunction) {
public static Path getRelativeSubmissionPath(File file, Submission submission, Function<Submission, String> submissionToIdFunction) {
if (file.toPath().equals(submission.getRoot().toPath())) {
return Path.of(submissionToIdFunction.apply(submission), submissionToIdFunction.apply(submission)).toString();
return Path.of(submissionToIdFunction.apply(submission), submissionToIdFunction.apply(submission));
}
return Path.of(submissionToIdFunction.apply(submission), submission.getRoot().toPath().relativize(file.toPath()).toString()).toString();
return Path.of(submissionToIdFunction.apply(submission), submission.getRoot().toPath().relativize(file.toPath()).toString());
}

/**
* Joins logical paths using a slash. This method ensures, that no duplicate slashes are created in between.
* @param left The left path segment
* @param right The right path segment
* @return The joined paths
* Forces a path to be relative. If the path is absolute, the returned path will be relative to the root.
* @param path The path to relativize
* @return The relative path
*/
public static String joinZipPathSegments(String left, String right) {
String rightStripped = right;
while (rightStripped.startsWith(ZIP_PATH_SEPARATOR) || rightStripped.startsWith(WINDOWS_PATH_SEPARATOR)) {
rightStripped = rightStripped.substring(1);
public static Path forceRelativePath(Path path) {
if (path.isAbsolute()) {
return Path.of("/").relativize(path);
}
return path;
}

String leftStripped = left;
while (leftStripped.endsWith(ZIP_PATH_SEPARATOR) || leftStripped.startsWith(WINDOWS_PATH_SEPARATOR)) {
leftStripped = leftStripped.substring(0, leftStripped.length() - 1);
/**
* Formats the path for usage with zip files. Returns the path segments separated by {@link #ZIP_PATH_SEPARATOR}
* @param path The path to format
* @return The zip file path
*/
public static String pathAsZipPath(Path path) {
Path relativePath = forceRelativePath(path);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < relativePath.getNameCount(); i++) {
if (i != 0) {
builder.append(ZIP_PATH_SEPARATOR);
}
builder.append(relativePath.getName(i));
}

return leftStripped + ZIP_PATH_SEPARATOR + rightStripped;
return builder.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.jplag.reporting.jsonfactory;

import java.nio.file.Path;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -58,7 +59,7 @@ private void writeComparisons(List<JPlagComparison> comparisons) {
var comparisonReport = new ComparisonReport(firstSubmissionId, secondSubmissionId,
Map.of(SimilarityMetric.AVG.name(), comparison.similarity(), SimilarityMetric.MAX.name(), comparison.maximalSimilarity()),
convertMatchesToReportMatches(comparison), comparison.similarityOfFirst(), comparison.similarityOfSecond());
resultWriter.addJsonEntry(comparisonReport, fileName);
resultWriter.addJsonEntry(comparisonReport, Path.of(fileName));
}
}

Expand Down Expand Up @@ -104,8 +105,9 @@ private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Mat
Token startOfSecond = tokensSecond.stream().min(lineComparator).orElseThrow();
Token endOfSecond = tokensSecond.stream().max(lineComparator).orElseThrow();

return new Match(FilePathUtil.getRelativeSubmissionPath(startOfFirst.getFile(), comparison.firstSubmission(), submissionToIdFunction),
FilePathUtil.getRelativeSubmissionPath(startOfSecond.getFile(), comparison.secondSubmission(), submissionToIdFunction),
return new Match(
FilePathUtil.getRelativeSubmissionPath(startOfFirst.getFile(), comparison.firstSubmission(), submissionToIdFunction).toString(),
FilePathUtil.getRelativeSubmissionPath(startOfSecond.getFile(), comparison.secondSubmission(), submissionToIdFunction).toString(),
startOfFirst.getLine(), endOfFirst.getLine(), startOfSecond.getLine(), endOfSecond.getLine(), match.length());
}

Expand Down
Loading

0 comments on commit 8861ede

Please sign in to comment.