From 8c983e84e6e373c2879697a7ff21ab6aeae3b436 Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Mon, 20 Jul 2026 04:03:12 +0100 Subject: [PATCH] Exit codes for GenerateVerificationCode Signed-off-by: Arthit Suriyawongkul --- .../spdx/tools/GenerateVerificationCode.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) 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: + * * @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);