use of de.jplag.exceptions.ExitException in project JPlag by jplag.
the class SubmissionSetBuilder method loadBaseCodeViaName.
/**
* Try to load the basecode by looking up the basecode name in the root directory.
* @return the base code submission if a fitting subdirectory was found, else {@code null}.
* @throws ExitException when the option value is a sub-directory with errors.
*/
private Submission loadBaseCodeViaName(String baseCodeName, File rootDirectory, Map<File, Submission> foundSubmissions) throws ExitException {
// Is the option value a single name after trimming spurious separators?
String name = baseCodeName;
while (name.startsWith(File.separator)) {
name = name.substring(1);
}
while (name.endsWith(File.separator)) {
name = name.substring(0, name.length() - 1);
}
// If it is not a name of a single sub-directory, bail out.
if (name.isEmpty() || name.contains(File.separator)) {
return null;
}
if (name.contains(".")) {
throw new BasecodeException("The basecode directory name \"" + name + "\" cannot contain dots!");
}
// Grab the basecode submission from the regular submissions.
File basecodePath = new File(rootDirectory, baseCodeName);
Submission baseCode = foundSubmissions.get(makeCanonical(basecodePath, it -> new BasecodeException("Cannot compute canonical file path: " + basecodePath, it)));
if (baseCode == null) {
// No base code found at all, report an error.
throw new BasecodeException(String.format("Basecode path \"%s\" relative to the working directory could not be found.", baseCodeName));
} else {
// Found a base code as a submission, report about legacy usage.
System.out.println("Legacy use of the -bc option found, please specify the basecode by path instead of by name!");
}
return baseCode;
}
use of de.jplag.exceptions.ExitException in project JPlag by jplag.
the class SubmissionSetBuilder method verifyRootDirectories.
/**
* Verify that the given root directories exist and have no duplicate entries.
*/
private Set<File> verifyRootDirectories(List<String> rootDirectoryNames) throws ExitException {
Set<File> canonicalRootDirectories = new HashSet<>(rootDirectoryNames.size());
for (String rootDirectoryName : rootDirectoryNames) {
File rootDirectory = new File(rootDirectoryName);
if (!rootDirectory.exists()) {
throw new RootDirectoryException(String.format("Root directory \"%s\" does not exist!", rootDirectoryName));
}
if (!rootDirectory.isDirectory()) {
throw new RootDirectoryException(String.format("Root directory \"%s\" is not a directory!", rootDirectoryName));
}
rootDirectory = makeCanonical(rootDirectory, it -> new RootDirectoryException("Cannot read root directory: " + rootDirectoryName, it));
if (!canonicalRootDirectories.add(rootDirectory)) {
// Root directory was already added, report a warning.
System.out.printf("Warning: Root directory \"%s\" was specified more than once, duplicates will be ignored.", rootDirectoryName);
}
}
return canonicalRootDirectories;
}
use of de.jplag.exceptions.ExitException in project JPlag by jplag.
the class SubmissionSetBuilder method loadBaseCodeAsPath.
/**
* Try to load the basecode under the assumption of being a path.
* @return Base code submission if the option value can be interpreted as global path, else {@code null}.
* @throws ExitException when the option value is a path with errors.
*/
private Submission loadBaseCodeAsPath(String baseCodeName) throws ExitException {
File basecodeSubmission = new File(baseCodeName);
if (!basecodeSubmission.exists()) {
return null;
}
String errorMessage = isExcludedEntry(basecodeSubmission);
if (errorMessage != null) {
// Stating an excluded path as basecode isn't very useful.
throw new BasecodeException(errorMessage);
}
try {
// in the output since basecode matches are removed from it
return processSubmission(basecodeSubmission.getName(), basecodeSubmission);
} catch (SubmissionException exception) {
// Change thrown exception to basecode exception.
throw new BasecodeException(exception.getMessage(), exception);
} catch (ExitException exception) {
throw exception;
}
}
use of de.jplag.exceptions.ExitException in project JPlag by jplag.
the class CLI method main.
/**
* Main class for using JPlag via the CLI.
* @param args are the CLI arguments that will be passed to JPlag.
*/
public static void main(String[] args) {
try {
CLI cli = new CLI();
Namespace arguments = cli.parseArguments(args);
JPlagOptions options = cli.buildOptionsFromArguments(arguments);
JPlag program = new JPlag(options);
System.out.println("JPlag initialized");
JPlagResult result = program.run();
Report report = new JsonReport();
report.saveReport(result, arguments.getString(RESULT_FOLDER.flagWithoutDash()));
} catch (ExitException exception) {
System.out.println("Error: " + exception.getMessage());
System.exit(1);
}
}
Aggregations