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
26 changes: 22 additions & 4 deletions src/main/java/org/spdx/tools/GenerateVerificationCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@

/**
* Generates a verification code for a specific directory
* <br/>
* Exit codes:
* <ul>
* <li>0 - the verification code was generated successfully</li>
* <li>1 - the verification code could not be generated</li>
* <li>2 - the command was invoked incorrectly (missing/invalid arguments)</li>
* </ul>
* @author Gary O'Neall
*/
public class GenerateVerificationCode {
Expand All @@ -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;
Expand All @@ -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);
Expand Down
Loading