Просмотр исходного кода

Add options for specifying root directories with new or prior submissions.

Alberth 4 лет назад
Родитель
Сommit
9978a519aa

+ 15 - 2
jplag/src/main/java/de/jplag/CLI.java

@@ -2,6 +2,7 @@ package de.jplag;
 
 import static de.jplag.CommandLineArgument.*;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
 import java.util.Random;
@@ -100,8 +101,12 @@ public class CLI {
             fileSuffixes = fileSuffixString.replaceAll("\\s+", "").split(",");
         }
 
-        List<String> plagiarismCheckRootDirectoryNames = ROOT_DIRECTORY.getListFrom(namespace);
-        List<String> priorSubmissionsRootDirectoryNames = List.of();
+        // Collect the root directories.
+        List<String> plagiarismCheckRootDirectoryNames = new ArrayList<>();
+        List<String> priorSubmissionsRootDirectoryNames = new ArrayList<>();
+        addAllMultiValueArgument(ROOT_DIRECTORY.getListFrom(namespace), plagiarismCheckRootDirectoryNames);
+        addAllMultiValueArgument(PLAGIARISM_DIRECTORY.getListFrom(namespace), plagiarismCheckRootDirectoryNames);
+        addAllMultiValueArgument(PRIOR_DIRECTORY.getListFrom(namespace), priorSubmissionsRootDirectoryNames);
 
         LanguageOption language = LanguageOption.fromDisplayName(LANGUAGE.getFrom(namespace));
         JPlagOptions options = new JPlagOptions(plagiarismCheckRootDirectoryNames, priorSubmissionsRootDirectoryNames, language);
@@ -157,4 +162,12 @@ public class CLI {
         var randomDescription = DESCRIPTIONS[new Random().nextInt(DESCRIPTIONS.length)];
         return String.format("JPlag - %s" + System.lineSeparator() + CREDITS, randomDescription);
     }
+
+    private void addAllMultiValueArgument(List<List<String>> argumentValues, List<String> destinationRootDirectoryNames) {
+        if (argumentValues == null) {
+            return;
+        }
+
+        argumentValues.stream().forEach(value -> destinationRootDirectoryNames.addAll(value));
+    }
 }

+ 9 - 3
jplag/src/main/java/de/jplag/CommandLineArgument.java

@@ -5,6 +5,7 @@ import static de.jplag.CLI.CLUSTERING_PREPROCESSING_GROUP_NAME;
 import static de.jplag.options.JPlagOptions.DEFAULT_COMPARISON_MODE;
 import static de.jplag.options.JPlagOptions.DEFAULT_SHOWN_COMPARISONS;
 import static de.jplag.options.JPlagOptions.DEFAULT_SIMILARITY_THRESHOLD;
+import static net.sourceforge.argparse4j.impl.Arguments.append;
 import static net.sourceforge.argparse4j.impl.Arguments.storeTrue;
 
 import java.util.Collection;
@@ -30,8 +31,9 @@ import de.jplag.strategy.ComparisonMode;
  * @author Timur Saglam
  */
 public enum CommandLineArgument {
-
-    ROOT_DIRECTORY(new Builder("rootDir", String.class).nargs(NumberOfArgumentValues.ONE_OR_MORE_VALUES)),
+    ROOT_DIRECTORY(new Builder("rootDir", String.class).nargs(NumberOfArgumentValues.ZERO_OR_MORE_VALUES)),
+    PLAGIARISM_DIRECTORY(new Builder("-new", String.class).nargs(NumberOfArgumentValues.ONE_OR_MORE_VALUES)),
+    PRIOR_DIRECTORY(new Builder("-old", String.class).nargs(NumberOfArgumentValues.ONE_OR_MORE_VALUES)),
     LANGUAGE(new Builder("-l", String.class).defaultsTo(LanguageOption.getDefault().getDisplayName()).choices(LanguageOption.getAllDisplayNames())),
     BASE_CODE("-bc", String.class),
     VERBOSITY(new Builder("-v", String.class).defaultsTo("quiet").choices(List.of("quiet", "long"))), // TODO SH: Replace verbosity when integrating a
@@ -167,8 +169,12 @@ public enum CommandLineArgument {
         if (type == Boolean.class) {
             argument.action(storeTrue());
         }
-        if (numberOfValues == NumberOfArgumentValues.ONE_OR_MORE_VALUES) {
+        if (!numberOfValues.toString().isEmpty()) {
+            // For multi-value arguments keep all invocations.
+            // This causes the argument value to change its type to 'List<List<String>>'.
+            // Also, when the retrieved value after parsing the CLI is 'null', the argument is not used.
             argument.nargs(numberOfValues.toString());
+            argument.action(append());
         }
     }
 

+ 2 - 1
jplag/src/main/java/de/jplag/NumberOfArgumentValues.java

@@ -5,7 +5,8 @@ package de.jplag;
  */
 public enum NumberOfArgumentValues {
     SINGLE_VALUE(""),
-    ONE_OR_MORE_VALUES("+"),;
+    ONE_OR_MORE_VALUES("+"),
+    ZERO_OR_MORE_VALUES("*");
 
     private final String representation;
 

+ 3 - 1
jplag/src/main/resources/de/jplag/messages.properties

@@ -6,7 +6,9 @@ CommandLineArgument.ExcludeFile=All files named in this file will be ignored in
 CommandLineArgument.Language=Select the language to parse the submissions
 CommandLineArgument.MinTokenMatch=Tunes the comparison sensitivity by adjusting the minimum token required to be counted as a matching section. A smaller <n> increases the sensitivity but might lead to more false-positives
 CommandLineArgument.ResultFolder=Name of the directory in which the comparison results will be stored
-CommandLineArgument.RootDirectory=Root-directory that contains submissions
+CommandLineArgument.RootDirectory=Root-directory with submissions to check for plagiarism
+CommandLineArgument.PlagiarismDirectory=Root-directory with submissions to check for plagiarism
+CommandLineArgument.PriorDirectory=Root-directory with prior submissions to compare against
 CommandLineArgument.ShownComparisons=The maximum number of comparisons that will be shown in the generated report, if set to -1 all comparisons will be shown
 CommandLineArgument.SimilarityThreshold=Comparison similarity threshold [0-100]: All comparisons above this threshold will be saved
 CommandLineArgument.Subdirectory=Look in directories <root-dir>/*/<dir> for programs