diff --git a/src/main/java/org/spdx/tools/GenerateVerificationCode.java b/src/main/java/org/spdx/tools/GenerateVerificationCode.java
index c125df5..3cf8411 100644
--- a/src/main/java/org/spdx/tools/GenerateVerificationCode.java
+++ b/src/main/java/org/spdx/tools/GenerateVerificationCode.java
@@ -37,6 +37,13 @@
/**
* Generates a verification code for a specific directory
+ *
+ * Exit codes:
+ *
+ * - 0 - the verification code was generated successfully
+ * - 1 - the verification code could not be generated
+ * - 2 - the command was invoked incorrectly (missing/invalid arguments)
+ *
* @author Gary O'Neall
*/
public class GenerateVerificationCode {
@@ -45,12 +52,23 @@ public class GenerateVerificationCode {
* Print an SPDX Verification code for a directory of files
* args[0] is the source directory containing the files
* args[1] is an optional regular expression of skipped files. The expression is applied against a file path relative the the source directory supplied
+ * Delegates to {@link #run(String[])} and terminates the JVM with its exit status.
* @param args
*/
public static void main(String[] args) {
+ System.exit(run(args));
+ }
+
+ /**
+ * Runs the GenerateVerificationCode command logic and reports results to
+ * standard out.
+ * @param args
+ * @return process exit status, see {@link ExitCode}
+ */
+ static int run(String[] args) {
if (args.length < 1 || args.length > 2) {
error("Incorrect number of arguments.");
- System.exit(1);
+ return ExitCode.USAGE_ERROR;
}
String directoryPath = args[0];
String skippedRegex = null;
@@ -62,13 +80,13 @@ public static void main(String[] args) {
try {
SpdxPackageVerificationCode verificationCode = generateVerificationCode(directoryPath, skippedRegex);
printVerificationCode(verificationCode);
- System.exit(0);
+ return ExitCode.SUCCESS;
} catch (Exception ex) {
error("Error creating verification code: "+ex.getMessage());
- System.exit(1);
+ return ExitCode.ERROR;
}
}
-
+
public static SpdxPackageVerificationCode generateVerificationCode(String directoryPath, @Nullable String skippedRegex) throws OnlineToolException {
Objects.requireNonNull(directoryPath, "Directory path must not be null");
File sourceDirectory = new File(directoryPath);