Преглед изворни кода

Delete code that was only used by the legacy reporting.

Timur Sağlam пре 4 година
родитељ
комит
8ac305eedf

+ 1 - 1
jplag/src/main/java/de/jplag/JPlag.java

@@ -52,7 +52,7 @@ public class JPlag {
      * If an exclusion file is given, it is read in and all strings are saved in the set "excluded".
      * If an exclusion file is given, it is read in and all strings are saved in the set "excluded".
      * @param exclusionFileName the file name or path
      * @param exclusionFileName the file name or path
      */
      */
-    Set<String> readExclusionFile(final String exclusionFileName) {
+    private Set<String> readExclusionFile(final String exclusionFileName) {
         try (BufferedReader reader = new BufferedReader(new FileReader(exclusionFileName, JPlagOptions.CHARSET))) {
         try (BufferedReader reader = new BufferedReader(new FileReader(exclusionFileName, JPlagOptions.CHARSET))) {
             final var excludedFileNames = reader.lines().collect(Collectors.toSet());
             final var excludedFileNames = reader.lines().collect(Collectors.toSet());
             if (options.getVerbosity() == LONG) {
             if (options.getVerbosity() == LONG) {

+ 1 - 77
jplag/src/main/java/de/jplag/JPlagComparison.java

@@ -1,12 +1,8 @@
 package de.jplag;
 package de.jplag;
 
 
 import java.util.ArrayList;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Comparator;
 import java.util.Comparator;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.List;
-import java.util.Set;
-import java.util.stream.IntStream;
 
 
 /**
 /**
  * This method represents the whole result of a comparison between two submissions.
  * This method represents the whole result of a comparison between two submissions.
@@ -30,7 +26,7 @@ public class JPlagComparison implements Comparator<JPlagComparison> { // FIXME T
      * Add a match to the comparison (token indices and number of tokens), if it does not overlap with the existing matches.
      * Add a match to the comparison (token indices and number of tokens), if it does not overlap with the existing matches.
      * @see Match#Match(int, int, int)
      * @see Match#Match(int, int, int)
      */
      */
-    public final void addMatch(int startOfFirst, int startOfSecond, int length) {
+    /* package-private */ final void addMatch(int startOfFirst, int startOfSecond, int length) {
         for (Match match : matches) {
         for (Match match : matches) {
             if (match.overlap(startOfFirst, startOfSecond, length)) {
             if (match.overlap(startOfFirst, startOfSecond, length)) {
                 return;
                 return;
@@ -39,16 +35,6 @@ public class JPlagComparison implements Comparator<JPlagComparison> { // FIXME T
         matches.add(new Match(startOfFirst, startOfSecond, length));
         matches.add(new Match(startOfFirst, startOfSecond, length));
     }
     }
 
 
-    /**
-     * The bigger a match (length) is relatively to the biggest match the redder is the color returned by this method.
-     */
-    public String color(int length) {
-        int longestMatch = matches.stream().mapToInt(Match::getLength).max().orElse(0);
-        int color = 255 * length / longestMatch;
-        String help = (color < 16 ? "0" : "") + Integer.toHexString(color);
-        return "#" + help + "0000";
-    }
-
     @Override
     @Override
     public int compare(JPlagComparison comparison1, JPlagComparison comparison2) {
     public int compare(JPlagComparison comparison1, JPlagComparison comparison2) {
         return Float.compare(comparison2.similarity(), comparison1.similarity()); // comparison2 first!
         return Float.compare(comparison2.similarity(), comparison1.similarity()); // comparison2 first!
@@ -62,34 +48,6 @@ public class JPlagComparison implements Comparator<JPlagComparison> { // FIXME T
         return (compare(this, (JPlagComparison) other) == 0);
         return (compare(this, (JPlagComparison) other) == 0);
     }
     }
 
 
-    /**
-     * This method returns all the files which contributed to a match. Parameter: j == 0 1st submission, j != 0 2nd
-     * submission.
-     */
-    public final String[] files(int j) {
-        if (matches.size() == 0) {
-            return new String[] {};
-        }
-
-        TokenList tokenList = (j == 0 ? firstSubmission : secondSubmission).getTokenList();
-
-        /*
-         * Collect the file names of the first token of each match.
-         */
-        Set<String> collectedFiles = new LinkedHashSet<>();
-        for (Match match : matches) {
-            collectedFiles.add(tokenList.getToken(match.getStart(j == 0)).getFile());
-        }
-
-        /*
-         * sort by file name. (so that equally named files are displayed approximately side by side.)
-         */
-        String[] res = collectedFiles.toArray(new String[0]);
-        Arrays.sort(res);
-
-        return res;
-    }
-
     /**
     /**
      * @return the base code matches of the first submission.
      * @return the base code matches of the first submission.
      */
      */
@@ -138,22 +96,6 @@ public class JPlagComparison implements Comparator<JPlagComparison> { // FIXME T
         return secondSubmission;
         return secondSubmission;
     }
     }
 
 
-    /**
-     * @param getFirst Whether to return the first submission, else return the second submission.
-     * @return The requested submission.
-     */
-    public Submission getSubmission(boolean getFirst) {
-        return getFirst ? firstSubmission : secondSubmission;
-    }
-
-    /**
-     * @param getFirst Whether to return the first basecode matches, else return the second basecode matches.
-     * @return The requested basecode matches.
-     */
-    public JPlagComparison getBaseCodeMatches(boolean getFirst) {
-        return getSubmission(getFirst).getBaseCodeComparison();
-    }
-
     /**
     /**
      * @return Maximum similarity in percent of both submissions.
      * @return Maximum similarity in percent of both submissions.
      */
      */
@@ -217,24 +159,6 @@ public class JPlagComparison implements Comparator<JPlagComparison> { // FIXME T
         return ((int) (secondBasecodeSimilarity() * ROUNDING_FACTOR)) / (float) ROUNDING_FACTOR;
         return ((int) (secondBasecodeSimilarity() * ROUNDING_FACTOR)) / (float) ROUNDING_FACTOR;
     }
     }
 
 
-    /**
-     * Creates a permutation for the matches based on the indices of the matched token groups.
-     * @param useFirst determines whether the start of the first or second submission is compared.
-     * @return the permutation indices.
-     */
-    public final List<Integer> sort_permutation(boolean useFirst) {
-        List<Integer> indices = new ArrayList<>(matches.size());
-        IntStream.range(0, matches.size()).forEach(indices::add);
-        Comparator<Integer> comparator = Comparator.comparingInt((Integer i) -> selectStartof(i, useFirst));
-        indices.sort(comparator);
-        return indices;
-    }
-
-    private int selectStartof(Integer index, boolean useFirst) {
-        Match match = matches.get(index);
-        return match.getStart(useFirst);
-    }
-
     @Override
     @Override
     public String toString() {
     public String toString() {
         return firstSubmission.getName() + " <-> " + secondSubmission.getName();
         return firstSubmission.getName() + " <-> " + secondSubmission.getName();

+ 0 - 9
jplag/src/main/java/de/jplag/Match.java

@@ -35,15 +35,6 @@ public class Match {
         return startOfSecond;
         return startOfSecond;
     }
     }
 
 
-    /**
-     * @param getFirst Whether to return the starting token index of the first submission, else the starting token index of
-     * the second submission is returned.
-     * @return Start index of the requested submission.
-     */
-    public int getStart(boolean getFirst) {
-        return getFirst ? startOfFirst : startOfSecond;
-    }
-
     /**
     /**
      * @return the length of the similar sections, meaning the number of tokens.
      * @return the length of the similar sections, meaning the number of tokens.
      */
      */

+ 70 - 155
jplag/src/main/java/de/jplag/Submission.java

@@ -1,20 +1,10 @@
 package de.jplag;
 package de.jplag;
 
 
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.IOException;
-import java.io.InputStreamReader;
 import java.nio.file.Files;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Path;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collection;
-import java.util.List;
-
-import de.jplag.exceptions.ReportGenerationException;
-import de.jplag.options.JPlagOptions;
 
 
 /**
 /**
  * Represents a single submission. A submission can contain multiple files.
  * Represents a single submission. A submission can contain multiple files.
@@ -81,33 +71,30 @@ public class Submission implements Comparable<Submission> {
         this.errorCollector = errorCollector;
         this.errorCollector = errorCollector;
     }
     }
 
 
-    /**
-     * @return a list of files this submission consists of.
-     */
-    public Collection<File> getFiles() {
-        return files;
+    @Override
+    public int compareTo(Submission other) {
+        return name.compareTo(other.name);
     }
     }
 
 
     /**
     /**
-     * @return name of the submission (directory or file name).
+     * @return base code comparison
      */
      */
-    public String getName() {
-        return name;
+    public JPlagComparison getBaseCodeComparison() {
+        return baseCodeComparison;
     }
     }
 
 
     /**
     /**
-     * @return the unique file of the submission, which is either in a root folder or a subfolder of root folder when the
-     * subdirectory option is used.
+     * @return a list of files this submission consists of.
      */
      */
-    public File getRoot() {
-        return submissionRootFile;
+    public Collection<File> getFiles() {
+        return files;
     }
     }
 
 
     /**
     /**
-     * @return whether the submission is new, That is, must be checked for plagiarism.
+     * @return name of the submission (directory or file name).
      */
      */
-    public boolean isNew() {
-        return isNew;
+    public String getName() {
+        return name;
     }
     }
 
 
     /**
     /**
@@ -121,25 +108,11 @@ public class Submission implements Comparable<Submission> {
     }
     }
 
 
     /**
     /**
-     * Sets the base code comparison
-     * @param baseCodeComparison is submissions matches with the base code
-     */
-    public void setBaseCodeComparison(JPlagComparison baseCodeComparison) {
-        this.baseCodeComparison = baseCodeComparison;
-    }
-
-    /**
-     * @return base code comparison
-     */
-    public JPlagComparison getBaseCodeComparison() {
-        return baseCodeComparison;
-    }
-
-    /**
-     * @return Whether a comparison between the submission and the base code is available.
+     * @return the unique file of the submission, which is either in a root folder or a subfolder of root folder when the
+     * subdirectory option is used.
      */
      */
-    public boolean hasBaseCodeMatches() {
-        return baseCodeComparison != null;
+    public File getRoot() {
+        return submissionRootFile;
     }
     }
 
 
     /**
     /**
@@ -162,118 +135,24 @@ public class Submission implements Comparable<Submission> {
     }
     }
 
 
     /**
     /**
-     * @return true if at least one error occurred while parsing this submission; false otherwise.
-     */
-    public boolean hasErrors() {
-        return hasErrors;
-    }
-
-    /**
-     * Parse files of the submission.
-     * @return Whether parsing was successful.
+     * @return Whether a comparison between the submission and the base code is available.
      */
      */
-    public boolean parse(boolean debugParser) {
-        if (files == null || files.size() == 0) {
-            errorCollector.print("ERROR: nothing to parse for submission \"" + name + "\"", null);
-            tokenList = null;
-            hasErrors = true; // invalidate submission
-            return false;
-        }
-
-        String[] relativeFilePaths = getRelativeFilePaths(submissionRootFile, files);
-
-        tokenList = language.parse(submissionRootFile, relativeFilePaths);
-        if (!language.hasErrors()) {
-            if (tokenList.size() < 3) {
-                errorCollector.print("Submission \"" + name + "\" is too short!", null);
-                tokenList = null;
-                hasErrors = true; // invalidate submission
-                return false;
-            }
-            return true;
-        }
-
-        tokenList = null;
-        hasErrors = true; // invalidate submission
-        if (debugParser) {
-            copySubmission();
-        }
-        return false;
+    public boolean hasBaseCodeMatches() {
+        return baseCodeComparison != null;
     }
     }
 
 
     /**
     /**
-     * Used by the "Report" class. All source files are returned as an array of an array of strings.
+     * @return true if at least one error occurred while parsing this submission; false otherwise.
      */
      */
-    public String[][] readFiles(String[] files) throws ReportGenerationException {
-        String[][] result = new String[files.length][];
-        String help;
-        List<String> text = new ArrayList<>();
-
-        for (int i = 0; i < files.length; i++) {
-            text.clear();
-
-            try {
-                FileInputStream fileInputStream = new FileInputStream(new File(submissionRootFile, files[i]));
-                InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, JPlagOptions.CHARSET);
-                BufferedReader in = new BufferedReader(inputStreamReader);
-
-                while ((help = in.readLine()) != null) {
-                    help = help.replaceAll("&", "&amp;");
-                    help = help.replaceAll("<", "&lt;");
-                    help = help.replaceAll(">", "&gt;");
-                    help = help.replaceAll("\"", "&quot;");
-                    text.add(help);
-                }
-
-                in.close();
-                inputStreamReader.close();
-                fileInputStream.close();
-            } catch (FileNotFoundException e) {
-                System.out.println("File not found: " + new File(submissionRootFile, files[i]));
-            } catch (IOException e) {
-                throw new ReportGenerationException("I/O exception!", e);
-            }
-
-            result[i] = new String[text.size()];
-            text.toArray(result[i]);
-        }
-
-        return result;
+    public boolean hasErrors() {
+        return hasErrors;
     }
     }
 
 
     /**
     /**
-     * Used by the "Report" class. All source files are returned as an array of an array of chars.
+     * @return whether the submission is new, That is, must be checked for plagiarism.
      */
      */
-    public char[][] readFilesChar(String[] files) throws ReportGenerationException {
-        char[][] result = new char[files.length][];
-
-        for (int i = 0; i < files.length; i++) {
-            // If the token path is absolute, ignore the provided directory
-            File file = new File(files[i]);
-            if (!file.isAbsolute()) {
-                file = new File(submissionRootFile, files[i]);
-            }
-
-            try {
-                int size = (int) file.length();
-                char[] buffer = new char[size];
-
-                FileReader reader = new FileReader(file, JPlagOptions.CHARSET);
-
-                if (size != reader.read(buffer)) {
-                    System.out.println("Not right size read from the file, but I will still continue...");
-                }
-
-                result[i] = buffer;
-                reader.close();
-            } catch (FileNotFoundException e) {
-                throw new ReportGenerationException("File not found: " + file.getPath(), e);
-            } catch (IOException e) {
-                throw new ReportGenerationException("I/O exception reading file \"" + file.getPath() + "\"!", e);
-            }
-        }
-
-        return result;
+    public boolean isNew() {
+        return isNew;
     }
     }
 
 
     /**
     /**
@@ -285,6 +164,14 @@ public class Submission implements Comparable<Submission> {
         }
         }
     }
     }
 
 
+    /**
+     * Sets the base code comparison
+     * @param baseCodeComparison is submissions matches with the base code
+     */
+    public void setBaseCodeComparison(JPlagComparison baseCodeComparison) {
+        this.baseCodeComparison = baseCodeComparison;
+    }
+
     /**
     /**
      * Sets the tokens that have been parsed from the files this submission consists of.
      * Sets the tokens that have been parsed from the files this submission consists of.
      * @param tokenList is the list of these tokens.
      * @param tokenList is the list of these tokens.
@@ -293,15 +180,6 @@ public class Submission implements Comparable<Submission> {
         this.tokenList = tokenList;
         this.tokenList = tokenList;
     }
     }
 
 
-    public void markAsErroneous() {
-        hasErrors = true;
-    }
-
-    @Override
-    public int compareTo(Submission other) {
-        return name.compareTo(other.name);
-    }
-
     @Override
     @Override
     public String toString() {
     public String toString() {
         return name;
         return name;
@@ -350,4 +228,41 @@ public class Submission implements Comparable<Submission> {
 
 
         return files.stream().map(File::toPath).map(baseFilePath::relativize).map(Path::toString).toArray(String[]::new);
         return files.stream().map(File::toPath).map(baseFilePath::relativize).map(Path::toString).toArray(String[]::new);
     }
     }
+
+    /* package-private */ void markAsErroneous() {
+        hasErrors = true;
+    }
+
+    /**
+     * Parse files of the submission.
+     * @return Whether parsing was successful.
+     */
+    /* package-private */ boolean parse(boolean debugParser) {
+        if (files == null || files.size() == 0) {
+            errorCollector.print("ERROR: nothing to parse for submission \"" + name + "\"", null);
+            tokenList = null;
+            hasErrors = true; // invalidate submission
+            return false;
+        }
+
+        String[] relativeFilePaths = getRelativeFilePaths(submissionRootFile, files);
+
+        tokenList = language.parse(submissionRootFile, relativeFilePaths);
+        if (!language.hasErrors()) {
+            if (tokenList.size() < 3) {
+                errorCollector.print("Submission \"" + name + "\" is too short!", null);
+                tokenList = null;
+                hasErrors = true; // invalidate submission
+                return false;
+            }
+            return true;
+        }
+
+        tokenList = null;
+        hasErrors = true; // invalidate submission
+        if (debugParser) {
+            copySubmission();
+        }
+        return false;
+    }
 }
 }

+ 0 - 42
jplag/src/test/java/de/jplag/JPlagComparisonTest.java

@@ -1,42 +0,0 @@
-package de.jplag;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
-import java.util.List;
-
-import org.junit.Test;
-
-import de.jplag.exceptions.ExitException;
-
-public class JPlagComparisonTest extends TestBase {
-
-    private static final String[] FILES = {"GSTiling.java", "Match.java", "Matches.java", "Structure.java", "Submission.java", "Table.java",
-            "Token.java"};
-    private static final String[] FILES_2 = {"Match.java", "Matches.java", "Structure.java", "Submission.java", "Table.java", "Token.java"};
-    private static final String[] FILES_3 = {"Table.java", "Token.java"};
-
-    /**
-     * Tests whether the right set of files corresponding to a set of matches is produced by the {@link JPlagComparison}.
-     */
-    @Test
-    public void testFilesOfMatches() throws ExitException {
-        JPlagResult result = runJPlagWithDefaultOptions("PartialPlagiarism");
-        List<JPlagComparison> comparisons = result.getComparisons();
-        assertEquals(5, result.getNumberOfSubmissions());
-        assertEquals(10, comparisons.size());
-        for (int submission = 0; submission < 2; submission++) { // for both submissions in a comparison
-            assertArrayEquals(FILES, comparisons.get(0).files(submission));
-            for (int i = 1; i < 3; i++) {
-                assertArrayEquals(FILES_2, comparisons.get(i).files(submission));
-            }
-            for (int i = 3; i < 6; i++) {
-                assertArrayEquals(FILES_3, comparisons.get(i).files(submission));
-            }
-            for (int i = 6; i < 10; i++) {
-                assertArrayEquals(new String[] {}, comparisons.get(i).files(submission));
-            }
-        }
-
-    }
-}