Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions src/main/java/org/spdx/tools/SpdxConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,44 @@
* arg[4] excludeLicenseDetails If present, listed license and listed exception properties will not be included in the output file
*
* the <code>covert(...)</code> methods can be called programmatically to convert files
* <br/>
* Exit codes:
* <ul>
* <li>0 - the conversion succeeded</li>
* <li>1 - the conversion failed</li>
* <li>2 - the command was invoked incorrectly (missing/invalid arguments)</li>
* </ul>
* @author Gary O'Neall
*/
public class SpdxConverter {
static final Logger logger = LoggerFactory.getLogger(SpdxConverter.class);

static final int ERROR_STATUS = 1;


static final int MIN_ARGS = 2;
static final int MAX_ARGS = 5;

/**
* Main entry point for the SpdxConverter 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 SpdxConverter command logic and reports results to standard
* out/error, without terminating the JVM - allows the logic to be unit tested.
* @param args
* @return process exit status, see {@link ExitCode}
*/
static int run(String[] args) {
SpdxToolsHelper.initialize();
if (args.length < MIN_ARGS) {

System.err
.println("Invalid number of arguments");
usage();
System.exit(ERROR_STATUS);
return ExitCode.USAGE_ERROR;
}
if (args.length > MAX_ARGS) {
System.out.printf("Warning: Extra arguments will be ignored");
Expand All @@ -85,7 +101,7 @@ public static void main(String[] args) {
convert(args[0], args[1]);
} catch (SpdxConverterException e) {
System.err.println("Error converting: "+e.getMessage());
System.exit(ERROR_STATUS);
return ExitCode.ERROR;
}
} else {
SerFileType fromFileType = null;
Expand All @@ -95,7 +111,7 @@ public static void main(String[] args) {
System.err
.println("From file type is not a valid SPDX file type: "+args[2]);
usage();
System.exit(ERROR_STATUS);
return ExitCode.USAGE_ERROR;
}
SerFileType toFileType = null;
try {
Expand All @@ -104,15 +120,16 @@ public static void main(String[] args) {
System.err
.println("To file type is not a valid SPDX file type: "+args[3]);
usage();
System.exit(ERROR_STATUS);
return ExitCode.USAGE_ERROR;
}
try {
convert(args[0], args[1], fromFileType, toFileType, excludeLicenseDetails);
} catch (SpdxConverterException e) {
System.err.println("Error converting: "+e.getMessage());
System.exit(ERROR_STATUS);
return ExitCode.ERROR;
}
}
return ExitCode.SUCCESS;
}

/**
Expand Down
Loading