Skip to content

Commit

Permalink
Fixed sonarcloud issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
TwoOfTwelve committed Nov 18, 2023
1 parent ca5af82 commit b8f061b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
20 changes: 12 additions & 8 deletions cli/src/main/java/de/jplag/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,7 @@ public static void main(String[] args) {
ReportObjectFactory reportObjectFactory = new ReportObjectFactory();
reportObjectFactory.createAndSaveReport(result, cli.getResultFolder());

if (cli.options.csv.print) {
try {
CsvComparisonOutput.writeCsvResults(result.getAllComparisons(), cli.options.csv.anonymize, new File(cli.getResultFolder()),
cli.options.csv.fileName);
} catch (IOException e) {
logger.error("Could not write csv", e);
}
}
cli.printCsv(result);
}
} catch (ExitException exception) {
logger.error(exception.getMessage()); // do not pass exception here to keep log clean
Expand All @@ -97,6 +90,17 @@ public static void main(String[] args) {
}
}

private void printCsv(JPlagResult result) {
if (options.csv.print) {
try {
CsvComparisonOutput.writeCsvResults(result.getAllComparisons(), options.csv.anonymize, new File(getResultFolder()),
options.csv.fileName);
} catch (IOException e) {
logger.error("Could not write csv", e);
}
}
}

/**
* Creates a new instance
*/
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/de/jplag/reporting/csv/CsvPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void printCell(Writer writer, String cellValue) throws IOException {
String actualValue = cellValue;
if (literalsNeeded) {
writer.write(LITERAL);
actualValue = actualValue.replaceAll("\"", "\"\"");
actualValue = actualValue.replace("\"", "\"\"");
}
writer.write(actualValue);
if (literalsNeeded) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
public class CsvComparisonOutput {
private static final String[] titles = new String[] {"submissionName1", "submissionName2", "averageSimilarity", "maxSimilarity"};

private CsvComparisonOutput() {
}

/**
* Writes the comparisons as a csv
* @param comparisons The list of comparisons
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.jplag.reporting.csv.comparisons;

import java.security.SecureRandom;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -17,11 +18,11 @@ public class NameMapperRandomIds implements NameMapper {
*/
public NameMapperRandomIds() {
this.map = new HashMap<>();
this.random = new Random();
this.random = new SecureRandom();
}

private String newId() {
String id = String.valueOf(Math.abs(random.nextInt()));
String id = String.valueOf(this.random.nextInt(0, Integer.MAX_VALUE));

if (this.map.containsKey(id)) {
return newId();
Expand Down

0 comments on commit b8f061b

Please sign in to comment.