|
@@ -43,18 +43,9 @@ public class JPlag {
|
|
|
* @throws ExitException if the JPlag exits preemptively.
|
|
* @throws ExitException if the JPlag exits preemptively.
|
|
|
*/
|
|
*/
|
|
|
public JPlagResult run() throws ExitException {
|
|
public JPlagResult run() throws ExitException {
|
|
|
- // 1. Preparation:
|
|
|
|
|
- File rootDir = new File(options.getRootDirectoryName());
|
|
|
|
|
- if (!rootDir.exists()) {
|
|
|
|
|
- throw new ExitException("Root directory " + options.getRootDirectoryName() + " does not exist!");
|
|
|
|
|
- }
|
|
|
|
|
- if (!rootDir.isDirectory()) {
|
|
|
|
|
- throw new ExitException(options.getRootDirectoryName() + " is not a directory!");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 2. Parse and validate submissions:
|
|
|
|
|
|
|
+ // Parse and validate submissions.
|
|
|
SubmissionSetBuilder builder = new SubmissionSetBuilder(language, options, errorCollector);
|
|
SubmissionSetBuilder builder = new SubmissionSetBuilder(language, options, errorCollector);
|
|
|
- SubmissionSet submissionSet = builder.buildSubmissionSet(rootDir);
|
|
|
|
|
|
|
+ SubmissionSet submissionSet = builder.buildSubmissionSet(getRootDirectory());
|
|
|
|
|
|
|
|
if (submissionSet.hasBaseCode()) {
|
|
if (submissionSet.hasBaseCode()) {
|
|
|
coreAlgorithm.createHashes(submissionSet.getBaseCode().getTokenList(), options.getMinimumTokenMatch(), true);
|
|
coreAlgorithm.createHashes(submissionSet.getBaseCode().getTokenList(), options.getMinimumTokenMatch(), true);
|
|
@@ -67,30 +58,20 @@ public class JPlag {
|
|
|
ExitException.NOT_ENOUGH_SUBMISSIONS_ERROR);
|
|
ExitException.NOT_ENOUGH_SUBMISSIONS_ERROR);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 3. Compare valid submissions:
|
|
|
|
|
|
|
+ // Compare valid submissions.
|
|
|
JPlagResult result = comparisonStrategy.compareSubmissions(submissionSet);
|
|
JPlagResult result = comparisonStrategy.compareSubmissions(submissionSet);
|
|
|
System.out.println("Total time for comparing submissions: " + TimeUtil.formatDuration(result.getDuration()));
|
|
System.out.println("Total time for comparing submissions: " + TimeUtil.formatDuration(result.getDuration()));
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * @return the configured language in which the submissions are written.
|
|
|
|
|
- */
|
|
|
|
|
- public Language getLanguage() {
|
|
|
|
|
- return language;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* This method checks whether the base code directory value is valid.
|
|
* This method checks whether the base code directory value is valid.
|
|
|
*/
|
|
*/
|
|
|
private void checkBaseCodeOption() throws ExitException {
|
|
private void checkBaseCodeOption() throws ExitException {
|
|
|
- if (options.hasBaseCode()) {
|
|
|
|
|
- if (!new File(options.getRootDirectoryName()).exists()) {
|
|
|
|
|
- throw new ExitException("Root directory \"" + options.getRootDirectoryName() + "\" doesn't exist!", ExitException.BAD_PARAMETER);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ getRootDirectory(); // Performs checks on the root directory.
|
|
|
|
|
|
|
|
- String baseCode = options.getBaseCodeSubmissionName().replace(File.separator, ""); // trim problematic file separators
|
|
|
|
|
|
|
+ if (options.hasBaseCode()) {
|
|
|
|
|
+ String baseCode = options.getBaseCodeSubmissionName();
|
|
|
if (baseCode.contains(".")) {
|
|
if (baseCode.contains(".")) {
|
|
|
throw new ExitException("The basecode directory name \"" + baseCode + "\" cannot contain dots!", ExitException.BAD_PARAMETER);
|
|
throw new ExitException("The basecode directory name \"" + baseCode + "\" cannot contain dots!", ExitException.BAD_PARAMETER);
|
|
|
}
|
|
}
|
|
@@ -106,11 +87,27 @@ public class JPlag {
|
|
|
ExitException.BAD_PARAMETER);
|
|
ExitException.BAD_PARAMETER);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- options.setBaseCodeSubmissionName(baseCode);
|
|
|
|
|
System.out.println("Basecode directory \"" + baseCodePath + "\" will be used");
|
|
System.out.println("Basecode directory \"" + baseCodePath + "\" will be used");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Check sanity of the root directory name in the options, and construct file system access to it.
|
|
|
|
|
+ */
|
|
|
|
|
+ private File getRootDirectory() throws ExitException {
|
|
|
|
|
+ String rootDirectoryName = options.getRootDirectoryName();
|
|
|
|
|
+ File rootDir = new File(rootDirectoryName);
|
|
|
|
|
+ if (!rootDir.exists()) {
|
|
|
|
|
+ String msg = String.format("Root directory \"%s\" does not exist!", rootDirectoryName);
|
|
|
|
|
+ throw new ExitException(msg, ExitException.BAD_PARAMETER);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!rootDir.isDirectory()) {
|
|
|
|
|
+ String msg = String.format("Root directory \"%s\" is not a directory!", rootDirectoryName);
|
|
|
|
|
+ throw new ExitException(msg, ExitException.BAD_PARAMETER);
|
|
|
|
|
+ }
|
|
|
|
|
+ return rootDir;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void initializeComparisonStrategy() throws ExitException {
|
|
private void initializeComparisonStrategy() throws ExitException {
|
|
|
switch (options.getComparisonMode()) {
|
|
switch (options.getComparisonMode()) {
|
|
|
case NORMAL:
|
|
case NORMAL:
|
|
@@ -142,8 +139,8 @@ public class JPlag {
|
|
|
throw new ExitException("Language instantiation failed", ExitException.BAD_LANGUAGE_ERROR);
|
|
throw new ExitException("Language instantiation failed", ExitException.BAD_LANGUAGE_ERROR);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.options.setLanguageDefaults(this.getLanguage());
|
|
|
|
|
|
|
+ this.options.setLanguageDefaults(this.language);
|
|
|
|
|
|
|
|
- System.out.println("Initialized language " + this.getLanguage().getName());
|
|
|
|
|
|
|
+ System.out.println("Initialized language " + this.language.getName());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|