diff --git a/src/main/java/org/spdx/tools/MatchingStandardLicenses.java b/src/main/java/org/spdx/tools/MatchingStandardLicenses.java index 272d95b..58a097c 100644 --- a/src/main/java/org/spdx/tools/MatchingStandardLicenses.java +++ b/src/main/java/org/spdx/tools/MatchingStandardLicenses.java @@ -31,6 +31,13 @@ * Tool to compare a license text to standard licenses. Lists all standard * license ID's that are equivalent using the SPDX Legal team's license matching * guidelines (http://spdx.org/spdx-license-list/matching-guidelines) + *
+ * Exit codes: + * * @author Gary O'Neall */ public class MatchingStandardLicenses { @@ -44,32 +51,49 @@ private MatchingStandardLicenses() { static int MIN_ARGS = 1; static int MAX_ARGS = 1; - static final int ERROR_STATUS = 1; + /** + * Main entry point for the MatchingStandardLicenses tool. + * 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 MatchingStandardLicenses command logic and reports results to + * standard out. + * @param args + * @return process exit status, see {@link ExitCode} + */ + static int run(String[] args) { if (args == null || args.length < MIN_ARGS || args.length > MAX_ARGS) { System.out.println("Invalid arguments"); usage(); - System.exit(ERROR_STATUS); + return ExitCode.USAGE_ERROR; } - @SuppressWarnings("null") - File textFile = new File(args[0]); + String textFilePath = args[0]; + if (textFilePath == null) { + System.out.println("Invalid arguments"); + usage(); + return ExitCode.USAGE_ERROR; + } + File textFile = new File(textFilePath); if (!textFile.exists()) { System.out.println("Text file "+textFile.getName()+" does not exist"); usage(); - System.exit(ERROR_STATUS); + return ExitCode.ERROR; } - + SpdxToolsHelper.initialize(); String licenseText = null; try { licenseText = readAll(textFile); } catch (IOException e) { System.out.println("Error reading file: "+e.getMessage()); - System.exit(ERROR_STATUS); + return ExitCode.ERROR; } String[] matchingLicenseIds = null; @@ -77,10 +101,10 @@ public static void main(String[] args) { matchingLicenseIds = LicenseCompareHelper.matchingStandardLicenseIds(licenseText); } catch (InvalidSPDXAnalysisException e) { System.out.println("Error reading standard licenses: "+e.getMessage()); - System.exit(ERROR_STATUS); + return ExitCode.ERROR; } catch (SpdxCompareException e) { System.out.println("Error comparing licenses: "+e.getMessage()); - System.exit(ERROR_STATUS); + return ExitCode.ERROR; } if (matchingLicenseIds == null || matchingLicenseIds.length == 0) { @@ -94,7 +118,7 @@ public static void main(String[] args) { } System.out.println(sb.toString()); } - System.exit(0); + return ExitCode.SUCCESS; } /**