Skip to content

Commit

Permalink
Added the option to specify a result file with --move VIEW
Browse files Browse the repository at this point in the history
  • Loading branch information
TwoOfTwelve committed Nov 20, 2024
1 parent 69cc90d commit 3079754
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ Parameter descriptions:
-l, --language=<language>
Select the language of the submissions (default: java). See subcommands below.
-M, --mode=<{RUN, VIEW, RUN_AND_VIEW}>
The mode of JPlag: either only run analysis, only open the viewer, or do both (default: null)
The mode of JPlag. If VIEW is chosen, you can specify a result file to display with either the positional argument, '--new', '--old' or '-r'. Make
sure to only specify one if you do that. One of: RUN, VIEW, RUN_AND_VIEW (default: null)
-n, --shown-comparisons=<shownComparisons>
The maximum number of comparisons that will be shown in the generated report, if set to -1 all comparisons will be shown (default: 500)
-new, --new=<newDirectories>[,<newDirectories>...]
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/java/de/jplag/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void executeCli() throws ExitException, IOException {

switch (this.inputHandler.getCliOptions().mode) {
case RUN -> runJPlag();
case VIEW -> runViewer(null);
case VIEW -> runViewer(this.inputHandler.getFileForViewMode());
case RUN_AND_VIEW -> runViewer(runJPlag());
}
}
Expand Down
3 changes: 2 additions & 1 deletion cli/src/main/java/de/jplag/cli/options/CliOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public class CliOptions implements Runnable {
"--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.")
public String resultFile = "results";

@Option(names = {"-M", "--mode"}, description = "The mode of JPlag. One of: ${COMPLETION-CANDIDATES} (default: ${DEFAULT_VALUE})")
@Option(names = {"-M",
"--mode"}, description = "The mode of JPlag. If VIEW is chosen, you can specify a result file to display with either the positional argument, '--new', '--old' or '-r'. Make sure to only specify one if you do that. One of: ${COMPLETION-CANDIDATES} (default: ${DEFAULT_VALUE})")
public JPlagMode mode = JPlagMode.RUN_AND_VIEW;

@Option(names = {"--normalize"}, description = "Activate the normalization of tokens. Supported for languages: Java, C++.")
Expand Down
24 changes: 24 additions & 0 deletions cli/src/main/java/de/jplag/cli/picocli/CliInputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.File;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand All @@ -29,6 +30,7 @@
public class CliInputHandler {
private static final String OPTION_LIST_HEADING = "Parameter descriptions: ";

private static final String AMBIGUOUS_VIEW_FILE = "There are multiple files selected for '--mode VIEW', Please make sure to only specify one.";
private static final String UNKNOWN_LANGUAGE_EXCEPTION = "Language %s does not exists. Available languages are: %s";
private static final String IMPOSSIBLE_EXCEPTION = "This should not have happened."
+ " Please create an issue on github (https://github.com/jplag/JPlag/issues) with the entire output.";
Expand Down Expand Up @@ -169,4 +171,26 @@ private String generateDescription() {
var randomDescription = DESCRIPTIONS[RANDOM.nextInt(DESCRIPTIONS.length)];
return String.format(DESCRIPTION_PATTERN, randomDescription, CREDITS);
}

/**
* Returns the file to display when using --move VIEW. The result can be null, if no file was selected
* @return The file to show
* @throws CliException If multiple options would be valid
*/
public File getFileForViewMode() throws CliException {
List<File> validOptions = new ArrayList<>(List.of(this.options.rootDirectory));

validOptions.addAll(List.of(this.options.newDirectories));
validOptions.addAll(List.of(this.options.oldDirectories));

if (this.parseResult.hasMatchedOption('r')) {
validOptions.add(new File(this.options.resultFile));
}

return switch (validOptions.size()) {
case 0 -> null;
case 1 -> validOptions.getFirst();
default -> throw new CliException(AMBIGUOUS_VIEW_FILE);
};
}
}

0 comments on commit 3079754

Please sign in to comment.