Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into report-viewer/clus…
Browse files Browse the repository at this point in the history
…ter-graph
  • Loading branch information
Kr0nox committed Dec 7, 2023
2 parents b359120 + cccc893 commit 4e5d7fb
Show file tree
Hide file tree
Showing 29 changed files with 1,567 additions and 345 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
Expand All @@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
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 @@ -25,7 +25,7 @@ jobs:
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21
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 @@ -48,7 +48,7 @@ jobs:
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/spotless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
Expand Down
21 changes: 0 additions & 21 deletions core/src/main/java/de/jplag/Messages.java

This file was deleted.

2 changes: 1 addition & 1 deletion core/src/main/java/de/jplag/options/JPlagOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public record JPlagOptions(Language language, Integer minimumTokenMatch, Set<Fil
boolean debugParser, MergingOptions mergingOptions) {

public static final double DEFAULT_SIMILARITY_THRESHOLD = 0;
public static final int DEFAULT_SHOWN_COMPARISONS = 100;
public static final int DEFAULT_SHOWN_COMPARISONS = 500;
public static final int SHOW_ALL_COMPARISONS = 0;
public static final SimilarityMetric DEFAULT_SIMILARITY_METRIC = SimilarityMetric.AVG;
public static final Charset CHARSET = StandardCharsets.UTF_8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@
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.JsonWriter;

/**
* Writes {@link ComparisonReport}s of given {@link JPlagResult} to the disk under the specified path. Instantiated with
* a function that associates a submission to its id.
*/
public class ComparisonReportWriter {

private final FileWriter fileWriter;
private final JsonWriter fileWriter;
private final Function<Submission, String> submissionToIdFunction;
private final Map<String, Map<String, String>> submissionIdToComparisonFileName = new ConcurrentHashMap<>();
private final Map<String, AtomicInteger> fileNameCollisions = new ConcurrentHashMap<>();

public ComparisonReportWriter(Function<Submission, String> submissionToIdFunction, FileWriter fileWriter) {
public ComparisonReportWriter(Function<Submission, String> submissionToIdFunction, JsonWriter fileWriter) {
this.submissionToIdFunction = submissionToIdFunction;
this.fileWriter = fileWriter;
}
Expand Down Expand Up @@ -59,7 +60,7 @@ private void writeComparisons(String path, List<JPlagComparison> 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);
});
}

Expand Down
13 changes: 0 additions & 13 deletions core/src/main/java/de/jplag/reporting/jsonfactory/DummyWriter.java

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,8 +47,13 @@ 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";
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";
public static final String SUBMISSION_FILE_INDEX_FILE_NAME = "submissionFileIndex.json";
public static final Version REPORT_VIEWER_VERSION = JPlag.JPLAG_VERSION;
Expand All @@ -73,6 +79,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);
Expand Down Expand Up @@ -159,7 +166,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);
}

Expand Down Expand Up @@ -194,8 +201,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(String.join(System.lineSeparator(), README_CONTENT), path, README_FILE_NAME);
}

private void writeSubmissionIndexFile(JPlagResult result, String path) {
Expand All @@ -210,7 +221,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<Submission> getSubmissions(List<JPlagComparison> comparisons) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.jplag.reporting.reportobject.writer;

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.";

@Override
public void writeFile(Object fileToSave, String folderPath, String fileName) {
logger.info(MESSAGE, fileToSave, folderPath, fileName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.jplag.reporting.reportobject.writer;

/**
* Responsible for writing a specific file type to the disk.
* @param <T> Object that the FileWriter writes.
*/
public interface FileWriter<T> {

/**
* 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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package de.jplag.reporting.reportobject.writer;

import java.io.IOException;
import java.nio.file.Path;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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<Object> {
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.toFile(), fileToSave);
} catch (IOException e) {
logger.error(WRITE_ERROR, e, path);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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;

/**
* Writes plain text to a file.
*/
public class TextWriter implements FileWriter<String> {

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);
} catch (IOException e) {
logger.error(WRITE_ERROR, e, path);
}
}
}
29 changes: 0 additions & 29 deletions core/src/main/resources/de/jplag/messages.properties

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
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.jsonfactory.FileWriter;
import de.jplag.reporting.reportobject.writer.DummyWriter;
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 {
Expand Down
6 changes: 6 additions & 0 deletions endtoend-testing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<version>1.2.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit 4e5d7fb

Please sign in to comment.