Przeglądaj źródła

Merge pull request #359 from jplag/remove-old-report2

 Remove old reporting code
Timur Sağlam 4 lat temu
rodzic
commit
40a2cca5c2
25 zmienionych plików z 151 dodań i 1342 usunięć
  1. 31 3
      jplag/src/main/java/de/jplag/CLI.java
  2. 1 1
      jplag/src/main/java/de/jplag/JPlag.java
  3. 1 77
      jplag/src/main/java/de/jplag/JPlagComparison.java
  4. 0 9
      jplag/src/main/java/de/jplag/Match.java
  5. 70 155
      jplag/src/main/java/de/jplag/Submission.java
  6. 0 46
      jplag/src/main/java/de/jplag/reporting/BufferedCounter.java
  7. 0 75
      jplag/src/main/java/de/jplag/reporting/Color.java
  8. 0 31
      jplag/src/main/java/de/jplag/reporting/HTMLFile.java
  9. 4 4
      jplag/src/main/java/de/jplag/reporting/JsonReport.java
  10. 0 24
      jplag/src/main/java/de/jplag/reporting/MarkupText.java
  11. 0 26
      jplag/src/main/java/de/jplag/reporting/Messages.java
  12. 14 769
      jplag/src/main/java/de/jplag/reporting/Report.java
  13. 0 35
      jplag/src/main/java/de/jplag/reporting/TagParser.java
  14. 3 3
      jplag/src/main/java/de/jplag/reporting/jsonfactory/JsonFactory.java
  15. 19 5
      jplag/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java
  16. 1 1
      jplag/src/main/java/de/jplag/reporting/reportobject/model/Cluster.java
  17. 1 1
      jplag/src/main/java/de/jplag/reporting/reportobject/model/ComparisonReport.java
  18. 1 1
      jplag/src/main/java/de/jplag/reporting/reportobject/model/FilesOfSubmission.java
  19. 1 1
      jplag/src/main/java/de/jplag/reporting/reportobject/model/JPlagReport.java
  20. 1 1
      jplag/src/main/java/de/jplag/reporting/reportobject/model/Match.java
  21. 1 1
      jplag/src/main/java/de/jplag/reporting/reportobject/model/Metric.java
  22. 1 1
      jplag/src/main/java/de/jplag/reporting/reportobject/model/OverviewReport.java
  23. 1 1
      jplag/src/main/java/de/jplag/reporting/reportobject/model/TopComparison.java
  24. 0 29
      jplag/src/main/java/de/jplag/reporting2/Report.java
  25. 0 42
      jplag/src/test/java/de/jplag/JPlagComparisonTest.java

+ 31 - 3
jplag/src/main/java/de/jplag/CLI.java

@@ -1,6 +1,34 @@
 package de.jplag;
 
-import static de.jplag.CommandLineArgument.*;
+import static de.jplag.CommandLineArgument.BASE_CODE;
+import static de.jplag.CommandLineArgument.CLUSTER_AGGLOMERATIVE_INTER_CLUSTER_SIMILARITY;
+import static de.jplag.CommandLineArgument.CLUSTER_AGGLOMERATIVE_THRESHOLD;
+import static de.jplag.CommandLineArgument.CLUSTER_ALGORITHM;
+import static de.jplag.CommandLineArgument.CLUSTER_ENABLE;
+import static de.jplag.CommandLineArgument.CLUSTER_METRIC;
+import static de.jplag.CommandLineArgument.CLUSTER_PREPROCESSING_CDF;
+import static de.jplag.CommandLineArgument.CLUSTER_PREPROCESSING_NONE;
+import static de.jplag.CommandLineArgument.CLUSTER_PREPROCESSING_PERCENTILE;
+import static de.jplag.CommandLineArgument.CLUSTER_PREPROCESSING_THRESHOLD;
+import static de.jplag.CommandLineArgument.CLUSTER_SPECTRAL_BANDWIDTH;
+import static de.jplag.CommandLineArgument.CLUSTER_SPECTRAL_KMEANS_ITERATIONS;
+import static de.jplag.CommandLineArgument.CLUSTER_SPECTRAL_MAX_RUNS;
+import static de.jplag.CommandLineArgument.CLUSTER_SPECTRAL_MIN_RUNS;
+import static de.jplag.CommandLineArgument.CLUSTER_SPECTRAL_NOISE;
+import static de.jplag.CommandLineArgument.COMPARISON_MODE;
+import static de.jplag.CommandLineArgument.DEBUG;
+import static de.jplag.CommandLineArgument.EXCLUDE_FILE;
+import static de.jplag.CommandLineArgument.LANGUAGE;
+import static de.jplag.CommandLineArgument.MIN_TOKEN_MATCH;
+import static de.jplag.CommandLineArgument.NEW_DIRECTORY;
+import static de.jplag.CommandLineArgument.OLD_DIRECTORY;
+import static de.jplag.CommandLineArgument.RESULT_FOLDER;
+import static de.jplag.CommandLineArgument.ROOT_DIRECTORY;
+import static de.jplag.CommandLineArgument.SHOWN_COMPARISONS;
+import static de.jplag.CommandLineArgument.SIMILARITY_THRESHOLD;
+import static de.jplag.CommandLineArgument.SUBDIRECTORY;
+import static de.jplag.CommandLineArgument.SUFFIXES;
+import static de.jplag.CommandLineArgument.VERBOSITY;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -21,8 +49,8 @@ import de.jplag.options.JPlagOptions;
 import de.jplag.options.LanguageOption;
 import de.jplag.options.SimilarityMetric;
 import de.jplag.options.Verbosity;
-import de.jplag.reporting2.JsonReport;
-import de.jplag.reporting2.Report;
+import de.jplag.reporting.JsonReport;
+import de.jplag.reporting.Report;
 import de.jplag.strategy.ComparisonMode;
 
 /**

+ 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".
      * @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))) {
             final var excludedFileNames = reader.lines().collect(Collectors.toSet());
             if (options.getVerbosity() == LONG) {

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

@@ -1,12 +1,8 @@
 package de.jplag;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Comparator;
-import java.util.LinkedHashSet;
 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.
@@ -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.
      * @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) {
             if (match.overlap(startOfFirst, startOfSecond, length)) {
                 return;
@@ -39,16 +35,6 @@ public class JPlagComparison implements Comparator<JPlagComparison> { // FIXME T
         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
     public int compare(JPlagComparison comparison1, JPlagComparison comparison2) {
         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);
     }
 
-    /**
-     * 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.
      */
