Skip to content

Commit

Permalink
Merge branch 'develop' into feature/implicitViewMode
Browse files Browse the repository at this point in the history
  • Loading branch information
TwoOfTwelve committed Feb 13, 2025
2 parents b94f334 + a93c6c0 commit 652d290
Show file tree
Hide file tree
Showing 66 changed files with 1,859 additions and 240 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/scripts/checkCoverage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
import xml.etree.ElementTree as ET

def get_all_pom_files():
pom_files = []
for root, dirs, files in os.walk("../../.."):
for file in files:
if file == "pom.xml":
pom_files.append(os.path.join(root, file))
return pom_files

# get content from a file as a string
def get_file_content(file):
with open(file, "r") as f:
return f.read()

# extract xml field artifact id from string
def extract_artifact_id(xml):
root = ET.fromstring(xml)
return root.find("{http://maven.apache.org/POM/4.0.0}artifactId").text

excluded_artifacts = ["coverage-report", "aggregator", "languages"]
artifact_ids = [extract_artifact_id(get_file_content(file)) for file in get_all_pom_files()]
print("All artifacts: " + str(artifact_ids))
filtered_artifact_ids = [artifact_id for artifact_id in artifact_ids if artifact_id not in excluded_artifacts]

coverage_report_pom = ""
with open("../../../coverage-report/pom.xml", "r") as f:
coverage_report_pom = f.read()
xml = ET.fromstring(coverage_report_pom)
coverage_report_artifacts = [dependency.find("{http://maven.apache.org/POM/4.0.0}artifactId").text for dependency in xml.find("{http://maven.apache.org/POM/4.0.0}dependencies").findall("{http://maven.apache.org/POM/4.0.0}dependency")]
print("Coverage report artifacts: " + str(coverage_report_artifacts))

only_in_coverage_report = [artifact_id for artifact_id in coverage_report_artifacts if artifact_id not in filtered_artifact_ids]
print("Only in coverage report: " + str(only_in_coverage_report))
not_in_coverage_report = [artifact_id for artifact_id in filtered_artifact_ids if artifact_id not in coverage_report_artifacts]
print("Not in coverage report: " + str(not_in_coverage_report))

if len(not_in_coverage_report) > 0:
raise Exception("Some artifacts are not in the coverage report: " + str(not_in_coverage_report))
if len(only_in_coverage_report) > 0:
raise Exception("Some artifacts are only in the coverage report: " + str(only_in_coverage_report))
28 changes: 28 additions & 0 deletions .github/workflows/verify-coverage-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Check that all dependencies are in coverage report

on:
workflow_dispatch:
push:
paths:
- ".github/workflows/verify-coverage-report.yml"
- "./scripts/checkCoverage.py"
- "**/pom.xml"
pull_request:
types: [opened, synchronize, reopened]
paths:
- ".github/workflows/verify-coverage-report..yml"
- "./scripts/checkCoverage.py"
- "**/pom.xml"

jobs:
check_coverage:
runs-on: ubuntu-latest

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

