Browse Source

implement code suggestions

Jan Wittler 4 years ago
parent
commit
10557e5400

+ 3 - 4
cli/src/main/java/de/jplag/CLI.java

@@ -48,7 +48,6 @@ import org.slf4j.LoggerFactory;
 
 import de.jplag.clustering.ClusteringOptions;
 import de.jplag.clustering.Preprocessing;
-import de.jplag.exceptions.BasecodeException;
 import de.jplag.exceptions.ExitException;
 import de.jplag.logger.CollectedLoggerFactory;
 import de.jplag.options.JPlagOptions;
@@ -137,7 +136,7 @@ public final class CLI {
      * @param namespace encapsulates the parsed arguments in a {@link Namespace} format.
      * @return the newly built options.F
      */
-    public JPlagOptions buildOptionsFromArguments(Namespace namespace) throws BasecodeException {
+    public JPlagOptions buildOptionsFromArguments(Namespace namespace) {
         String fileSuffixString = SUFFIXES.getFrom(namespace);
         String[] fileSuffixes = new String[] {};
         if (fileSuffixString != null) {
@@ -150,8 +149,8 @@ public final class CLI {
         addAllMultiValueArgument(ROOT_DIRECTORY.getListFrom(namespace), submissionDirectoryPaths);
         addAllMultiValueArgument(NEW_DIRECTORY.getListFrom(namespace), submissionDirectoryPaths);
         addAllMultiValueArgument(OLD_DIRECTORY.getListFrom(namespace), oldSubmissionDirectoryPaths);
-        var submissionDirectories = submissionDirectoryPaths.stream().map(path -> new File(path)).collect(Collectors.toSet());
-        var oldSubmissionDirectories = oldSubmissionDirectoryPaths.stream().map(path -> new File(path)).collect(Collectors.toSet());
+        var submissionDirectories = submissionDirectoryPaths.stream().map(File::new).collect(Collectors.toSet());
+        var oldSubmissionDirectories = oldSubmissionDirectoryPaths.stream().map(File::new).collect(Collectors.toSet());
 
         var language = LanguageLoader.getLanguage(LANGUAGE.getFrom(namespace)).orElseThrow();
         ClusteringOptions clusteringOptions = getClusteringOptions(namespace);

+ 1 - 7
cli/src/test/java/de/jplag/cli/CommandLineInterfaceTest.java

@@ -2,7 +2,6 @@ package de.jplag.cli;
 
 import static de.jplag.CommandLineArgument.ROOT_DIRECTORY;
 import static java.util.stream.Collectors.toSet;
-import static org.junit.jupiter.api.Assertions.assertFalse;
 
 import java.util.Arrays;
 
@@ -10,7 +9,6 @@ import net.sourceforge.argparse4j.inf.Namespace;
 
 import de.jplag.CLI;
 import de.jplag.CommandLineArgument;
-import de.jplag.exceptions.BasecodeException;
 import de.jplag.options.JPlagOptions;
 
 /**
@@ -55,11 +53,7 @@ public abstract class CommandLineInterfaceTest {
         cli = new CLI();
         namespace = cli.parseArguments(arguments);
         System.out.println("Parsed arguments: " + parsedKeys(arguments));
-        try {
-            options = cli.buildOptionsFromArguments(namespace);
-        } catch (BasecodeException e) {
-            assertFalse(true);
-        }
+        options = cli.buildOptionsFromArguments(namespace);
     }
 
 }

+ 5 - 10
core/src/main/java/de/jplag/SubmissionSetBuilder.java

@@ -70,10 +70,8 @@ public class SubmissionSetBuilder {
             processRootDirectoryEntries(oldDirectory, multipleRoots, foundSubmissions, false);
         }
 
-        Optional<Submission> baseCodeSubmission = loadBaseCode(submissionDirectories, oldSubmissionDirectories);
-        baseCodeSubmission.ifPresent(baseSubmission -> {
-            foundSubmissions.remove(baseSubmission.getRoot());
-        });
+        Optional<Submission> baseCodeSubmission = loadBaseCode();
+        baseCodeSubmission.ifPresent(baseSubmission -> foundSubmissions.remove(baseSubmission.getRoot()));
 
         // Merge everything in a submission set.
         List<Submission> submissions = new ArrayList<>(foundSubmissions.values());
@@ -128,14 +126,14 @@ public class SubmissionSetBuilder {
         }
     }
 
-    private Optional<Submission> loadBaseCode(Set<File> submissionDirectories, Set<File> oldSubmissionDirectories) throws ExitException {
+    private Optional<Submission> loadBaseCode() throws ExitException {
         if (!options.hasBaseCode()) {
             return Optional.empty();
         }
 
         File baseCodeSubmissionDirectory = options.baseCodeSubmissionDirectory();
         if (!baseCodeSubmissionDirectory.exists()) {
-            throw new BasecodeException("Basecode directory \"{}\" does not exist".formatted(baseCodeSubmissionDirectory));
+            throw new BasecodeException("Basecode directory \"%s\" does not exist".formatted(baseCodeSubmissionDirectory));
         }
         String errorMessage = isExcludedEntry(baseCodeSubmissionDirectory);
         if (errorMessage != null) {
@@ -143,10 +141,7 @@ public class SubmissionSetBuilder {
         }
 
         Submission baseCodeSubmission = processSubmission(baseCodeSubmissionDirectory.getName(), baseCodeSubmissionDirectory, false);
-
-        if (baseCodeSubmission != null) {
-            logger.info("Basecode directory \"{}\" will be used.", baseCodeSubmission.getName());
-        }
+        logger.info("Basecode directory \"{}\" will be used.", baseCodeSubmission.getName());
         return Optional.ofNullable(baseCodeSubmission);
     }
 

+ 7 - 3
core/src/main/java/de/jplag/options/JPlagOptions.java

@@ -252,7 +252,7 @@ public record JPlagOptions(Language language, Integer minimumTokenMatch, Set<Fil
      * @param debugParser If true, submissions that cannot be parsed will be stored in a separate directory.
      * @deprecated Use the default initializer with @{{@link #baseCodeSubmissionDirectory} instead.
      */
-    @Deprecated
+    @Deprecated(since = "4.0.0", forRemoval = true)
     public JPlagOptions(Language language, Integer minimumTokenMatch, File submissionDirectory, Set<File> oldSubmissionDirectories,
             String baseCodeSubmissionName, String subdirectoryName, List<String> fileSuffixes, String exclusionFileName,
             SimilarityMetric similarityMetric, double similarityThreshold, int maximumNumberOfComparisons, ClusteringOptions clusteringOptions,
@@ -268,7 +268,7 @@ public record JPlagOptions(Language language, Integer minimumTokenMatch, Set<Fil
      * @return a new options instance with the provided base code submission name
      * @deprecated Use @{{@link #withBaseCodeSubmissionDirectory} instead.
      */
-    @Deprecated
+    @Deprecated(since = "4.0.0", forRemoval = true)
     public JPlagOptions withBaseCodeSubmissionName(String baseCodeSubmissionName) {
         File baseCodeDirectory = new File(baseCodeSubmissionName);
         if (baseCodeDirectory.exists()) {
@@ -288,7 +288,11 @@ public record JPlagOptions(Language language, Integer minimumTokenMatch, Set<Fil
         }
     }
 
-    @Deprecated
+    /**
+     * Converts a legacy base code submission name to a directory path.
+     * @deprecated Use the default initializer with @{{@link #baseCodeSubmissionDirectory} instead.
+     */
+    @Deprecated(since = "4.0.0", forRemoval = true)
     private static File convertLegacyBaseCodeToFile(String baseCodeSubmissionName, File submissionDirectory) throws BasecodeException {
         if (baseCodeSubmissionName == null) {
             return null;

+ 7 - 3
core/src/test/java/de/jplag/LegacyBaseCodeParallelComparisonTest.java

@@ -9,7 +9,11 @@ import org.junit.jupiter.api.Test;
 
 import de.jplag.exceptions.ExitException;
 
-public class LegacyBaseCodeParallelComparisonTest extends ParallelComparisonTest {
+/**
+ * Tests for the legacy behaviour of the String-based base code initializer.
+ */
+@Deprecated(since = "4.0.0", forRemoval = true)
+class LegacyBaseCodeParallelComparisonTest extends ParallelComparisonTest {
     @Test
     void testMultiRootDirSeparateBasecode() throws ExitException {
         String basecodePath = getBasePath("basecode-base");
@@ -19,7 +23,7 @@ public class LegacyBaseCodeParallelComparisonTest extends ParallelComparisonTest
     }
 
     @Test
-    public void testMultiRootDirBasecodeInSubmissionDir() throws ExitException {
+    void testMultiRootDirBasecodeInSubmissionDir() throws ExitException {
         String basecodePath = getBasePath("basecode", "base");
         List<String> paths = List.of(getBasePath("basecode"), getBasePath("SimpleDuplicate")); // 2 + 2 submissions.
         JPlagResult result = runJPlag(paths, it -> it.withBaseCodeSubmissionName(basecodePath));
@@ -27,7 +31,7 @@ public class LegacyBaseCodeParallelComparisonTest extends ParallelComparisonTest
     }
 
     @Test
-    public void testMultiRootDirBasecodeName() {
+    void testMultiRootDirBasecodeName() {
         List<String> paths = List.of(getBasePath("basecode"), getBasePath("SimpleDuplicate"));
         String basecodePath = "base"; // Should *not* find basecode/base
         assertThrows(IllegalArgumentException.class, () -> runJPlag(paths, it -> it.withBaseCodeSubmissionName(basecodePath)));

+ 2 - 2
core/src/test/java/de/jplag/LegacyBaseCodeTest.java

@@ -13,8 +13,8 @@ import de.jplag.exceptions.ExitException;
 /**
  * Tests for the legacy behaviour of the String-based base code initializer.
  */
-@Deprecated
-public class LegacyBaseCodeTest extends BaseCodeTest {
+@Deprecated(since = "4.0.0", forRemoval = true)
+class LegacyBaseCodeTest extends BaseCodeTest {
     @Test
     void testBasecodeUserSubmissionComparison() throws ExitException {
         JPlagResult result = runJPlag("basecode", it -> it.withBaseCodeSubmissionName("base"));