|
44 | 44 | * where output.xls is a file name for the output spreadsheet file |
45 | 45 | * and docX are SPDX document files to compare or directories containing SPDX documents. |
46 | 46 | * Document files can be either in RDF/XML or tag/value format |
| 47 | + * <br/> |
| 48 | + * Exit codes: |
| 49 | + * <ul> |
| 50 | + * <li>0 - the documents were compared and the output spreadsheet was written</li> |
| 51 | + * <li>1 - the comparison failed, or the output spreadsheet could not be written</li> |
| 52 | + * <li>2 - the command was invoked incorrectly (missing/invalid arguments)</li> |
| 53 | + * </ul> |
47 | 54 | * |
48 | 55 | * @author Gary O'Neall |
49 | 56 | */ |
50 | 57 | public class CompareSpdxDocs { |
51 | 58 | static final int MIN_ARGS = 2; |
52 | 59 | static final int MAX_ARGS = MultiDocumentSpreadsheet.MAX_DOCUMENTS + 1; |
53 | | - static final int ERROR_STATUS = 1; |
54 | | - static final Logger logger = LoggerFactory.getLogger(CompareSpdxDocs.class); |
55 | 60 |
|
| 61 | + static final Logger logger = LoggerFactory.getLogger(CompareSpdxDocs.class); |
56 | 62 |
|
57 | 63 | /** |
| 64 | + * Main entry point for the CompareSpdxDocs tool. |
| 65 | + * Delegates to {@link #run(String[])} and terminates the JVM with its exit status. |
| 66 | + * |
58 | 67 | * @param args args[0] is the output Excel file name, all other args are SPDX document file names |
59 | 68 | */ |
60 | 69 | public static void main(String[] args) { |
| 70 | + System.exit(run(args)); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Runs the CompareSpdxDocs command logic and reports results to standard |
| 75 | + * out, without terminating the JVM - allows the logic to be unit tested. |
| 76 | + * |
| 77 | + * @param args args[0] is the output Excel file name, all other args are SPDX document file names |
| 78 | + * @return process exit status, see {@link ExitCode} |
| 79 | + */ |
| 80 | + static int run(String[] args) { |
61 | 81 | if (args.length < MIN_ARGS) { |
62 | 82 | System.out.println("Insufficient arguments"); |
63 | 83 | usage(); |
64 | | - System.exit(ERROR_STATUS); |
| 84 | + return ExitCode.USAGE_ERROR; |
65 | 85 | } |
66 | 86 | if (args.length > MAX_ARGS) { |
67 | 87 | System.out.println("Too many SPDX documents specified. Must be less than "+String.valueOf(MAX_ARGS-1)+" document filenames"); |
68 | 88 | usage(); |
69 | | - System.exit(ERROR_STATUS); |
| 89 | + return ExitCode.USAGE_ERROR; |
70 | 90 | } |
71 | 91 | SpdxToolsHelper.initialize(); |
72 | 92 | try { |
73 | 93 | onlineFunction(args); |
74 | 94 | } catch (OnlineToolException e){ |
75 | 95 | System.out.println(e.getMessage()); |
76 | | - System.exit(ERROR_STATUS); |
| 96 | + return ExitCode.ERROR; |
77 | 97 | } |
| 98 | + return ExitCode.SUCCESS; |
78 | 99 | } |
79 | 100 |
|
80 | 101 | /** |
|
0 commit comments