@@ -138,22 +96,6 @@ public class JPlagComparison implements Comparator<JPlagComparison> { // FIXME T
         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.
      */
@@ -217,24 +159,6 @@ public class JPlagComparison implements Comparator<JPlagComparison> { // FIXME T
         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
     public String toString() {
         return firstSubmission.getName() + " <-> " + secondSubmission.getName();

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

@@ -35,15 +35,6 @@ public class Match {
         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.
      */

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

@@ -1,20 +1,10 @@
 package de.jplag;
 
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
-import java.io.InputStreamReader;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.util.ArrayList;
 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.
@@ -81,33 +71,30 @@ public class Submission implements Comparable<Submission> {
         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.
      * @param tokenList is the list of these tokens.
@@ -293,15 +180,6 @@ public class Submission implements Comparable<Submission> {
         this.tokenList = tokenList;
     }
 
-    public void markAsErroneous() {
-        hasErrors = true;
-    }
-
-    @Override
-    public int compareTo(Submission other) {
-        return name.compareTo(other.name);
-    }
-
     @Override
     public String toString() {
         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);
     }
+
+    /* 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 - 46
jplag/src/main/java/de/jplag/reporting/BufferedCounter.java

@@ -1,46 +0,0 @@
-package de.jplag.reporting;
-
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.io.Writer;
-
-/**
- * A buffered writer that counts the number of printed characters.
- */
-public class BufferedCounter extends BufferedWriter {
-
-    private int count;
-
-    public BufferedCounter(Writer out) {
-        super(out);
-        count = 0;
-    }
-
-    @Override
-    public void write(int c) throws IOException {
-        super.write(c);
-        count++;
-    }
-
-    @Override
-    public void write(char[] cbuf, int off, int len) throws IOException {
-        super.write(cbuf, off, len);
-        count += len;
-    }
-
-    @Override
-    public void write(String s, int off, int len) throws IOException {
-        super.write(s, off, len);
-        count += len;
-    }
-
-    @Override
-    public void newLine() throws IOException {
-        super.newLine();
-        count++;
-    }
-
-    public int bytesWritten() {
-        return count;
-    }
-}

+ 0 - 75
jplag/src/main/java/de/jplag/reporting/Color.java

@@ -1,75 +0,0 @@
-package de.jplag.reporting;
-
-public enum Color {
-    BLUE("#0000ff"),
-    BROWN("#f63526"),
-    BROWN_2("#980517"),
-    CADET_BLUE("#53858b"),
-    CHARTREUSE("#6cc417"),
-    CORNFLOWER_BLUE("#151b8d"),
-    CORNSILK("#8c8774"),
-    CYAN("#38a4a5"),
-    DARK_GOLDENROD("#c58917"),
-    DARK_OLIVE_GREEN("#83a33a"),
-    DARK_ORANGE("#ad5910"),
-    DARK_ORCHID("#b041ff"),
-    DARK_ORCHID_2("#571b7e"),
-    DARK_TURQUOISE("#3b9c9c"),
-    DARK_VIOLET("#842dce"),
-    DEEP_PINK("#f52887"),
-    DEEP_SKY_BLUE("#2981b2"),
-    DEEP_SKY_BLUE_2("#3090c7"),
-    FIRE_BRICK("#800517"),
-    FIRE_BRICK_2("#f62817"),
-    FOREST_GREEN("#4e9258"),
-    GOLD("#947010"),
-    GREEN("#4cc417"),
-    HOT_PINK("#f660ab"),
-    KHAKI("#79764d"),
-    LAWN_GREEN("#5eac10"),
-    LIGHT_BLUE("#68818b"),
-    LIGHT_CORAL("#e77471"),
-    LIGHT_CYAN("#717d7d"),
-    LIGHT_PINK("#af7a82"),
-    LIGHT_SALMON("#ae694a"),
-    LIGHT_SEA_GREEN("#3ea99f"),
-    LIGHT_SKY_BLUE("#5b8daf"),
-    LIGHT_SLATE_BLUE("#736aff"),
-    LIGHT_YELLOW("#827d6b"),
-    LIME_GREEN("#41a317"),
-    MAGENTA("#ff00ff"),
-    MAROON("#810541"),
-    MEDIUM_AQUAMARINE("#348781"),
-    MEDIUM_BLUE("#152dc6"),
-    MEDIUM_FOREST_GREEN("#347235"),
-    ORANGE("#f87a17"),
-    ORANGE_2("#c57717"),
-    ORANGE_RED("#c22817"),
-    ORCHID("#a057a5"),
-    PALE_GREEN("#549748"),
-    PALE_TURQUOISE("#668b8b"),
-    PALE_VIOLET_RED("#d16587"),
-    PERU("#c57726"),
-    PURPLE("#8e35ef"),
-    RED("#ff0000"),
-    ROSY_BROWN("#b38481"),
-    ROYAL_BLUE("#2b60de"),
-    SALMON("#ad5a3d"),
-    SEA_GREEN("#4e8975"),
-    STEEL_BLUE("#4863a0"),
-    YELLOW_GREEN("#52d017");
-
-    private final String hexadecimalValue;
-
-    Color(String hexadecimalValue) {
-        this.hexadecimalValue = hexadecimalValue;
-    }
-
-    public String getHexadecimalValue() {
-        return hexadecimalValue;
-    }
-
-    public static String getHexadecimalValue(int index) {
-        return values()[index % values().length].getHexadecimalValue();
-    }
-}

+ 0 - 31
jplag/src/main/java/de/jplag/reporting/HTMLFile.java

@@ -1,31 +0,0 @@
-package de.jplag.reporting;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-
-import de.jplag.options.JPlagOptions;
-
-public class HTMLFile extends PrintWriter {
-
-    private final BufferedCounter counter;
-
-    /**
-     * Static factory method to instantiate an HTMLFile objects.
-     */
-    public static HTMLFile fromFile(File file) throws IOException {
-        BufferedCounter counter = new BufferedCounter(new OutputStreamWriter(new FileOutputStream(file), JPlagOptions.CHARSET));
-        return new HTMLFile(counter);
-    }
-
-    private HTMLFile(BufferedCounter counter) {
-        super(counter);
-        this.counter = counter;
-    }
-
-    public int bytesWritten() {
-        return counter.bytesWritten();
-    }
-}

+ 4 - 4
jplag/src/main/java/de/jplag/reporting2/JsonReport.java → jplag/src/main/java/de/jplag/reporting/JsonReport.java

@@ -1,12 +1,12 @@
-package de.jplag.reporting2;
+package de.jplag.reporting;
 
 import java.io.File;
 import java.util.List;
 
 import de.jplag.JPlagResult;
-import de.jplag.reporting2.jsonfactory.JsonFactory;
-import de.jplag.reporting2.reportobject.ReportObjectFactory;
-import de.jplag.reporting2.reportobject.model.JPlagReport;
+import de.jplag.reporting.jsonfactory.JsonFactory;
+import de.jplag.reporting.reportobject.ReportObjectFactory;
+import de.jplag.reporting.reportobject.model.JPlagReport;
 
 // ReportImplementation -> JsonReport
 

+ 0 - 24
jplag/src/main/java/de/jplag/reporting/MarkupText.java

@@ -1,24 +0,0 @@
-package de.jplag.reporting;
-
-/**
- * This class represents one markup tag that will be included in the text. It is necessary to sort the objects before
- * they are included into the text, so that the original position can be found.
- */
-public class MarkupText {
-    public int fileIndex, lineIndex, column;
-    public String text;
-    public boolean frontMarkup;
-
-    public MarkupText(int fileIndex, int lineIndex, int column, String text, boolean frontMarkup) {
-        this.fileIndex = fileIndex;
-        this.lineIndex = lineIndex;
-        this.column = column;
-        this.text = text;
-        this.frontMarkup = frontMarkup;
-    }
-
-    @Override
-    public String toString() {
-        return "MarkUp - file: " + fileIndex + " line: " + lineIndex + " column: " + column + " text: " + text;
-    }
-}

+ 0 - 26
jplag/src/main/java/de/jplag/reporting/Messages.java

@@ -1,26 +0,0 @@
-package de.jplag.reporting;
-
-import java.util.Locale;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-public class Messages {
-
-    private final ResourceBundle resourceBundle;
-
-    /**
-     * @param countryTag may be "de", "en", "fr", "es", "pt" or "ptbr"
-     */
-    public Messages(String countryTag) {
-        String bundleName = "de.jplag.messages";
-        resourceBundle = ResourceBundle.getBundle(bundleName, new Locale(countryTag));
-    }
-
-    public String getString(String key) {
-        try {
-            return resourceBundle.getString(key);
-        } catch (MissingResourceException e) {
-            return '!' + key + '!';
-        }
-    }
-}

+ 14 - 769
jplag/src/main/java/de/jplag/reporting/Report.java

@@ -1,784 +1,29 @@
 package de.jplag.reporting;
 
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.net.URL;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
 
-import de.jplag.JPlagComparison;
 import de.jplag.JPlagResult;
-import de.jplag.Match;
-import de.jplag.Submission;
-import de.jplag.Token;
-import de.jplag.TokenList;
-import de.jplag.exceptions.ExitException;
-import de.jplag.exceptions.ReportGenerationException;
-import de.jplag.options.JPlagOptions;
+
+// ReportStrategy -> Report
 
 /**
- * This class writes all the HTML pages.
+ * Strategy interface for reporting. A report generator should implement this interface.
  */
-public class Report { // Mostly legacy code with some minor improvements.
-
-    private static final String CSV_FILE = "matches_avg.csv";
-    private static final String[] PICS = {"forward.gif", "back.gif"};
-
-    private final Map<JPlagComparison, Integer> comparisonToIndex = new HashMap<>();
-    private final Messages msg;
-    private final File reportDir;
-    private final JPlagOptions options;
-
-    private JPlagResult result;
-
-    private int currentComparisonIndex = 0;
-    private int matchWritingProgess = 0;
-    private int matchesWritten = 0;
-
-    public Report(File reportDir, JPlagOptions options) throws ReportGenerationException {
-        this.reportDir = reportDir;
-        this.options = options;
-        msg = new Messages("en");
-
-        validateReportDir();
-    }
-
-    public void writeResult(JPlagResult result) throws ReportGenerationException {
-        this.result = result;
-        System.out.println("\nWriting report...");
-        writeIndex();
-        copyStaticFiles();
-        writeMatches(result.getComparisons(options.getMaximumNumberOfComparisons()));
-        System.out.println("Report exported to " + reportDir.getAbsolutePath());
-    }
-
-    /*
-     * Two colors, represented by Rl,Gl,Bl and Rh,Gh,Bh respectively are mixed according to the percentage "percent"
-     */
-    private String color(float percent, int Rl, int Rh, int Gl, int Gh, int Bl, int Bh) {
-        int redValue = (int) (Rl + (Rh - Rl) * percent / 100);
-        int greenValue = (int) (Gl + (Gh - Gl) * percent / 100);
-        int blueValue = (int) (Bl + (Bh - Bl) * percent / 100);
-
-        String red = (redValue < 16 ? "0" : "") + Integer.toHexString(redValue);
-        String green = (greenValue < 16 ? "0" : "") + Integer.toHexString(greenValue);
-        String blue = (blueValue < 16 ? "0" : "") + Integer.toHexString(blueValue);
-
-        return "#" + red + green + blue;
-    }
-
-    /*
-     * This procedure copies all the data from "data/" into the result-directory.
-     */
-    private void copyStaticFiles() {
-        final String[] fileList = {"back.gif", "forward.gif", "help-en.html", "help-sim-en.html", "logo.png", "fields.js"};
-
-        for (int i = fileList.length - 1; i >= 0; i--) {
-            try {
-                URL url = Report.class.getResource("data/" + fileList[i]);
-                DataInputStream dis = new DataInputStream(url.openStream());
-
-                File dest = new File(reportDir, fileList[i]);
-                DataOutputStream dos = new DataOutputStream(new FileOutputStream(dest));
-
-                byte[] buffer = new byte[1024];
-                int count;
-                do {
-                    count = dis.read(buffer);
-                    if (count != -1) {
-                        dos.write(buffer, 0, count);
-                    }
-                } while (count != -1);
-                dis.close();
-                dos.close();
-            } catch (IOException | NullPointerException e) {
-                e.printStackTrace();
-            }
-        }
-    }
-
-    /**
-     * Create a new HTML file.
-     */
-    private HTMLFile createHTMLFile(String name) throws ReportGenerationException {
-        File file = new File(reportDir, name);
-
-        try {
-            return HTMLFile.fromFile(file);
-        } catch (IOException exception) {
-            throw new ReportGenerationException("Error opening file: " + file, exception);
-        }
-    }
-
-    private int getComparisonIndex(JPlagComparison comparison) {
-        Integer index = comparisonToIndex.get(comparison);
-
-        if (index != null) {
-            return index;
-        }
-
-        comparisonToIndex.put(comparison, currentComparisonIndex++);
-
-        return currentComparisonIndex - 1;
-    }
-
-    /**
-     * This method generates an table entry in the list of all comparisons.
-     */
-    private void reportComparison(HTMLFile htmlFile, JPlagComparison comparison, int index) {
-        Match match;
-        TokenList tokensA = comparison.getFirstSubmission().getTokenList();
-        TokenList tokensB = comparison.getSecondSubmission().getTokenList();
-        // sort();
-
-        htmlFile.println("<TABLE BORDER=\"1\" CELLSPACING=\"0\" BGCOLOR=\"#d0d0d0\">");
-        htmlFile.println("<TR><TH><TH>" + comparison.getFirstSubmission().getName() + " (" + comparison.similarityOfFirst() + "%)<TH>"
-                + comparison.getSecondSubmission().getName() + " (" + comparison.similarityOfSecond() + "%)<TH>"
-                + msg.getString("AllMatches.Tokens"));
-
-        for (int i = 0; i < comparison.getMatches().size(); i++) {
-            match = comparison.getMatches().get(i);
-
-            Token startA = tokensA.getToken(match.getStartOfFirst());
-            Token endA = tokensA.getToken(match.getStartOfFirst() + match.getLength() - 1);
-            Token startB = tokensB.getToken(match.getStartOfSecond());
-            Token endB = tokensB.getToken(match.getStartOfSecond() + match.getLength() - 1);
-
-            String col = Color.getHexadecimalValue(i);
-
-            htmlFile.print("<TR><TD BGCOLOR=\"" + col + "\"><FONT COLOR=\"" + col + "\">-</FONT>");
-            htmlFile.print("<TD><A HREF=\"javascript:ZweiFrames('match" + index + "-0.html#" + i + "',2,'match" + index + "-1.html#" + i
-                    + "',3)\" NAME=\"" + i + "\">");
-            htmlFile.print(new String(startA.getFile().getBytes()));
-
-            if (options.getLanguage().usesIndex()) {
-                htmlFile.print("(" + startA.getIndex() + "-" + endA.getIndex() + ")");
-            } else {
-                htmlFile.print("(" + startA.getLine() + "-" + endA.getLine() + ")");
-            }
-
-            htmlFile.print("<TD><A HREF=\"javascript:ZweiFrames('match" + index + "-0.html#" + i + "',2,'match" + index + "-1.html#" + i
-                    + "',3)\" NAME=\"" + i + "\">");
-            htmlFile.print(startB.getFile());
-
-            if (options.getLanguage().usesIndex()) {
-                htmlFile.print("(" + startB.getIndex() + "-" + endB.getIndex());
-            } else {
-                htmlFile.print("(" + startB.getLine() + "-" + endB.getLine());
-            }
-
-            htmlFile.println(
-                    ")</A><TD ALIGN=center>" + "<FONT COLOR=\"" + comparison.color(match.getLength()) + "\">" + match.getLength() + "</FONT>");
-        }
-
-        if (options.hasBaseCode()) {
-            htmlFile.print(
-                    "<TR><TD BGCOLOR=\"#C0C0C0\"><TD>" + msg.getString("AllMatches.Basecode") + " " + comparison.basecodeSimilarityOfFirst() + "%");
-            htmlFile.println("<TD>" + msg.getString("AllMatches.Basecode") + " " + comparison.basecodeSimilarityOfSecond() + "%<TD>&nbsp;");
-        }
-
-        htmlFile.println("</TABLE>");
-    }
-
-    private synchronized void reportMatchWritingProgress(List<JPlagComparison> comparisons) {
-        matchesWritten++;
-        int currentProgress = 20 * matchesWritten / comparisons.size() * 5; // report every 5% step
-        if (currentProgress > matchWritingProgess) {
-            System.out.println("Writing matches: " + currentProgress + "%");
-            matchWritingProgess = currentProgress;
-        }
-    }
-
-    /**
-     * Make sure the report directory exists, is a directory and has write access.
-     */
-    private void validateReportDir() throws ReportGenerationException {
-        if (!reportDir.exists() && !reportDir.mkdirs()) {
-            throw new ReportGenerationException("Cannot create report directory!");
-        }
-
-        if (!reportDir.isDirectory()) {
-            throw new ReportGenerationException(reportDir + " is not a directory!");
-        }
-
-        if (!reportDir.canWrite()) {
-            throw new ReportGenerationException("Cannot write directory: " + reportDir);
-        }
-    }
-
-    private void writeDistribution(HTMLFile htmlFile) {
-        int barLength = 75;
-        int[] similarityDistribution = result.getSimilarityDistribution();
-
-        int max = 1;
-
-        for (int i = 0; i < 10; i++) {
-            if (similarityDistribution[i] > max) {
-                max = similarityDistribution[i];
-            }
-        }
-
-        htmlFile.println("<H4>" + this.msg.getString("Report.Distribution") + ":</H4>\n<CENTER>");
-        htmlFile.println("<TABLE CELLPADDING=1 CELLSPACING=1>");
-
-        for (int i = 9; i >= 0; i--) {
-            htmlFile.print("<TR BGCOLOR=" + color(i * 10 + 10, 128, 192, 128, 192, 255, 255) + "><TD ALIGN=center>" + (i * 10) + "% - "
-                    + (i * 10 + 10) + "%" + "</TD><TD ALIGN=right>" + similarityDistribution[i] + "</TD><TD>");
-
-            for (int j = (similarityDistribution[i] * barLength / max); j > 0; j--) {
-                htmlFile.print("#");
-            }
-
-            if (similarityDistribution[i] * barLength / max == 0) {
-                if (similarityDistribution[i] == 0) {
-                    htmlFile.print(".");
-                } else {
-                    htmlFile.print("#");
-                }
-            }
-
-            htmlFile.println("</TD></TR>");
-        }
-
-        htmlFile.println("</TABLE></CENTER>\n<P>\n<HR>");
-    }
-
-    private void writeHTMLHeader(HTMLFile file, String title) {
-        file.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
-        file.println("<HTML><HEAD><TITLE>" + title + "</TITLE>");
-        file.println("<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
-        file.println("</HEAD>");
-    }
-
-    /*
-     * i is the number of the match j == 0 if subA is considered, otherwise (j must then be 1) it is subB This procedure
-     * makes use of the column and length information!
-     */
-    private int writeImprovedSubmission(HTMLFile f, int i, JPlagComparison comparison, int j) throws ReportGenerationException {
-        Submission sub = comparison.getSubmission(j == 0);
-        String[] files = comparison.files(j);
-        String[][] text = sub.readFiles(files);
-        TokenList tokens = comparison.getSubmission(j == 0).getTokenList();
-
-        // Markup list:
-        Comparator<MarkupText> comp = (mo1, mo2) -> {
-            int col1 = mo1.column;
-            int col2 = mo2.column;
-            if (col1 > col2) {
-                return -1;
-            } else if (col1 < col2) {
-                return 1;
-            }
-            return (mo1.frontMarkup ? -1 : 1);
-        };
-        TreeMap<MarkupText, Object> markupList = new TreeMap<>(comp);
-
-        for (int x = 0; x < comparison.getMatches().size(); x++) {
-            Match onematch = comparison.getMatches().get(x);
-
-            Token start = tokens.getToken(onematch.getStart(j == 0));
-            Token end = tokens.getToken((onematch.getStart(j == 0)) + onematch.getLength() - 1);
-            for (int fileIndex = 0; fileIndex < files.length; fileIndex++) {
-                if (start.getFile().equals(files[fileIndex]) && text[fileIndex] != null) {
-                    String tmp = "<FONT color=\"" + Color.getHexadecimalValue(x) + "\">" + (j == 1 ? "<div style=\"position:absolute;left:0\">" : "")
-                            + "<A HREF=\"javascript:ZweiFrames('match" + i + "-" + (1 - j) + ".html#" + x + "'," + (3 - j) + ",'match" + i
-                            + "-top.html#" + x + "',1)\"><IMG SRC=\"" + PICS[j] + "\" ALT=\"other\" " + "BORDER=\"0\" ALIGN=\""
-                            + (j == 0 ? "right" : "left") + "\"></A>" + (j == 1 ? "</div>" : "") + "<B>";
-                    // position the icon and the beginning of the colorblock
-                    markupList.put(new MarkupText(fileIndex, start.getLine() - 1, start.getColumn() - 1, tmp, true), null);
-                    // mark the end
-                    markupList.put(new MarkupText(fileIndex, end.getLine() - 1, end.getColumn() + end.getLength() - 1, "</B></FONT>", false), null);
-
-                    // the link location is placed 3 lines before the start of a block
-                    int linkLine = (Math.max(start.getLine() - 4, 0));
-                    markupList.put(new MarkupText(fileIndex, linkLine, 0, "<A NAME=\"" + x + "\"></A>", false), null);
-                }
-            }
-        }
-
-        if (options.hasBaseCode() && comparison.getFirstBaseCodeMatches() != null && comparison.getSecondBaseCodeMatches() != null) {
-            JPlagComparison baseCodeComparison = comparison.getBaseCodeMatches(j == 0);
-
-            for (Match match : baseCodeComparison.getMatches()) {
-                Token start = tokens.getToken(match.getStartOfFirst());
-                Token end = tokens.getToken(match.getStartOfFirst() + match.getLength() - 1);
-
-                for (int fileIndex = 0; fileIndex < files.length; fileIndex++) {
-                    if (start.getFile().equals(files[fileIndex]) && text[fileIndex] != null) {
-                        String tmp = "<font color=\"#C0C0C0\"><EM>";
-                        // beginning of the colorblock
-                        markupList.put(new MarkupText(fileIndex, start.getLine() - 1, start.getColumn() - 1, tmp, false), null);
-                        // mark the end
-                        markupList.put(new MarkupText(fileIndex, end.getLine() - 1, end.getColumn() + end.getLength() - 1, "</EM></font>", true),
-                                null);
-                    }
-                }
-            }
-        }
-
-        // Apply changes:
-        for (MarkupText markup : markupList.keySet()) {
-            // System.out.println(markup);
-            String tmp = text[markup.fileIndex][markup.lineIndex];
-            // is there any &quot;, &amp;, &gt; or &lt; in the String?
-            if (tmp.indexOf('&') >= 0) {
-                List<String> list = new ArrayList<>();
-                // convert the string into a vector
-                int strLength = tmp.length();
-                for (int k = 0; k < strLength; k++) {
-                    if (tmp.charAt(k) != '&') {
-                        list.add(tmp.charAt(k) + "");
-                    } else { // put &quot;, &amp;, &gt; and &lt; into one element
-                        String tmpSub = tmp.substring(k);
-                        if (tmpSub.startsWith("&quot;")) {
-                            list.add("&quot;");
-                            k = k + 5;
-                        } else if (tmpSub.startsWith("&amp;")) {
-                            list.add("&amp;");
-                            k = k + 4;
-                        } else if (tmpSub.startsWith("&lt;")) {
-                            list.add("&lt;");
-                            k = k + 3;
-                        } else if (tmpSub.startsWith("&gt;")) {
-                            list.add("&gt;");
-                            k = k + 3;
-                        } else {
-                            list.add(tmp.charAt(k) + "");
-                        }
-                    }
-                }
-                if (markup.column <= list.size()) {
-                    list.add(markup.column, markup.text);
-                } else {
-                    list.add(markup.text);
-                }
-
-                StringBuilder builder = new StringBuilder();
-                // reconvert the Vector into a String
-                for (String element : list) {
-                    builder.append(element);
-                }
-                text[markup.fileIndex][markup.lineIndex] = builder.toString();
-            } else {
-                text[markup.fileIndex][markup.lineIndex] = tmp.substring(0, (Math.min(tmp.length(), markup.column))) + markup.text
-                        + tmp.substring((Math.min(tmp.length(), markup.column)));
-            }
-        }
-
-        f.println("<div style=\"flex-grow: 1;\">");
-
-        for (int x = 0; x < text.length; x++) {
-            f.println("<h3>");
-            f.println("<center>");
-            f.println("<span>" + sub.getName() + "</span>");
-            f.println("<span> - </span>");
-            f.println("<span>" + files[x] + "</span>");
-            f.println("</center>");
-            f.println("</h3>");
-            f.println("<HR>");
-            if (options.getLanguage().isPreformatted()) {
-                f.println("<PRE>");
-            }
-            for (int y = 0; y < text[x].length; y++) {
-                f.print(text[x][y]);
-                if (!options.getLanguage().isPreformatted()) {
-                    f.println("<BR>");
-                } else {
-                    f.println();
-                }
-            }
-            if (options.getLanguage().isPreformatted()) {
-                f.println("</PRE>");
-            }
-        }
-
-        f.println("</div>");
-
-        return f.bytesWritten();
-    }
+public interface Report {
 
     /**
-     * Write the index.html file.
-     */
-    private void writeIndex() throws ReportGenerationException {
-        HTMLFile htmlFile = createHTMLFile("index.html");
-
-        writeIndexBegin(htmlFile, msg.getString("Report.Search_Results"));
-        writeDistribution(htmlFile);
-
-        writeLinksToComparisons(htmlFile, "<H4>" + msg.getString("Report.MatchesAvg"), CSV_FILE);
-
-        writeMatchesCSV(CSV_FILE);
-
-        writeIndexEnd(htmlFile);
-
-        htmlFile.close();
-    }
-
-    /**
-     * Write the beginning of the index.html file.
-     */
-    private void writeIndexBegin(HTMLFile htmlFile, String title) {
-        writeHTMLHeader(htmlFile, title);
-
-        htmlFile.println("<BODY BGCOLOR=#ffffff LINK=#000088 VLINK=#000000 TEXT=#000000>");
-        htmlFile.println("<TABLE ALIGN=center CELLPADDING=2 CELLSPACING=1>");
-        htmlFile.println("<TR VALIGN=middle ALIGN=center BGCOLOR=#ffffff><TD>" + "<IMG SRC=\"logo.png\" ALT=\"JPlag\" BORDER=0></TD>");
-        htmlFile.println("<TD><H1><BIG>" + title + "</BIG></H1></TD></TR>");
-
-        htmlFile.println("<TR BGCOLOR=#aaaaff VALIGN=top><TD>" + msg.getString("Report.Language") + ":</TD><TD>" + options.getLanguageOption().name()
-                + "</TD></TR>");
-        htmlFile.print("<TR BGCOLOR=#aaaaff VALIGN=top><TD>" + msg.getString("Report.Submissions") + ":</TD><TD>" + result.getNumberOfSubmissions());
-
-        htmlFile.println("</TD></TR>");
-
-        if (options.hasBaseCode()) {
-            htmlFile.print("<TR BGCOLOR=#aaaaff VALIGN=top><TD>" + msg.getString("Report.Basecode_submission") + ":</TD>" + "<TD>"
-                    + options.getBaseCodeSubmissionName().get() + "</TD></TR>");
-        }
-
-        if (options.getMaximumNumberOfComparisons() > 0) {
-            htmlFile.println("<TR BGCOLOR=#aaaaff VALIGN=top><TD>" + msg.getString("Report.Matches_displayed") + ":</TD>" + "<TD>");
-            htmlFile.println(options.getMaximumNumberOfComparisons() + " of " + result.getComparisons().size() + " ("
-                    + msg.getString("Report.Treshold") + ": " + options.getSimilarityThreshold() + "%)<br>");
-
-            htmlFile.println("</TD></TR>");
-        }
-
-        SimpleDateFormat dateFormat = new SimpleDateFormat();
-
-        htmlFile.println(
-                "<TR BGCOLOR=#aaaaff VALIGN=top><TD>" + msg.getString("Report.Date") + ":</TD><TD>" + dateFormat.format(new Date()) + "</TD></TR>");
-        htmlFile.println("<TR BGCOLOR=#aaaaff>" + "<TD><EM>" + msg.getString("Report.Minimum_Match_Length") + "</EM> ("
-                + msg.getString("Report.sensitivity") + "):</TD><TD>" + options.getMinimumTokenMatch() + "</TD></TR>");
-        htmlFile.println("<TR BGCOLOR=#aaaaff VALIGN=top><TD>" + msg.getString("Report.Suffixes") + ":</TD><TD>");
-
-        String[] fileSuffixes = options.getFileSuffixes();
-
-        for (int i = 0; i < fileSuffixes.length; i++) {
-            htmlFile.print(fileSuffixes[i] + (i < fileSuffixes.length - 1 ? ", " : "</TD></TR>\n"));
-        }
-
-        htmlFile.println("</TABLE>\n<HR>");
-    }
-
-    /*
-     * i is the number of the match j == 0 if subA is considered, otherwise it is subB This procedure uses only the
-     * getIndex() method of the token. It is meant to be used with the Character front end
+     * This function returns a list containing the report objects as simple strings. The first element is the string of the
+     * overview object. Each following element is a string of a comparison report object.
+     * @param result The result of a JPlag comparison
+     * @return A list containing report objects to string. First element is Overview. Other elements are comparisons.
      */
-    private void writeIndexedSubmission(HTMLFile f, int i, JPlagComparison comparison, int j) throws ReportGenerationException {
-        boolean useFirst = j == 0;
-        Submission sub = comparison.getSubmission(useFirst);
-        String[] files = comparison.files(j);
-        char[][] text = sub.readFilesChar(files);
-        TokenList tokens = comparison.getSubmission(useFirst).getTokenList();
-
-        // get index array with matches sorted in ascending order.
-        List<Integer> perm = comparison.sort_permutation(useFirst);
-
-        int index = 0; // match index
-        Match onematch = null;
-        Token start = null;
-        Token end = null;
-
-        f.println("<div style=\"flex-grow: 1;\">");
-
-        for (int fileIndex = 0; fileIndex < files.length; fileIndex++) {
-            f.println("<h3>");
-            f.println("<center>");
-            f.println("<span>" + sub.getName() + "</span>");
-            f.println("<span> - </span>");
-            f.println("<span>" + files[fileIndex] + "</span>");
-            f.println("</center>");
-            f.println("</h3>");
-            f.println("<HR>");
-            char[] buffer = text[fileIndex];
-
-            for (int charNr = 0; charNr < buffer.length; charNr++) {
-                if (onematch == null) {
-                    if (index < comparison.getMatches().size()) {
-                        onematch = comparison.getMatches().get(perm.get(index));
-                        start = tokens.getToken(onematch.getStart(j == 0));
-                        end = tokens.getToken((onematch.getStart(j == 0)) + onematch.getLength() - 1);
-                        index++;
-                    } else {
-                        start = end = null;
-                    }
-                }
-                // begin markup
-                if (start != null && start.getIndex() == charNr) {
-                    f.print("<A NAME=\"" + perm.get(index - 1) + "\"></A>");
-                    f.print("<FONT color=\"" + Color.getHexadecimalValue(perm.get(index - 1)) + "\"><B>");
-                    // "<A HREF=\"javascript:ZweiFrames('match"+i+"-"+(1-j)+
-                    // ".html#"+index+"',"+(3-j)+",'match"+i+"-top.html#"+index+
-                    // "',1)\">"+"<IMG SRC=\""+pics[j]+
-                    // "\" ALT=\"other\" BORDER=\"0\" "+"ALIGN="+
-                    // (j==0 ? "right" : "left")+"></A>");
-                }
-                // text
-                if (buffer[charNr] == '<') {
-                    f.print("&lt;");
-                } else if (buffer[charNr] == '>') {
-                    f.print("&gt;");
-                } else if (buffer[charNr] == '\n') {
-                    f.print("<br>\n");
-                } else {
-                    f.print(buffer[charNr]);
-                }
-                // end markup
-                if (end != null && end.getIndex() == charNr) {
-                    f.print("</B></FONT>");
-                    onematch = null; // switch to next match
-                }
-            }
-        }
-
-        f.println("</div>");
-    }
+    List<String> getReportStrings(JPlagResult result);
 
     /**
-     * Write the end of the index.html file.
+     * Creates and saves JPlag report files to the disk.
+     * @param result The result of a JPlag comparison.
+     * @param path Path to the directory where the report should be saved.
+     * @return True if the process is successful, otherwise false.
      */
-    private void writeIndexEnd(HTMLFile htmlFile) {
-        htmlFile.println("<HR>\n<P ALIGN=right><FONT SIZE=\"1\" FACE=\"helvetica\">JPlag</FONT></P>");
-        htmlFile.println("</BODY>\n</HTML>");
-    }
-
-    private void writeLinksToComparisons(HTMLFile htmlFile, String headerStr, String csvFile) {
-        List<JPlagComparison> comparisons = result.getComparisons(options.getMaximumNumberOfComparisons()); // should be already sorted!
-
-        htmlFile.println(headerStr + " (<a href=\"help-sim-" + "en" // Country tag
-                + ".html\"><small><font color=\"#000088\">" + msg.getString("Report.WhatIsThis") + "</font></small></a>):</H4>");
-        htmlFile.println("<p><a href=\"" + csvFile + "\">download csv</a></p>");
-        htmlFile.println("<TABLE CELLPADDING=3 CELLSPACING=2>");
-
-        for (JPlagComparison comparison : comparisons) {
-            String submissionNameA = comparison.getFirstSubmission().getName();
-            String submissionNameB = comparison.getSecondSubmission().getName();
-
-            htmlFile.print("<TR><TD BGCOLOR=" + color(comparison.similarityOfFirst(), 128, 192, 128, 192, 255, 255) + ">" + submissionNameA
-                    + "</TD><TD><nobr>-&gt;</nobr>");
-
-            htmlFile.print("</TD><TD BGCOLOR=" + color(comparison.similarityOfSecond(), 128, 192, 128, 192, 255, 255)
-                    + " ALIGN=center><A HREF=\"match" + getComparisonIndex(comparison) + ".html\">" + submissionNameB + "</A><BR><FONT COLOR=\""
-                    + color(comparison.similarity(), 0, 255, 0, 0, 0, 0) + "\">(" + (((int) (comparison.similarity() * 10)) / (float) 10)
-                    + "%)</FONT>");
-
-            htmlFile.println("</TD></TR>");
-        }
-
-        htmlFile.println("</TABLE><P>\n");
-        htmlFile.println("<!---->");
-    }
-
-    private void writeMatch(JPlagComparison comparison, int i) throws ReportGenerationException {
-        HTMLFile htmlFile = createHTMLFile("match" + i + ".html");
-
-        writeHTMLHeader(htmlFile, TagParser.parse(msg.getString("Report.Matches_for_X1_AND_X2"),
-                new String[] {comparison.getFirstSubmission().getName(), comparison.getSecondSubmission().getName()}));
-
-        htmlFile.println("<body>");
-        htmlFile.println("  <div style=\"align-items: center; display: flex; justify-content: space-around;\">");
-
-        htmlFile.println("    <div>");
-        htmlFile.println("      <h3 align=\"center\">");
-        htmlFile.println(TagParser.parse(msg.getString("Report.Matches_for_X1_AND_X2"),
-                new String[] {comparison.getFirstSubmission().getName(), comparison.getSecondSubmission().getName()}));
-        htmlFile.println("      </h3>");
-        htmlFile.println("      <h1 align=\"center\">");
-        htmlFile.println("        " + comparison.roundedSimilarity() + "%");
-        htmlFile.println("      </h1>");
-        htmlFile.println("      <center>");
-        htmlFile.println("        <a href=\"index.html\" target=\"_top\">");
-        htmlFile.println("          " + msg.getString("Report.INDEX"));
-        htmlFile.println("        </a>");
-        htmlFile.println("        <span>-</span>");
-        htmlFile.println("        <a href=\"help-en.html\" target=\"_top\">");
-        htmlFile.println("          " + msg.getString("Report.HELP"));
-        htmlFile.println("        </a>");
-        htmlFile.println("      </center>");
-        htmlFile.println("    </div>");
-
-        htmlFile.println("    <div>");
-        reportComparison(htmlFile, comparison, i);
-        htmlFile.println("    </div>");
-
-        htmlFile.println("  </div>");
-
-        htmlFile.println("  <hr>");
-
-        htmlFile.println("  <div style=\"display: flex;\">");
-
-        if (options.getLanguage().usesIndex()) {
-            writeIndexedSubmission(htmlFile, i, comparison, 0);
-            writeIndexedSubmission(htmlFile, i, comparison, 1);
-        } else if (options.getLanguage().supportsColumns()) {
-            writeImprovedSubmission(htmlFile, i, comparison, 0);
-            writeImprovedSubmission(htmlFile, i, comparison, 1);
-        } else {
-            writeNormalSubmission(htmlFile, i, comparison, 0);
-            writeNormalSubmission(htmlFile, i, comparison, 1);
-        }
-
-        htmlFile.println("  </div>");
-
-        htmlFile.println("</body>");
-        htmlFile.println("</html>");
-        htmlFile.close();
-    }
-
-    private void writeMatches(List<JPlagComparison> comparisons) {
-        comparisons.parallelStream().forEach(comparison -> {
-            try {
-                writeMatch(comparison, getComparisonIndex(comparison));
-            } catch (ExitException exception) {
-                exception.printStackTrace();
-            }
-            reportMatchWritingProgress(comparisons);
-        });
-    }
-
-    private void writeMatchesCSV(String fileName) {
-        FileWriter writer = null;
-        File csvFile = new File(reportDir, fileName);
-        List<JPlagComparison> comparisons = result.getComparisons(options.getMaximumNumberOfComparisons());
-
-        try {
-            csvFile.createNewFile();
-            writer = new FileWriter(csvFile, JPlagOptions.CHARSET);
-
-            for (JPlagComparison comparison : comparisons) {
-                String submissionNameA = comparison.getFirstSubmission().getName();
-                String submissionNameB = comparison.getSecondSubmission().getName();
-
-                writer.write(getComparisonIndex(comparison) + ";");
-                writer.write(submissionNameA + ";");
-                writer.write(submissionNameB + ";");
-                writer.write((((int) (comparison.similarity() * 10)) / (float) 10) + ";");
-                writer.write("\n");
-            }
-
-            writer.flush();
-        } catch (Exception e) {
-            e.printStackTrace();
-        } finally {
-            try {
-                writer.close();
-            } catch (Exception ignored) {
-            }
-        }
-    }
-
-    /*
-     * i is the number of the match j == 0 if subA is considered, otherwise (j must then be 1) it is subB
-     */
-    private void writeNormalSubmission(HTMLFile f, int i, JPlagComparison comparison, int j) throws ReportGenerationException {
-        Submission sub = comparison.getSubmission(j == 0);
-        String[] files = comparison.files(j);
-
-        String[][] text = sub.readFiles(files);
-
-        TokenList tokens = comparison.getSubmission(j == 0).getTokenList();
-        String hilf;
-        int h;
-        for (int x = 0; x < comparison.getMatches().size(); x++) {
-            Match currentMatch = comparison.getMatches().get(x);
-
-            Token start = tokens.getToken(currentMatch.getStart(j == 0));
-            Token end = tokens.getToken((currentMatch.getStart(j == 0)) + currentMatch.getLength() - 1);
-
-            for (int y = 0; y < files.length; y++) {
-                if (start.getFile().equals(files[y]) && text[y] != null) {
-                    hilf = "<FONT color=\"" + Color.getHexadecimalValue(x) + "\">" + (j == 1 ? "<div style=\"position:absolute;left:0\">" : "")
-                            + "<A HREF=\"javascript:ZweiFrames('match" + i + "-" + (1 - j) + ".html#" + x + "'," + (3 - j) + ",'match" + i
-                            + "-top.html#" + x + "',1)\"><IMG SRC=\"" + PICS[j] + "\" ALT=\"other\" " + "BORDER=\"0\" ALIGN=\""
-                            + (j == 0 ? "right" : "left") + "\"></A>" + (j == 1 ? "</div>" : "") + "<B>";
-                    // position the icon and the beginning of the colorblock
-                    if (text[y][start.getLine() - 1].endsWith("</FONT>")) {
-                        text[y][start.getLine() - 1] += hilf;
-                    } else {
-                        text[y][start.getLine() - 1] = hilf + text[y][start.getLine() - 1];
-                    }
-                    // the link location is placed 3 lines before the start of a block
-                    h = (Math.max(start.getLine() - 4, 0));
-                    text[y][h] = "<A NAME=\"" + x + "\"></A>" + text[y][h];
-                    // mark the end
-                    if (start.getLine() != end.getLine() && // if match is only one line
-                            text[y][end.getLine() - 1].startsWith("<FONT ")) {
-                        text[y][end.getLine() - 1] = "</B></FONT>" + text[y][end.getLine() - 1];
-                    } else {
-                        text[y][end.getLine() - 1] += "</B></FONT>";
-                    }
-                }
-            }
-        }
-
-        if (options.hasBaseCode() && comparison.getFirstBaseCodeMatches() != null && comparison.getSecondBaseCodeMatches() != null) {
-            JPlagComparison baseCodeComparison = comparison.getBaseCodeMatches(j == 0);
-
-            for (Match currentMatch : baseCodeComparison.getMatches()) {
-                Token start = tokens.getToken(currentMatch.getStartOfFirst());
-                Token end = tokens.getToken(currentMatch.getStartOfFirst() + currentMatch.getLength() - 1);
-
-                for (int y = 0; y < files.length; y++) {
-                    if (start.getFile().equals(files[y]) && text[y] != null) {
-                        hilf = ("<font color=\"#C0C0C0\"><EM>");
-                        // position the icon and the beginning of the colorblock
-                        if (text[y][start.getLine() - 1].endsWith("<font color=\"#000000\">")) {
-                            text[y][start.getLine() - 1] += hilf;
-                        } else {
-                            text[y][start.getLine() - 1] = hilf + text[y][start.getLine() - 1];
-                        }
-
-                        // mark the end
-                        if (start.getLine() != end.getLine() && // match is only one line
-                                text[y][end.getLine() - 1].startsWith("<font color=\"#C0C0C0\">")) {
-                            text[y][end.getLine() - 1] = "</EM><font color=\"#000000\">" + text[y][end.getLine() - 1];
-                        } else {
-                            text[y][end.getLine() - 1] += "</EM><font color=\"#000000\">";
-                        }
-                    }
-                }
-            }
-        }
-
-        f.println("<div style=\"flex-grow: 1;\">");
-
-        for (int x = 0; x < text.length; x++) {
-            f.println("<h3>");
-            f.println("<center>");
-            f.println("<span>" + sub.getName() + "</span>");
-            f.println("<span> - </span>");
-            f.println("<span>" + files[x] + "</span>");
-            f.println("</center>");
-            f.println("</h3>");
-            f.println("<HR>");
-            if (options.getLanguage().isPreformatted()) {
-                f.println("<PRE>");
-            }
-            for (int y = 0; y < text[x].length; y++) {
-                f.print(text[x][y]);
-                if (!options.getLanguage().isPreformatted()) {
-                    f.println("<BR>");
-                } else {
-                    f.println();
-                }
-            }
-            if (options.getLanguage().isPreformatted()) {
-                f.println("</PRE>");
-            }
-        }
-
-        f.println("</div>");
-    }
+    boolean saveReport(JPlagResult result, String path);
 }

+ 0 - 35
jplag/src/main/java/de/jplag/reporting/TagParser.java

@@ -1,35 +0,0 @@
-package de.jplag.reporting;
-
-public class TagParser {
-
-    /**
-     * Replaces all "{&lt;index&gt;_description}" tags inside the message string with params[&lt;index&gt;-1].
-     * <p>
-     * Example: parse("blb {1_n/a} d {3_desc} sf {2_bla} d", new String[] {"#", blabla(), null}); returns "blb # d null sf
-     * blab d", if blabla() returns "blab"
-     */
-    public static String parse(String message, String[] params) {
-        String[] tokens = message.split("[{}]", -1);
-        String result = tokens[0];
-
-        for (int i = 1; i < tokens.length; i += 2) { // Go to next tag position
-            try {
-                int ind = tokens[i].indexOf('_');
-                String num = (ind == -1) ? tokens[i] : tokens[i].substring(0, ind);
-                result += params[Integer.parseInt(num) - 1];
-            } catch (Exception ex) {
-                if (ex instanceof NumberFormatException || ex instanceof IndexOutOfBoundsException) {
-                    ex.printStackTrace();
-                    result += "{ILLEGAL PARAMETER INDEX \"" + tokens[i] + "\"}";
-                } else {
-                    throw (RuntimeException) ex;
-                }
-            }
-            if (i + 1 < tokens.length) {
-                result += tokens[i + 1];
-            }
-        }
-
-        return result;
-    }
-}

+ 3 - 3
jplag/src/main/java/de/jplag/reporting2/jsonfactory/JsonFactory.java → jplag/src/main/java/de/jplag/reporting/jsonfactory/JsonFactory.java

@@ -1,4 +1,4 @@
-package de.jplag.reporting2.jsonfactory;
+package de.jplag.reporting.jsonfactory;
 
 import java.io.IOException;
 import java.nio.file.Path;
@@ -8,8 +8,8 @@ import java.util.List;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 
-import de.jplag.reporting2.reportobject.model.ComparisonReport;
-import de.jplag.reporting2.reportobject.model.JPlagReport;
+import de.jplag.reporting.reportobject.model.ComparisonReport;
+import de.jplag.reporting.reportobject.model.JPlagReport;
 
 /**
  * Factory class, responsible for creating Json strings and writing them to files.

+ 19 - 5
jplag/src/main/java/de/jplag/reporting2/reportobject/ReportObjectFactory.java → jplag/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java

@@ -1,16 +1,30 @@
-package de.jplag.reporting2.reportobject;
+package de.jplag.reporting.reportobject;
 
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
 import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
 import java.util.stream.Collectors;
 
-import de.jplag.*;
-import de.jplag.reporting2.reportobject.model.*;
-import de.jplag.reporting2.reportobject.model.Match;
+import de.jplag.JPlagComparison;
+import de.jplag.JPlagResult;
+import de.jplag.Submission;
+import de.jplag.Token;
+import de.jplag.TokenList;
+import de.jplag.reporting.reportobject.model.Cluster;
+import de.jplag.reporting.reportobject.model.ComparisonReport;
+import de.jplag.reporting.reportobject.model.FilesOfSubmission;
+import de.jplag.reporting.reportobject.model.JPlagReport;
+import de.jplag.reporting.reportobject.model.Match;
+import de.jplag.reporting.reportobject.model.Metric;
+import de.jplag.reporting.reportobject.model.OverviewReport;
+import de.jplag.reporting.reportobject.model.TopComparison;
 
 /**
  * Factory class, responsible for converting a JPlagResult object to Overview and Comparison DTO classes.

+ 1 - 1
jplag/src/main/java/de/jplag/reporting2/reportobject/model/Cluster.java → jplag/src/main/java/de/jplag/reporting/reportobject/model/Cluster.java

@@ -1,4 +1,4 @@
-package de.jplag.reporting2.reportobject.model;
+package de.jplag.reporting.reportobject.model;
 
 import java.util.List;
 

+ 1 - 1
jplag/src/main/java/de/jplag/reporting2/reportobject/model/ComparisonReport.java → jplag/src/main/java/de/jplag/reporting/reportobject/model/ComparisonReport.java

@@ -1,4 +1,4 @@
-package de.jplag.reporting2.reportobject.model;
+package de.jplag.reporting.reportobject.model;
 
 import java.util.List;
 

+ 1 - 1
jplag/src/main/java/de/jplag/reporting2/reportobject/model/FilesOfSubmission.java → jplag/src/main/java/de/jplag/reporting/reportobject/model/FilesOfSubmission.java

@@ -1,4 +1,4 @@
-package de.jplag.reporting2.reportobject.model;
+package de.jplag.reporting.reportobject.model;
 
 import java.util.List;
 

+ 1 - 1
jplag/src/main/java/de/jplag/reporting2/reportobject/model/JPlagReport.java → jplag/src/main/java/de/jplag/reporting/reportobject/model/JPlagReport.java

@@ -1,4 +1,4 @@
-package de.jplag.reporting2.reportobject.model;
+package de.jplag.reporting.reportobject.model;
 
 import java.util.List;
 

+ 1 - 1
jplag/src/main/java/de/jplag/reporting2/reportobject/model/Match.java → jplag/src/main/java/de/jplag/reporting/reportobject/model/Match.java

@@ -1,4 +1,4 @@
-package de.jplag.reporting2.reportobject.model;
+package de.jplag.reporting.reportobject.model;
 
 import com.fasterxml.jackson.annotation.JsonProperty;
 

+ 1 - 1
jplag/src/main/java/de/jplag/reporting2/reportobject/model/Metric.java → jplag/src/main/java/de/jplag/reporting/reportobject/model/Metric.java

@@ -1,4 +1,4 @@
-package de.jplag.reporting2.reportobject.model;
+package de.jplag.reporting.reportobject.model;
 
 import java.util.List;
 

+ 1 - 1
jplag/src/main/java/de/jplag/reporting2/reportobject/model/OverviewReport.java → jplag/src/main/java/de/jplag/reporting/reportobject/model/OverviewReport.java

@@ -1,4 +1,4 @@
-package de.jplag.reporting2.reportobject.model;
+package de.jplag.reporting.reportobject.model;
 
 import java.util.List;
 import java.util.Set;

+ 1 - 1
jplag/src/main/java/de/jplag/reporting2/reportobject/model/TopComparison.java → jplag/src/main/java/de/jplag/reporting/reportobject/model/TopComparison.java

@@ -1,4 +1,4 @@
-package de.jplag.reporting2.reportobject.model;
+package de.jplag.reporting.reportobject.model;
 
 import com.fasterxml.jackson.annotation.JsonProperty;
 

+ 0 - 29
jplag/src/main/java/de/jplag/reporting2/Report.java

@@ -1,29 +0,0 @@
-package de.jplag.reporting2;
-
-import java.util.List;
-
-import de.jplag.JPlagResult;
-
-// ReportStrategy -> Report
-
-/**
- * Strategy interface for reporting. A report generator should implement this interface.
- */
-public interface Report {
-
-    /**
-     * This function returns a list containing the report objects as simple strings. The first element is the string of the
-     * overview object. Each following element is a string of a comparison report object.
-     * @param result The result of a JPlag comparison
-     * @return A list containing report objects to string. First element is Overview. Other elements are comparisons.
-     */
-    List<String> getReportStrings(JPlagResult result);
-
-    /**
-     * Creates and saves JPlag report files to the disk.
-     * @param result The result of a JPlag comparison.
-     * @param path Path to the directory where the report should be saved.
-     * @return True if the process is successful, otherwise false.
-     */
-    boolean saveReport(JPlagResult result, String path);
-}

+ 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));
-            }
-        }
-
-    }
-}