From fe7075022e720b7122f856ac74caed7d736a621d Mon Sep 17 00:00:00 2001 From: Alex | Kronox Date: Mon, 16 Oct 2023 12:11:09 +0200 Subject: [PATCH 1/8] add readme to zip --- .../jsonfactory/ComparisonReportWriter.java | 3 ++- .../reporting/jsonfactory/DummyWriter.java | 6 +++-- .../reporting/jsonfactory/FileWriter.java | 5 ---- .../reportobject/ReportObjectFactory.java | 18 +++++++++---- .../reportobject/writer/FileWriter.java | 8 ++++++ .../writer/JsonWriter.java} | 9 ++++--- .../reportobject/writer/TextWriter.java | 26 +++++++++++++++++++ .../mapper/ComparisonReportWriterTest.java | 2 +- 8 files changed, 59 insertions(+), 18 deletions(-) delete mode 100644 core/src/main/java/de/jplag/reporting/jsonfactory/FileWriter.java create mode 100644 core/src/main/java/de/jplag/reporting/reportobject/writer/FileWriter.java rename core/src/main/java/de/jplag/reporting/{jsonfactory/ToDiskWriter.java => reportobject/writer/JsonWriter.java} (79%) create mode 100644 core/src/main/java/de/jplag/reporting/reportobject/writer/TextWriter.java diff --git a/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java b/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java index 242d09138..8b0a10737 100644 --- a/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java +++ b/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java @@ -16,6 +16,7 @@ import de.jplag.reporting.FilePathUtil; import de.jplag.reporting.reportobject.model.ComparisonReport; import de.jplag.reporting.reportobject.model.Match; +import de.jplag.reporting.reportobject.writer.FileWriter; /** * Writes {@link ComparisonReport}s of given {@link JPlagResult} to the disk under the specified path. Instantiated with @@ -59,7 +60,7 @@ private void writeComparisons(String path, List comparisons) { var comparisonReport = new ComparisonReport(firstSubmissionId, secondSubmissionId, Map.of(SimilarityMetric.AVG.name(), comparison.similarity(), SimilarityMetric.MAX.name(), comparison.maximalSimilarity()), convertMatchesToReportMatches(comparison)); - fileWriter.saveAsJSON(comparisonReport, path, fileName); + fileWriter.writeFile(comparisonReport, path, fileName); }); } diff --git a/core/src/main/java/de/jplag/reporting/jsonfactory/DummyWriter.java b/core/src/main/java/de/jplag/reporting/jsonfactory/DummyWriter.java index 7f8841fc9..3a3d33069 100644 --- a/core/src/main/java/de/jplag/reporting/jsonfactory/DummyWriter.java +++ b/core/src/main/java/de/jplag/reporting/jsonfactory/DummyWriter.java @@ -3,11 +3,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class DummyWriter implements FileWriter { +import de.jplag.reporting.reportobject.writer.FileWriter; + +public class DummyWriter implements FileWriter { private static final Logger logger = LoggerFactory.getLogger(DummyWriter.class); @Override - public void saveAsJSON(Object fileToSave, String folderPath, String fileName) { + public void writeFile(Object fileToSave, String folderPath, String fileName) { logger.info("DummyWriter writes object " + fileToSave + " to path " + folderPath + " with name " + fileName + " as JSON."); } } diff --git a/core/src/main/java/de/jplag/reporting/jsonfactory/FileWriter.java b/core/src/main/java/de/jplag/reporting/jsonfactory/FileWriter.java deleted file mode 100644 index e0198684b..000000000 --- a/core/src/main/java/de/jplag/reporting/jsonfactory/FileWriter.java +++ /dev/null @@ -1,5 +0,0 @@ -package de.jplag.reporting.jsonfactory; - -public interface FileWriter { - void saveAsJSON(Object fileToSave, String folderPath, String fileName); -} diff --git a/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java b/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java index 0f8f142da..5a5983fb7 100644 --- a/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java +++ b/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java @@ -30,12 +30,13 @@ import de.jplag.Submission; import de.jplag.reporting.FilePathUtil; import de.jplag.reporting.jsonfactory.ComparisonReportWriter; -import de.jplag.reporting.jsonfactory.ToDiskWriter; import de.jplag.reporting.reportobject.mapper.ClusteringResultMapper; import de.jplag.reporting.reportobject.mapper.MetricMapper; import de.jplag.reporting.reportobject.model.OverviewReport; import de.jplag.reporting.reportobject.model.SubmissionFileIndex; import de.jplag.reporting.reportobject.model.Version; +import de.jplag.reporting.reportobject.writer.JsonWriter; +import de.jplag.reporting.reportobject.writer.TextWriter; /** * Factory class, responsible for converting a JPlagResult object to Overview and Comparison DTO classes and writing it @@ -46,8 +47,10 @@ public class ReportObjectFactory { private static final Logger logger = LoggerFactory.getLogger(ReportObjectFactory.class); - private static final ToDiskWriter fileWriter = new ToDiskWriter(); + private static final JsonWriter jsonFileWriter = new JsonWriter(); public static final String OVERVIEW_FILE_NAME = "overview.json"; + + public static final String README_FILE_NAME = "README.txt"; public static final String SUBMISSIONS_FOLDER = "files"; public static final String SUBMISSION_FILE_INDEX_FILE_NAME = "submissionFileIndex.json"; public static final Version REPORT_VIEWER_VERSION = JPlag.JPLAG_VERSION; @@ -73,6 +76,7 @@ public void createAndSaveReport(JPlagResult result, String path) { writeComparisons(result, path); writeOverview(result, path); writeSubmissionIndexFile(result, path); + writeReadMeFile(path); logger.info("Zipping report files..."); zipAndDelete(path); @@ -159,7 +163,7 @@ private File getFileToCopy(Language language, File file) { } private void writeComparisons(JPlagResult result, String path) { - ComparisonReportWriter comparisonReportWriter = new ComparisonReportWriter(submissionToIdFunction, fileWriter); + ComparisonReportWriter comparisonReportWriter = new ComparisonReportWriter(submissionToIdFunction, jsonFileWriter); submissionNameToNameToComparisonFileName = comparisonReportWriter.writeComparisonReports(result, path); } @@ -194,8 +198,12 @@ private void writeOverview(JPlagResult result, String path) { clusteringResultMapper.map(result), // clusters totalComparisons); // totalComparisons - fileWriter.saveAsJSON(overviewReport, path, OVERVIEW_FILE_NAME); + jsonFileWriter.writeFile(overviewReport, path, OVERVIEW_FILE_NAME); + + } + private void writeReadMeFile(String path) { + new TextWriter().writeFile("Test content", path, README_FILE_NAME); } private void writeSubmissionIndexFile(JPlagResult result, String path) { @@ -210,7 +218,7 @@ private void writeSubmissionIndexFile(JPlagResult result, String path) { } fileIndex.fileIndexes().put(submissionNameToIdMap.get(submission.getName()), filePaths); } - fileWriter.saveAsJSON(fileIndex, path, SUBMISSION_FILE_INDEX_FILE_NAME); + jsonFileWriter.writeFile(fileIndex, path, SUBMISSION_FILE_INDEX_FILE_NAME); } private Set getSubmissions(List comparisons) { diff --git a/core/src/main/java/de/jplag/reporting/reportobject/writer/FileWriter.java b/core/src/main/java/de/jplag/reporting/reportobject/writer/FileWriter.java new file mode 100644 index 000000000..84f6ce1cc --- /dev/null +++ b/core/src/main/java/de/jplag/reporting/reportobject/writer/FileWriter.java @@ -0,0 +1,8 @@ +package de.jplag.reporting.reportobject.writer; + +/** + * @param Object that the FileWriter writes. + */ +public interface FileWriter { + void writeFile(T fileContent, String folderPath, String fileName); +} diff --git a/core/src/main/java/de/jplag/reporting/jsonfactory/ToDiskWriter.java b/core/src/main/java/de/jplag/reporting/reportobject/writer/JsonWriter.java similarity index 79% rename from core/src/main/java/de/jplag/reporting/jsonfactory/ToDiskWriter.java rename to core/src/main/java/de/jplag/reporting/reportobject/writer/JsonWriter.java index 48722e6b1..817b068f0 100644 --- a/core/src/main/java/de/jplag/reporting/jsonfactory/ToDiskWriter.java +++ b/core/src/main/java/de/jplag/reporting/reportobject/writer/JsonWriter.java @@ -1,4 +1,4 @@ -package de.jplag.reporting.jsonfactory; +package de.jplag.reporting.reportobject.writer; import java.io.IOException; import java.nio.file.Path; @@ -8,8 +8,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; -public class ToDiskWriter implements FileWriter { - private static final Logger logger = LoggerFactory.getLogger(ToDiskWriter.class); +public class JsonWriter implements FileWriter { + private static final Logger logger = LoggerFactory.getLogger(JsonWriter.class); private static final ObjectMapper objectMapper = new ObjectMapper(); @@ -20,11 +20,12 @@ public class ToDiskWriter implements FileWriter { * @param fileName The name to save the object under */ @Override - public void saveAsJSON(Object fileToSave, String folderPath, String fileName) { + public void writeFile(Object fileToSave, String folderPath, String fileName) { try { objectMapper.writeValue(Path.of(folderPath, fileName).toFile(), fileToSave); } catch (IOException e) { logger.error("Failed to save json file " + fileName + ": " + e.getMessage(), e); } } + } diff --git a/core/src/main/java/de/jplag/reporting/reportobject/writer/TextWriter.java b/core/src/main/java/de/jplag/reporting/reportobject/writer/TextWriter.java new file mode 100644 index 000000000..4f168b311 --- /dev/null +++ b/core/src/main/java/de/jplag/reporting/reportobject/writer/TextWriter.java @@ -0,0 +1,26 @@ +package de.jplag.reporting.reportobject.writer; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.file.Path; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TextWriter implements FileWriter { + + private static final Logger logger = LoggerFactory.getLogger(TextWriter.class); + private static final String WRITE_ERROR = "Failed to write text file {}"; + + @Override + public void writeFile(String fileContent, String folderPath, String fileName) { + String path = Path.of(folderPath, fileName).toString(); + try { + BufferedWriter writer = new BufferedWriter(new java.io.FileWriter(path)); + writer.write(fileContent); + writer.close(); + } catch (IOException e) { + logger.error(WRITE_ERROR, e, path); + } + } +} diff --git a/core/src/test/java/de/jplag/reporting/reportobject/mapper/ComparisonReportWriterTest.java b/core/src/test/java/de/jplag/reporting/reportobject/mapper/ComparisonReportWriterTest.java index ffde264e9..98fc2ff72 100644 --- a/core/src/test/java/de/jplag/reporting/reportobject/mapper/ComparisonReportWriterTest.java +++ b/core/src/test/java/de/jplag/reporting/reportobject/mapper/ComparisonReportWriterTest.java @@ -11,7 +11,7 @@ import de.jplag.exceptions.ExitException; import de.jplag.reporting.jsonfactory.ComparisonReportWriter; import de.jplag.reporting.jsonfactory.DummyWriter; -import de.jplag.reporting.jsonfactory.FileWriter; +import de.jplag.reporting.reportobject.writer.FileWriter; public class ComparisonReportWriterTest extends TestBase { private final FileWriter fileWriter = new DummyWriter(); From 7a258da03342cccc4b112688de2c1fdd67a468ee Mon Sep 17 00:00:00 2001 From: Alex | Kronox Date: Mon, 16 Oct 2023 12:57:45 +0200 Subject: [PATCH 2/8] improve documentation --- .../reporting/reportobject/ReportObjectFactory.java | 4 +++- .../jplag/reporting/reportobject/writer/FileWriter.java | 8 ++++++++ .../jplag/reporting/reportobject/writer/JsonWriter.java | 9 +++------ .../jplag/reporting/reportobject/writer/TextWriter.java | 3 +++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java b/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java index 5a5983fb7..1be304a3b 100644 --- a/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java +++ b/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java @@ -51,6 +51,8 @@ public class ReportObjectFactory { public static final String OVERVIEW_FILE_NAME = "overview.json"; public static final String README_FILE_NAME = "README.txt"; + public static final String README_CONTENT = "To view the results go to https://jplag.github.io/JPlag/ and drag the generated zip file onto the page."; + public static final String SUBMISSIONS_FOLDER = "files"; public static final String SUBMISSION_FILE_INDEX_FILE_NAME = "submissionFileIndex.json"; public static final Version REPORT_VIEWER_VERSION = JPlag.JPLAG_VERSION; @@ -203,7 +205,7 @@ private void writeOverview(JPlagResult result, String path) { } private void writeReadMeFile(String path) { - new TextWriter().writeFile("Test content", path, README_FILE_NAME); + new TextWriter().writeFile(README_CONTENT, path, README_FILE_NAME); } private void writeSubmissionIndexFile(JPlagResult result, String path) { diff --git a/core/src/main/java/de/jplag/reporting/reportobject/writer/FileWriter.java b/core/src/main/java/de/jplag/reporting/reportobject/writer/FileWriter.java index 84f6ce1cc..ec8888a49 100644 --- a/core/src/main/java/de/jplag/reporting/reportobject/writer/FileWriter.java +++ b/core/src/main/java/de/jplag/reporting/reportobject/writer/FileWriter.java @@ -1,8 +1,16 @@ package de.jplag.reporting.reportobject.writer; /** + * Responsible for writing a specific file type to the disk. * @param Object that the FileWriter writes. */ public interface FileWriter { + + /** + * Saves the provided object to the provided path under the provided name + * @param fileContent The object to save + * @param folderPath The path to save the object to + * @param fileName The name to save the object under + */ void writeFile(T fileContent, String folderPath, String fileName); } diff --git a/core/src/main/java/de/jplag/reporting/reportobject/writer/JsonWriter.java b/core/src/main/java/de/jplag/reporting/reportobject/writer/JsonWriter.java index 817b068f0..165742652 100644 --- a/core/src/main/java/de/jplag/reporting/reportobject/writer/JsonWriter.java +++ b/core/src/main/java/de/jplag/reporting/reportobject/writer/JsonWriter.java @@ -8,17 +8,14 @@ import com.fasterxml.jackson.databind.ObjectMapper; +/** + * Writes an object with {@link com.fasterxml.jackson.annotation.JsonProperty}s to the disk. + */ public class JsonWriter implements FileWriter { private static final Logger logger = LoggerFactory.getLogger(JsonWriter.class); private static final ObjectMapper objectMapper = new ObjectMapper(); - /** - * Saves the provided object to the provided path under the provided name - * @param fileToSave The object to save - * @param folderPath The path to save the object to - * @param fileName The name to save the object under - */ @Override public void writeFile(Object fileToSave, String folderPath, String fileName) { try { diff --git a/core/src/main/java/de/jplag/reporting/reportobject/writer/TextWriter.java b/core/src/main/java/de/jplag/reporting/reportobject/writer/TextWriter.java index 4f168b311..ebf6d7dca 100644 --- a/core/src/main/java/de/jplag/reporting/reportobject/writer/TextWriter.java +++ b/core/src/main/java/de/jplag/reporting/reportobject/writer/TextWriter.java @@ -7,6 +7,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * Writes plain text to a file. + */ public class TextWriter implements FileWriter { private static final Logger logger = LoggerFactory.getLogger(TextWriter.class); From debfed521f225541261a5b8fdd7ce1ee4451b2a7 Mon Sep 17 00:00:00 2001 From: Alexander Vogt Date: Mon, 30 Oct 2023 14:56:51 +0100 Subject: [PATCH 3/8] Change to try with resource --- .../{jsonfactory => reportobject/writer}/DummyWriter.java | 4 +--- .../de/jplag/reporting/reportobject/writer/JsonWriter.java | 7 ++++--- .../de/jplag/reporting/reportobject/writer/TextWriter.java | 4 +--- .../reportobject/mapper/ComparisonReportWriterTest.java | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) rename core/src/main/java/de/jplag/reporting/{jsonfactory => reportobject/writer}/DummyWriter.java (81%) diff --git a/core/src/main/java/de/jplag/reporting/jsonfactory/DummyWriter.java b/core/src/main/java/de/jplag/reporting/reportobject/writer/DummyWriter.java similarity index 81% rename from core/src/main/java/de/jplag/reporting/jsonfactory/DummyWriter.java rename to core/src/main/java/de/jplag/reporting/reportobject/writer/DummyWriter.java index 3a3d33069..1f39def90 100644 --- a/core/src/main/java/de/jplag/reporting/jsonfactory/DummyWriter.java +++ b/core/src/main/java/de/jplag/reporting/reportobject/writer/DummyWriter.java @@ -1,10 +1,8 @@ -package de.jplag.reporting.jsonfactory; +package de.jplag.reporting.reportobject.writer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import de.jplag.reporting.reportobject.writer.FileWriter; - public class DummyWriter implements FileWriter { private static final Logger logger = LoggerFactory.getLogger(DummyWriter.class); diff --git a/core/src/main/java/de/jplag/reporting/reportobject/writer/JsonWriter.java b/core/src/main/java/de/jplag/reporting/reportobject/writer/JsonWriter.java index 165742652..723718cf8 100644 --- a/core/src/main/java/de/jplag/reporting/reportobject/writer/JsonWriter.java +++ b/core/src/main/java/de/jplag/reporting/reportobject/writer/JsonWriter.java @@ -13,15 +13,16 @@ */ public class JsonWriter implements FileWriter { private static final Logger logger = LoggerFactory.getLogger(JsonWriter.class); - private static final ObjectMapper objectMapper = new ObjectMapper(); + private static final String WRITE_ERROR = "Failed to write JSON file {}"; @Override public void writeFile(Object fileToSave, String folderPath, String fileName) { + Path path = Path.of(folderPath, fileName); try { - objectMapper.writeValue(Path.of(folderPath, fileName).toFile(), fileToSave); + objectMapper.writeValue(path.toFile(), fileToSave); } catch (IOException e) { - logger.error("Failed to save json file " + fileName + ": " + e.getMessage(), e); + logger.error(WRITE_ERROR, e, path); } } diff --git a/core/src/main/java/de/jplag/reporting/reportobject/writer/TextWriter.java b/core/src/main/java/de/jplag/reporting/reportobject/writer/TextWriter.java index ebf6d7dca..d4b3601d4 100644 --- a/core/src/main/java/de/jplag/reporting/reportobject/writer/TextWriter.java +++ b/core/src/main/java/de/jplag/reporting/reportobject/writer/TextWriter.java @@ -18,10 +18,8 @@ public class TextWriter implements FileWriter { @Override public void writeFile(String fileContent, String folderPath, String fileName) { String path = Path.of(folderPath, fileName).toString(); - try { - BufferedWriter writer = new BufferedWriter(new java.io.FileWriter(path)); + try (BufferedWriter writer = new BufferedWriter(new java.io.FileWriter(path))) { writer.write(fileContent); - writer.close(); } catch (IOException e) { logger.error(WRITE_ERROR, e, path); } diff --git a/core/src/test/java/de/jplag/reporting/reportobject/mapper/ComparisonReportWriterTest.java b/core/src/test/java/de/jplag/reporting/reportobject/mapper/ComparisonReportWriterTest.java index 98fc2ff72..22b725798 100644 --- a/core/src/test/java/de/jplag/reporting/reportobject/mapper/ComparisonReportWriterTest.java +++ b/core/src/test/java/de/jplag/reporting/reportobject/mapper/ComparisonReportWriterTest.java @@ -10,7 +10,7 @@ import de.jplag.TestBase; import de.jplag.exceptions.ExitException; import de.jplag.reporting.jsonfactory.ComparisonReportWriter; -import de.jplag.reporting.jsonfactory.DummyWriter; +import de.jplag.reporting.reportobject.writer.DummyWriter; import de.jplag.reporting.reportobject.writer.FileWriter; public class ComparisonReportWriterTest extends TestBase { From 080fe2001e6acfa7ea953fe909d501036ddc974f Mon Sep 17 00:00:00 2001 From: Alexander Vogt Date: Mon, 30 Oct 2023 15:53:03 +0100 Subject: [PATCH 4/8] Fix Code smells --- .../jplag/reporting/jsonfactory/ComparisonReportWriter.java | 4 ++-- .../de/jplag/reporting/reportobject/writer/DummyWriter.java | 3 ++- .../reportobject/mapper/ComparisonReportWriterTest.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java b/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java index 8b0a10737..2147761a0 100644 --- a/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java +++ b/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java @@ -24,12 +24,12 @@ */ public class ComparisonReportWriter { - private final FileWriter fileWriter; + private final FileWriter fileWriter; private final Function submissionToIdFunction; private final Map> submissionIdToComparisonFileName = new ConcurrentHashMap<>(); private final Map fileNameCollisions = new ConcurrentHashMap<>(); - public ComparisonReportWriter(Function submissionToIdFunction, FileWriter fileWriter) { + public ComparisonReportWriter(Function submissionToIdFunction, FileWriter fileWriter) { this.submissionToIdFunction = submissionToIdFunction; this.fileWriter = fileWriter; } diff --git a/core/src/main/java/de/jplag/reporting/reportobject/writer/DummyWriter.java b/core/src/main/java/de/jplag/reporting/reportobject/writer/DummyWriter.java index 1f39def90..be301b9c5 100644 --- a/core/src/main/java/de/jplag/reporting/reportobject/writer/DummyWriter.java +++ b/core/src/main/java/de/jplag/reporting/reportobject/writer/DummyWriter.java @@ -5,9 +5,10 @@ public class DummyWriter implements FileWriter { private static final Logger logger = LoggerFactory.getLogger(DummyWriter.class); + private static final String MESSAGE = "DummyWriter writes object {} to path {} with name {} as JSON."; @Override public void writeFile(Object fileToSave, String folderPath, String fileName) { - logger.info("DummyWriter writes object " + fileToSave + " to path " + folderPath + " with name " + fileName + " as JSON."); + logger.info(MESSAGE, fileToSave, folderPath, fileName); } } diff --git a/core/src/test/java/de/jplag/reporting/reportobject/mapper/ComparisonReportWriterTest.java b/core/src/test/java/de/jplag/reporting/reportobject/mapper/ComparisonReportWriterTest.java index 22b725798..2af3fd15a 100644 --- a/core/src/test/java/de/jplag/reporting/reportobject/mapper/ComparisonReportWriterTest.java +++ b/core/src/test/java/de/jplag/reporting/reportobject/mapper/ComparisonReportWriterTest.java @@ -14,7 +14,7 @@ import de.jplag.reporting.reportobject.writer.FileWriter; public class ComparisonReportWriterTest extends TestBase { - private final FileWriter fileWriter = new DummyWriter(); + private final FileWriter fileWriter = new DummyWriter(); @Test public void firsLevelOfLookupMapComplete() throws ExitException { From c1e8b6be9b44597003d9c965d93e52e2f5878e6f Mon Sep 17 00:00:00 2001 From: Alex | Kronox Date: Wed, 15 Nov 2023 11:23:59 +0100 Subject: [PATCH 5/8] switch to json writer --- .../jplag/reporting/jsonfactory/ComparisonReportWriter.java | 6 +++--- .../de/jplag/reporting/reportobject/writer/DummyWriter.java | 2 +- .../reportobject/mapper/ComparisonReportWriterTest.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java b/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java index 2147761a0..8ebb4c555 100644 --- a/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java +++ b/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java @@ -16,7 +16,7 @@ import de.jplag.reporting.FilePathUtil; import de.jplag.reporting.reportobject.model.ComparisonReport; import de.jplag.reporting.reportobject.model.Match; -import de.jplag.reporting.reportobject.writer.FileWriter; +import de.jplag.reporting.reportobject.writer.JsonWriter; /** * Writes {@link ComparisonReport}s of given {@link JPlagResult} to the disk under the specified path. Instantiated with @@ -24,12 +24,12 @@ */ public class ComparisonReportWriter { - private final FileWriter fileWriter; + private final JsonWriter fileWriter; private final Function submissionToIdFunction; private final Map> submissionIdToComparisonFileName = new ConcurrentHashMap<>(); private final Map fileNameCollisions = new ConcurrentHashMap<>(); - public ComparisonReportWriter(Function submissionToIdFunction, FileWriter fileWriter) { + public ComparisonReportWriter(Function submissionToIdFunction, JsonWriter fileWriter) { this.submissionToIdFunction = submissionToIdFunction; this.fileWriter = fileWriter; } diff --git a/core/src/main/java/de/jplag/reporting/reportobject/writer/DummyWriter.java b/core/src/main/java/de/jplag/reporting/reportobject/writer/DummyWriter.java index be301b9c5..92258482f 100644 --- a/core/src/main/java/de/jplag/reporting/reportobject/writer/DummyWriter.java +++ b/core/src/main/java/de/jplag/reporting/reportobject/writer/DummyWriter.java @@ -3,7 +3,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class DummyWriter implements FileWriter { +public class DummyWriter extends JsonWriter { private static final Logger logger = LoggerFactory.getLogger(DummyWriter.class); private static final String MESSAGE = "DummyWriter writes object {} to path {} with name {} as JSON."; diff --git a/core/src/test/java/de/jplag/reporting/reportobject/mapper/ComparisonReportWriterTest.java b/core/src/test/java/de/jplag/reporting/reportobject/mapper/ComparisonReportWriterTest.java index 2af3fd15a..02af18f52 100644 --- a/core/src/test/java/de/jplag/reporting/reportobject/mapper/ComparisonReportWriterTest.java +++ b/core/src/test/java/de/jplag/reporting/reportobject/mapper/ComparisonReportWriterTest.java @@ -11,10 +11,10 @@ import de.jplag.exceptions.ExitException; import de.jplag.reporting.jsonfactory.ComparisonReportWriter; import de.jplag.reporting.reportobject.writer.DummyWriter; -import de.jplag.reporting.reportobject.writer.FileWriter; +import de.jplag.reporting.reportobject.writer.JsonWriter; public class ComparisonReportWriterTest extends TestBase { - private final FileWriter fileWriter = new DummyWriter(); + private final JsonWriter fileWriter = new DummyWriter(); @Test public void firsLevelOfLookupMapComplete() throws ExitException { From e1a418fecaef94f329bf7e666c4bd8e0cd9a5441 Mon Sep 17 00:00:00 2001 From: Alex | Kronox Date: Mon, 27 Nov 2023 15:39:29 +0100 Subject: [PATCH 6/8] improve text --- .../de/jplag/reporting/reportobject/ReportObjectFactory.java | 5 +++-- .../de/jplag/reporting/reportobject/writer/DummyWriter.java | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java b/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java index 1be304a3b..13a23cc0b 100644 --- a/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java +++ b/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java @@ -51,7 +51,8 @@ public class ReportObjectFactory { public static final String OVERVIEW_FILE_NAME = "overview.json"; public static final String README_FILE_NAME = "README.txt"; - public static final String README_CONTENT = "To view the results go to https://jplag.github.io/JPlag/ and drag the generated zip file onto the page."; + public static final String[] README_CONTENT = new String[] {"This is a software plagiarism report generated by JPlag.", + "To view the results go to https://jplag.github.io/JPlag/ and drag the generated zip file onto the page."}; public static final String SUBMISSIONS_FOLDER = "files"; public static final String SUBMISSION_FILE_INDEX_FILE_NAME = "submissionFileIndex.json"; @@ -205,7 +206,7 @@ private void writeOverview(JPlagResult result, String path) { } private void writeReadMeFile(String path) { - new TextWriter().writeFile(README_CONTENT, path, README_FILE_NAME); + new TextWriter().writeFile(String.join(System.lineSeparator(), README_CONTENT), path, README_FILE_NAME); } private void writeSubmissionIndexFile(JPlagResult result, String path) { diff --git a/core/src/main/java/de/jplag/reporting/reportobject/writer/DummyWriter.java b/core/src/main/java/de/jplag/reporting/reportobject/writer/DummyWriter.java index 92258482f..c344802dc 100644 --- a/core/src/main/java/de/jplag/reporting/reportobject/writer/DummyWriter.java +++ b/core/src/main/java/de/jplag/reporting/reportobject/writer/DummyWriter.java @@ -3,6 +3,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * This writer is used as a mock for testing purposes only. + */ public class DummyWriter extends JsonWriter { private static final Logger logger = LoggerFactory.getLogger(DummyWriter.class); private static final String MESSAGE = "DummyWriter writes object {} to path {} with name {} as JSON."; From 50e338fe1c33ad003f72160e8f53e7299f5a4f97 Mon Sep 17 00:00:00 2001 From: Alex | Kronox Date: Mon, 27 Nov 2023 15:40:17 +0100 Subject: [PATCH 7/8] change comment --- .../de/jplag/reporting/reportobject/ReportObjectFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java b/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java index 13a23cc0b..50bbd2015 100644 --- a/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java +++ b/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java @@ -52,7 +52,7 @@ public class ReportObjectFactory { public static final String README_FILE_NAME = "README.txt"; public static final String[] README_CONTENT = new String[] {"This is a software plagiarism report generated by JPlag.", - "To view the results go to https://jplag.github.io/JPlag/ and drag the generated zip file onto the page."}; + "To view the report go to https://jplag.github.io/JPlag/ and drag the generated zip file onto the page."}; public static final String SUBMISSIONS_FOLDER = "files"; public static final String SUBMISSION_FILE_INDEX_FILE_NAME = "submissionFileIndex.json"; From 68f8066fb1edae637288309a04e5cdb7576492bd Mon Sep 17 00:00:00 2001 From: Alex | Kronox Date: Tue, 28 Nov 2023 17:19:31 +0100 Subject: [PATCH 8/8] make readme content private --- .../de/jplag/reporting/reportobject/ReportObjectFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java b/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java index 50bbd2015..342338fe7 100644 --- a/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java +++ b/core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java @@ -51,7 +51,7 @@ public class ReportObjectFactory { public static final String OVERVIEW_FILE_NAME = "overview.json"; public static final String README_FILE_NAME = "README.txt"; - public static final String[] README_CONTENT = new String[] {"This is a software plagiarism report generated by JPlag.", + private static final String[] README_CONTENT = new String[] {"This is a software plagiarism report generated by JPlag.", "To view the report go to https://jplag.github.io/JPlag/ and drag the generated zip file onto the page."}; public static final String SUBMISSIONS_FOLDER = "files";