- name: Run script
working-directory: .github/workflows/scripts
run: |
python checkCoverage.py
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
[![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&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 Expand Up @@ -83,22 +82,20 @@ Language-specific arguments can be set when using the subcommand. A list of lang
```
Parameter descriptions:
[root-dirs[,root-dirs...]...]
Root-directory with submissions to check for plagiarism.
Root-directory with submissions to check for
plagiarism. If mode is set to VIEW, this parameter
can be used to specify a file to open. In that case
only a single file may be specified.
-bc, --bc, --base-code=<baseCode>
Path to the base code directory (common framework used
in all submissions).
-l, --language=<language>
Select the language of the submissions (default: java).
See subcommands below.
-M, --mode=<{RUN, VIEW, RUN_AND_VIEW, AUTO}>
The mode of JPlag. By default JPlag will automatically
select the mode based on the given input files. If
none are given the report viewer will open on the
file upload page. If a single result zip is given it
will be opened in the report viewer directly.
Otherwise, JPlag will check the given submissions and
show the result in the report viewer. One of: RUN,
VIEW, RUN_AND_VIEW, AUTO (default: null)
-M, --mode=<{RUN, VIEW, RUN_AND_VIEW}>
The mode of JPlag. If VIEW is chosen, you can specify a
result file to display. One of: RUN, VIEW,
RUN_AND_VIEW (default: null)
-n, --shown-comparisons=<shownComparisons>
The maximum number of comparisons that will be shown in
the generated report, if set to -1 all comparisons
Expand Down Expand Up @@ -174,7 +171,6 @@ Languages:
javascript
kotlin
llvmir
multi
python3
rlang
rust
Expand Down
5 changes: 5 additions & 0 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@
<targetPath>report-viewer</targetPath>
<directory>../report-viewer/dist</directory>
</resource>
<!-- Even though it is already in the resources folder, it needs to be explicitly included to be part of the jar -->
<resource>
<targetPath>v5</targetPath>
<directory>src/main/resources/v5</directory>
</resource>
</resources>
<plugins>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/java/de/jplag/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void executeCli() throws ExitException, IOException {

switch (this.inputHandler.getCliOptions().mode) {
case RUN -> runJPlag();
case VIEW -> runViewer(null);
case VIEW -> runViewer(this.inputHandler.getFileForViewMode());
case RUN_AND_VIEW -> runAndView();
case AUTO -> selectModeAutomatically();
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/java/de/jplag/cli/options/CliOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class CliOptions implements Runnable {
public static final Language defaultLanguage = new JavaLanguage();

@Parameters(paramLabel = "root-dirs", description = "Root-directory with submissions to check for plagiarism.", split = ",")
@Parameters(paramLabel = "root-dirs", description = "Root-directory with submissions to check for plagiarism. If mode is set to VIEW, this parameter can be used to specify a report file to open. In that case only a single file may be specified.", split = ",")
public File[] rootDirectory = new File[0];

@Option(names = {"--new", "-new"}, split = ",", description = "Root-directories with submissions to check for plagiarism (same as root).")
Expand Down
26 changes: 26 additions & 0 deletions cli/src/main/java/de/jplag/cli/picocli/CliInputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.File;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand All @@ -29,6 +30,7 @@
public class CliInputHandler {
private static final String OPTION_LIST_HEADING = "Parameter descriptions: ";

private static final String AMBIGUOUS_VIEW_FILE = "There are multiple files specified for '--mode VIEW', please make sure only to specify one.";
private static final String UNKNOWN_LANGUAGE_EXCEPTION = "Language %s does not exists. Available languages are: %s";
private static final String IMPOSSIBLE_EXCEPTION = "This should not have happened."
+ " Please create an issue on github (https://github.com/jplag/JPlag/issues) with the entire output.";
Expand All @@ -43,6 +45,8 @@ public class CliInputHandler {
private static final String PARAMETER_SHORT_PREFIX = " -";
private static final String PARAMETER_SHORT_ADDITIONAL_INDENT = " ";

private static final char RESULT_FILE_OPTION_NAME = 'r';

private static final Random RANDOM = new SecureRandom();

private final String[] args;
Expand Down Expand Up @@ -169,4 +173,26 @@ private String generateDescription() {
var randomDescription = DESCRIPTIONS[RANDOM.nextInt(DESCRIPTIONS.length)];
return String.format(DESCRIPTION_PATTERN, randomDescription, CREDITS);
}

/**
* Returns the file to display when using --move VIEW. The result can be null, if no file was selected
* @return The file to show
* @throws CliException If multiple options would be valid
*/
public File getFileForViewMode() throws CliException {
List<File> validOptions = new ArrayList<>(List.of(this.options.rootDirectory));

validOptions.addAll(List.of(this.options.newDirectories));
validOptions.addAll(List.of(this.options.oldDirectories));

if (this.parseResult.hasMatchedOption(RESULT_FILE_OPTION_NAME)) {
validOptions.add(new File(this.options.resultFile));
}

return switch (validOptions.size()) {
case 0 -> null;
case 1 -> validOptions.getFirst();
default -> throw new CliException(AMBIGUOUS_VIEW_FILE);
};
}
}
5 changes: 5 additions & 0 deletions cli/src/main/java/de/jplag/cli/server/ReportViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ReportViewer implements HttpHandler {
private static final String REPORT_VIEWER_RESOURCE_PREFIX = "report-viewer";
private static final String INDEX_PATH = "index.html";
private static final String RESULT_PATH = "results.zip";
private static final String[] OLD_VERSION_DIRECTORIES = new String[] {"v5"};

private static final Logger logger = LoggerFactory.getLogger(ReportViewer.class);
private static final int SUCCESS_RESPONSE = 200;
Expand All @@ -45,6 +46,10 @@ public ReportViewer(File zipFile, int port) throws IOException {

this.routingTree.insertRouting("", new RoutingResources(REPORT_VIEWER_RESOURCE_PREFIX).or(new RoutingAlias(INDEX_PATH)));
this.routingTree.insertRouting(RESULT_PATH, new RoutingStaticFile(zipFile, ContentType.ZIP));
for (String version : OLD_VERSION_DIRECTORIES) {
this.routingTree.insertRouting(version, new RoutingResources(version).or(new RoutingAlias(version + "/" + INDEX_PATH)));
}

this.port = port;
}

Expand Down
9 changes: 9 additions & 0 deletions cli/src/main/resources/v5/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!doctype html>
<html lang="">
<script>
const UrlPath = window.location.pathname
const branch = UrlPath.split('/')[1]
const url = 'https://jplag.github.io/' + branch + '/'
location.replace(url)
</script>
</html>
Loading

0 comments on commit 652d290

Please sign in to comment.