From a6ccc061db75c270ebcf0814aa0524880184f50d Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Fri, 16 Feb 2024 09:14:16 +0100 Subject: [PATCH 1/4] Renamed the result-directory option to result-file --- cli/src/main/java/de/jplag/cli/CLI.java | 22 ++++++++++++++----- .../main/java/de/jplag/cli/CliOptions.java | 4 ++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/cli/src/main/java/de/jplag/cli/CLI.java b/cli/src/main/java/de/jplag/cli/CLI.java index 0a93d14d2..72d00c9ed 100644 --- a/cli/src/main/java/de/jplag/cli/CLI.java +++ b/cli/src/main/java/de/jplag/cli/CLI.java @@ -64,6 +64,8 @@ public final class CLI { private static final String DESCRIPTION_PATTERN = "%nJPlag - %s%n%s%n%n"; + private static final String DEFAULT_FILE_ENDING = ".zip"; + /** * Main class for using JPlag via the CLI. * @param args are the CLI arguments that will be passed to JPlag. @@ -79,10 +81,10 @@ public static void main(String[] args) { if (!parseResult.isUsageHelpRequested() && !(parseResult.subcommand() != null && parseResult.subcommand().isUsageHelpRequested())) { JPlagOptions options = cli.buildOptionsFromArguments(parseResult); JPlagResult result = JPlag.run(options); - ReportObjectFactory reportObjectFactory = new ReportObjectFactory(new File(cli.getResultFolder() + ".zip")); + ReportObjectFactory reportObjectFactory = new ReportObjectFactory(new File(cli.getResultFilePath())); reportObjectFactory.createAndSaveReport(result); - OutputFileGenerator.generateCsvOutput(result, new File(cli.getResultFolder()), cli.options); + OutputFileGenerator.generateCsvOutput(result, new File(cli.getResultFileBaseName()), cli.options); } } catch (ExitException | FileNotFoundException exception) { logger.error(exception.getMessage()); // do not pass exception here to keep log clean @@ -144,7 +146,7 @@ public ParseResult parseOptions(String... args) throws CliException { } return result; } catch (CommandLine.ParameterException e) { - if (e.getArgSpec().isOption() && Arrays.asList(((OptionSpec) e.getArgSpec()).names()).contains("-l")) { + if (e.getArgSpec() != null && e.getArgSpec().isOption() && Arrays.asList(((OptionSpec) e.getArgSpec()).names()).contains("-l")) { throw new CliException(String.format(UNKOWN_LANGAUGE_EXCEPTION, e.getValue(), String.join(", ", LanguageLoader.getAllAvailableLanguageIdentifiers()))); } @@ -250,7 +252,17 @@ private String generateDescription() { return String.format(DESCRIPTION_PATTERN, randomDescription, CREDITS); } - public String getResultFolder() { - return this.options.resultFolder; + private String getResultFilePath() { + String optionValue = this.options.resultFile; + if(optionValue.endsWith(DEFAULT_FILE_ENDING)) { + return optionValue; + } else { + return optionValue + DEFAULT_FILE_ENDING; + } + } + + private String getResultFileBaseName() { + String defaultOutputFile = getResultFilePath(); + return defaultOutputFile.substring(0, defaultOutputFile.length() - DEFAULT_FILE_ENDING.length()); } } diff --git a/cli/src/main/java/de/jplag/cli/CliOptions.java b/cli/src/main/java/de/jplag/cli/CliOptions.java index da249342c..c43ea7d22 100644 --- a/cli/src/main/java/de/jplag/cli/CliOptions.java +++ b/cli/src/main/java/de/jplag/cli/CliOptions.java @@ -50,8 +50,8 @@ public class CliOptions implements Runnable { public int shownComparisons = JPlagOptions.DEFAULT_SHOWN_COMPARISONS; @Option(names = {"-r", - "--result-directory"}, description = "Name of the directory in which the comparison results will be stored (default: ${DEFAULT-VALUE})%n") - public String resultFolder = "results"; + "--result-file"}, description = "Name of the file in which the comparison results will be stored (default: ${DEFAULT-VALUE}). Missing .zip endings will be automatically added.%n") + public String resultFile = "results"; @ArgGroup(heading = "Advanced%n", exclusive = false) public Advanced advanced = new Advanced(); From 36de011439ed78ff19fe57088cd2834440bb6d44 Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Fri, 16 Feb 2024 09:19:20 +0100 Subject: [PATCH 2/4] spotless --- cli/src/main/java/de/jplag/cli/CLI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/main/java/de/jplag/cli/CLI.java b/cli/src/main/java/de/jplag/cli/CLI.java index 72d00c9ed..c1eba5f7f 100644 --- a/cli/src/main/java/de/jplag/cli/CLI.java +++ b/cli/src/main/java/de/jplag/cli/CLI.java @@ -254,7 +254,7 @@ private String generateDescription() { private String getResultFilePath() { String optionValue = this.options.resultFile; - if(optionValue.endsWith(DEFAULT_FILE_ENDING)) { + if (optionValue.endsWith(DEFAULT_FILE_ENDING)) { return optionValue; } else { return optionValue + DEFAULT_FILE_ENDING; From 8b26c7f4722fa916581bfdc99d5ddf6af404e796 Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Fri, 16 Feb 2024 09:24:12 +0100 Subject: [PATCH 3/4] Fixed error in ScalaLanguageTest due to Language interface change. --- .../scala/src/test/java/de/jplag/scala/ScalaLanguageTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/languages/scala/src/test/java/de/jplag/scala/ScalaLanguageTest.java b/languages/scala/src/test/java/de/jplag/scala/ScalaLanguageTest.java index fc659f083..2f0660b54 100644 --- a/languages/scala/src/test/java/de/jplag/scala/ScalaLanguageTest.java +++ b/languages/scala/src/test/java/de/jplag/scala/ScalaLanguageTest.java @@ -19,6 +19,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import de.jplag.ParsingException; import de.jplag.SharedTokenType; import de.jplag.Token; import de.jplag.TokenPrinter; @@ -57,7 +58,7 @@ void setup() { } @Test - void parseTestFiles() { + void parseTestFiles() throws ParsingException { for (String fileName : testFiles) { List tokens = language.parse(Set.of(new File(testFileLocation, fileName))); String output = TokenPrinter.printTokens(tokens, testFileLocation); From 0be10a0da41c8c8735a9029697ad189c277eb0ff Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Fri, 16 Feb 2024 09:24:56 +0100 Subject: [PATCH 4/4] Revert "Fixed error in ScalaLanguageTest due to Language interface change." This reverts commit 8b26c7f4722fa916581bfdc99d5ddf6af404e796. --- .../scala/src/test/java/de/jplag/scala/ScalaLanguageTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/languages/scala/src/test/java/de/jplag/scala/ScalaLanguageTest.java b/languages/scala/src/test/java/de/jplag/scala/ScalaLanguageTest.java index 2f0660b54..fc659f083 100644 --- a/languages/scala/src/test/java/de/jplag/scala/ScalaLanguageTest.java +++ b/languages/scala/src/test/java/de/jplag/scala/ScalaLanguageTest.java @@ -19,7 +19,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import de.jplag.ParsingException; import de.jplag.SharedTokenType; import de.jplag.Token; import de.jplag.TokenPrinter; @@ -58,7 +57,7 @@ void setup() { } @Test - void parseTestFiles() throws ParsingException { + void parseTestFiles() { for (String fileName : testFiles) { List tokens = language.parse(Set.of(new File(testFileLocation, fileName))); String output = TokenPrinter.printTokens(tokens, testFileLocation);