Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions src/main/java/org/spdx/tools/SpdxConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@ public static void main(String[] args) {

/**
* Runs the SpdxConverter command logic and reports results to standard
* out/error, without terminating the JVM - allows the logic to be unit tested.
* out/error.
* @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();
Expand Down Expand Up @@ -131,7 +130,7 @@ static int run(String[] args) {
}
return ExitCode.SUCCESS;
}

/**
* Convert an SPDX file from the fromFilePath to a new file at the toFilePath using the file extensions to determine the serialization type
* @param fromFilePath Path of the file to convert from
Expand Down
32 changes: 26 additions & 6 deletions src/main/java/org/spdx/tools/SpdxViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
* Simple pretty printer for SPDX RDF XML files. Writes output to System.out.
* Usage: PrettyPrinter SPDXRdfXMLFile > textFile where SPDXRdfXMLFile is a
* valid SPDX RDF XML file
* <br/>
* Exit codes:
* <ul>
* <li>0 - the document was pretty-printed successfully</li>
* <li>1 - the document could not be read, parsed, or printed</li>
* <li>2 - the command was invoked incorrectly (missing/invalid arguments)</li>
* </ul>
*
* @author Gary O'Neall
* @version 0.1
Expand All @@ -42,21 +49,32 @@ public class SpdxViewer {

static final int MIN_ARGS = 1;
static final int MAX_ARGS = 2;
static final int ERROR_STATUS = 1;

/**
* Pretty Printer for an SPDX Document
*
* Main entry point for the SpdxViewer tool.
* Delegates to {@link #run(String[])} and terminates the JVM with its exit status.
* @param args args[0] SPDX file path; args[1] [RDFXML|JSON|XLS|XLSX|YAML|TAG] an optional file type - if not present, file type of the to file will be used
*/
public static void main(String[] args) {
System.exit(run(args));
}

/**
* Runs the SpdxViewer command logic and reports results to standard
* out/error.
* @param args args[0] SPDX file path; args[1] [RDFXML|JSON|XLS|XLSX|YAML|TAG] an optional file type - if not present, file type of the to file will be used
* @return process exit status, see {@link ExitCode}
*/
static int run(String[] args) {
if (args.length < MIN_ARGS) {
System.err
.println("Usage:\n SPDXViewer file [RDFXML|JSON|XLS|XLSX|YAML|TAG] \n"
+ "where file is the file path to a valid SPDX file\n"
+ "and [RDFXML|JSON|XLS|XLSX|YAML|TAG|JSONLD] is an optional file type\n"
+ "if not present, file type of the to file will be used");
return;
return ExitCode.USAGE_ERROR;
}
if (args.length > MAX_ARGS) {
System.out.printf("Warning: Extra arguments will be ignored");
Expand All @@ -79,7 +97,7 @@ public static void main(String[] args) {
fileType = SpdxToolsHelper.strToFileType(args[1]);
} catch (Exception ex) {
System.err.println("Invalid file type: "+args[1]);
System.exit(ERROR_STATUS);
return ExitCode.USAGE_ERROR;
}
} else {
fileType = SpdxToolsHelper.fileToFileType(file);
Expand All @@ -89,13 +107,13 @@ public static void main(String[] args) {
} catch (InvalidSPDXAnalysisException e) {
throw new SpdxVerificationException("Error converting fileType to store",e);
}

try {
doc = SpdxToolsHelper.readDocumentFromFileCompatV2(store, file);
} catch (Exception ex) {
System.out
.print("Error creating SPDX Document: " + ex.getMessage());
return;
return ExitCode.ERROR;
}
writer = new PrintWriter(System.out);
List<String> verify = doc.verify();
Expand All @@ -113,10 +131,11 @@ public static void main(String[] args) {
} catch (InvalidSPDXAnalysisException e) {
System.out.print("Error pretty printing SPDX Document: "
+ e.getMessage());
return;
return ExitCode.ERROR;
} catch (Exception e) {
System.out.print("Unexpected error displaying SPDX Document: "
+ e.getMessage());
return ExitCode.ERROR;
} finally {
if (Objects.nonNull(writer)) {
writer.close();
Expand All @@ -129,5 +148,6 @@ public static void main(String[] args) {
}
}
}
return ExitCode.SUCCESS;
}
}
Loading