Skip to content

Commit 22faab9

Browse files
authored
Merge pull request spdx#301 from bact/exit-code-comparedocs
CompareDocs: Returns 1 if comparison failed; 2 if bad args
2 parents c5889ef + 201b6f4 commit 22faab9

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

src/main/java/org/spdx/tools/CompareSpdxDocs.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,37 +44,58 @@
4444
* where output.xls is a file name for the output spreadsheet file
4545
* and docX are SPDX document files to compare or directories containing SPDX documents.
4646
* 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>
4754
*
4855
* @author Gary O'Neall
4956
*/
5057
public class CompareSpdxDocs {
5158
static final int MIN_ARGS = 2;
5259
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);
5560

61+
static final Logger logger = LoggerFactory.getLogger(CompareSpdxDocs.class);
5662

5763
/**
64+
* Main entry point for the CompareSpdxDocs tool.
65+
* Delegates to {@link #run(String[])} and terminates the JVM with its exit status.
66+
*
5867
* @param args args[0] is the output Excel file name, all other args are SPDX document file names
5968
*/
6069
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) {
6181
if (args.length < MIN_ARGS) {
6282
System.out.println("Insufficient arguments");
6383
usage();
64-
System.exit(ERROR_STATUS);
84+
return ExitCode.USAGE_ERROR;
6585
}
6686
if (args.length > MAX_ARGS) {
6787
System.out.println("Too many SPDX documents specified. Must be less than "+String.valueOf(MAX_ARGS-1)+" document filenames");
6888
usage();
69-
System.exit(ERROR_STATUS);
89+
return ExitCode.USAGE_ERROR;
7090
}
7191
SpdxToolsHelper.initialize();
7292
try {
7393
onlineFunction(args);
7494
} catch (OnlineToolException e){
7595
System.out.println(e.getMessage());
76-
System.exit(ERROR_STATUS);
96+
return ExitCode.ERROR;
7797
}
98+
return ExitCode.SUCCESS;
7899
}
79100

80101
/**

0 commit comments

Comments
 (0)