Skip to content

Commit

Permalink
Merge pull request #1645 from jplag/bug/zipPathStructure
Browse files Browse the repository at this point in the history
Fixed wrong paths in results.zip with multiple root directories.
  • Loading branch information
tsaglam authored Mar 13, 2024
2 parents 667faa5 + 6373131 commit 53ef1b5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/de/jplag/reporting/FilePathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ 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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,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
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,9 @@ private void copySubmissionFilesToReport(JPlagResult result) {
Set<Submission> submissions = getSubmissions(comparisons);
Language language = result.getOptions().language();
for (Submission submission : submissions) {
Path submissionRootPath = SUBMISSIONS_ROOT_PATH
.resolve(FilePathUtil.forceRelativePath(Path.of(submissionToIdFunction.apply(submission))));
for (File file : submission.getFiles()) {
Path relativeFilePath = Path.of(submission.getRoot().getAbsolutePath()).relativize(Path.of(file.getAbsolutePath()));
if (relativeFilePath.getNameCount() == 0 || relativeFilePath.equals(Path.of(""))) {
relativeFilePath = Path.of(file.getName());
}
Path zipPath = submissionRootPath.resolve(relativeFilePath);
Path filePath = FilePathUtil.getRelativeSubmissionPath(file, submission, submissionToIdFunction);
Path zipPath = SUBMISSIONS_ROOT_PATH.resolve(filePath);

File fileToCopy = getFileToCopy(language, file);
this.resultWriter.addFileContentEntry(zipPath, fileToCopy);
Expand Down Expand Up @@ -177,7 +172,7 @@ private void writeSubmissionIndexFile(JPlagResult result) {
List<Map<String, Map<String, SubmissionFile>>> submissionTokenCountList = submissions.stream().parallel().map(submission -> {
Map<String, SubmissionFile> tokenCounts = new HashMap<>();
for (Map.Entry<File, Integer> entry : submission.getTokenCountPerFile().entrySet()) {
String key = FilePathUtil.getRelativeSubmissionPath(entry.getKey(), submission, submissionToIdFunction);
String key = FilePathUtil.getRelativeSubmissionPath(entry.getKey(), submission, submissionToIdFunction).toString();
tokenCounts.put(key, new SubmissionFile(entry.getValue()));
}
return Map.of(submissionNameToIdMap.get(submission.getName()), tokenCounts);
Expand Down
5 changes: 2 additions & 3 deletions report-viewer/tests/e2e/OpenComparisonTest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ const testSets: DataSet[] = [
firstSubmissionName: '0',
secondSubmissionName: '1'
},
// Disabled due to https://github.com/jplag/JPlag/issues/1610
/*{
{
datasetName: 'fileMultiRoot-report.zip',
firstSubmissionName: 'f0\\\\|/0.java',
secondSubmissionName: 'f1\\\\|/1.java'
Expand All @@ -34,7 +33,7 @@ const testSets: DataSet[] = [
datasetName: 'mixedBaseFolder-report.zip',
firstSubmissionName: 'f0\\\\|/0.java',
secondSubmissionName: 'f1\\\\|/1'
},*/
},
{
datasetName: 'folderMultiRoot-report.zip',
firstSubmissionName: 'f0\\\\|/0',
Expand Down

0 comments on commit 53ef1b5

Please sign in to comment.