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

Option -c to compare a list of files. Fixes #39

ov7a 9 лет назад
Родитель
Сommit
f5f6dd4d0d

+ 6 - 1
README.md

@@ -2,7 +2,7 @@
 Download a released version - all releases are single-JAR releases.
 
 Type `java -jar jplag-yourVersion.jar` in a console to see the command line options.
-The options as of 2016/02/29 are:
+The options as of 2017/09/17 are:
 
 ```
 JPlag (Version 2.11.9-SNAPSHOT), Copyright (c) 2004-2017 KIT - IPD Tichy, Guido Malpohl, and others.
@@ -32,6 +32,7 @@ options are:
  -r <dir>        (Result) Name of directory in which the web pages will be
                  stored (default: result)
  -bc <dir>       Name of the directory which contains the basecode (common framework)
+ -c [files]      Compare a list of files.
  -l <language>   (Language) Supported Languages:
                  java17 (default), java15, java15dm, java12, java11, python3, c/c++, c#-1.2, char, text, scheme
 ```
@@ -57,6 +58,10 @@ The option `-x` requires an exclusion list saved as `<file>`.
 The exclusion list contains a  number of suffixes.
 JPlag will ignore all files that end with one of the suffixes.
 
+### `-c [files]`   (Compare) Compare a list of files
+Example: `java -jar jplag-yourVersion.jar root_dir -l java17 -c student1_file student2_file student3_file`
+This option should be the last one.
+JPlag will compare just a list of files pairwise.
 
 # Building JPlag
 To build and run a local installation of JPlag, you can use the pom.xml in this directory (aggregator). It builds JPlag and the available frontends. 

+ 14 - 1
jplag/src/main/java/jplag/Program.java

@@ -442,6 +442,17 @@ public class Program implements ProgramI {
 		}
 	}
 
+	private void createSubmissionsFileList() throws jplag.ExitException {
+		submissions = new Vector<Submission>();
+		File f = new File(options.root_dir);
+		if (f == null || !f.isDirectory()) {
+			throw new jplag.ExitException(options.root_dir + " is not a directory!");
+		}
+		for (String file : options.fileList){
+			submissions.addElement(new Submission(file, f, this, get_language()));
+		}
+	}
+
 	/**
 	 * THIS IS FOR THE EMPIRICAL STUDY
 	 */
@@ -1124,7 +1135,9 @@ public class Program implements ProgramI {
 			print(null, "Root-dir: " + options.root_dir + "\n"); // server
 		// this file contains all files names which are excluded
 		readExclusionFile();
-		if (options.include_file == null) {
+		if (options.fileListMode) {
+			createSubmissionsFileList();
+		} else if (options.include_file == null) {
 			createSubmissions();
 			System.out.println(submissions.size() + " submissions");
 		} else

+ 8 - 2
jplag/src/main/java/jplag/options/CommandLineOptions.java

@@ -317,11 +317,17 @@ public class CommandLineOptions extends Options {
             System.out.println();
             i++;
         } else if (arg.equals("-title") && i+1 < args.length) {
-            if (args[i+1].equals("")) {
+            if (args[i + 1].equals("")) {
                 throw new jplag.ExitException("Title is empty!");
             }
-            this.title = args[i+1];
+            this.title = args[i + 1];
             i++;
+        } else if (arg.equals("-c") && i + 2 < args.length){
+            this.fileListMode = true;
+            while (i + 1 < args.length){
+                this.fileList.add(args[i + 1]);
+                i++;
+            }
         } else if (!scanOption(arg))
             throw new jplag.ExitException("Unknown option: " + arg,
                     ExitException.BAD_PARAMETER);

+ 12 - 2
jplag/src/main/java/jplag/options/Options.java

@@ -12,6 +12,9 @@ import jplag.Language;
 import jplag.Program;
 import jplag.clustering.SimilarityMatrix;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * @Author Emeric Kwemou 30.01.2005
  *  
@@ -129,6 +132,11 @@ public abstract class Options {
 
 	public jplag.Language language;
 
+	//compare two files options
+	public boolean fileListMode = false;
+
+	public List<String> fileList = new ArrayList<String>();
+
 	// "FINAL" OPTIONS
 	public boolean debugParser = false;
 
@@ -181,8 +189,9 @@ public abstract class Options {
 	public static void usage() {
 		System.out.print(Program.name_long
 						+ ", Copyright (c) 2004-2017 KIT - IPD Tichy, Guido Malpohl, and others.\n"
-						+ "Usage: JPlag [ options ] <root-dir>\n"
-						+ " <root-dir>        The root-directory that contains all submissions\n\n"
+						+ "Usage: JPlag [ options ] <root-dir> or JPlag [ options ] <file1> <file2>\n"
+						+ " <root-dir>        The root-directory that contains all submissions. \n"
+						+ "                   Mandatory unless -c flag is provided.\n\n"
 						+ "options are:\n"
 						+ " -v[qlpd]        (Verbose)\n"
 						+ "                 q: (Quiet) no output\n"
@@ -204,6 +213,7 @@ public abstract class Options {
 						+ " -r <dir>        (Result) Name of directory in which the web pages will be\n"
 						+ "                 stored (default: result)\n"
 						+ " -bc <dir>       Name of the directory which contains the basecode (common framework)\n"
+						+ " -c [files]      Compare a list of files. \n"
 						+ " -l <language>   (Language) Supported Languages:\n                 ");
 		for (int i = 0; i < languages.length - 2; i += 2)
 			System.out.print(languages[i] + (i == 0 ? " (default), " : ", "));