Skip to content
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ buildNumber.properties

# IntelliJ IDE
.idea
.DS_Store
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ The following converter tools support SPDX format:

* Tag
* RDF/XML
* ODS Spreadsheet
* XLSX Spreadsheet
* XLS Spreadsheet
* JSON
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/spdx/tools/SpdxConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
* Converts between various SPDX file types
* arg[0] from file path
* arg[1] to file path
* arg[2] from file type [RDFXML|RDFTTL|JSON|XLS|XLSX|YAML|TAG] - if not present, file type of the from file will be used
* arg[3] to file type [RDFXML|RDFTTL|JSON|XLS|XLSX|YAML|TAG] - if not present, file type of the to file will be used
* arg[2] from file type [RDFXML|RDFTTL|JSON|ODS|XLS|XLSX|YAML|TAG] - if not present, file type of the from file will be used
* arg[3] to file type [RDFXML|RDFTTL|JSON|ODS|XLS|XLSX|YAML|TAG] - if not present, file type of the to file will be used
* 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
Expand Down Expand Up @@ -368,8 +368,8 @@ private static void usage() {
System.out.println("SpdxConverter fromFilePath toFilePath [fromFileType] [toFileType]");
System.out.println("\tfromFilePath - File path of the file to convert from");
System.out.println("\ttoFilePath - output file");
System.out.println("\t[fromFileType] - optional file type of the input file. One of JSON, XLS, XLSX, TAG, RDFXML, RDFTTL, YAML, XML or JSONLD. If not provided the file type will be determined by the file extension");
System.out.println("\t[toFileType] - optional file type of the output file. One of JSON, XLS, XLSX, TAG, RDFXML, RDFTTL, YAML, XML or JSONLD. If not provided the file type will be determined by the file extension");
System.out.println("\t[fromFileType] - optional file type of the input file. One of JSON, XLS, XLSX, ODS, TAG, RDFXML, RDFTTL, YAML, XML or JSONLD. If not provided the file type will be determined by the file extension");
System.out.println("\t[toFileType] - optional file type of the output file. One of JSON, XLS, XLSX, ODS, TAG, RDFXML, RDFTTL, YAML, XML or JSONLD. If not provided the file type will be determined by the file extension");
System.out.println("\t[excludeLicenseDetails] - If present, listed license and listed exception properties will not be included in the output file");
}

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/spdx/tools/SpdxToolsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class SpdxToolsHelper {
* Supported serialization file types
*/
public enum SerFileType {
JSON, RDFXML, XML, XLS, XLSX, YAML, TAG, RDFTTL, JSONLD
JSON, RDFXML, XML, ODS, XLS, XLSX, YAML, TAG, RDFTTL, JSONLD
}

static final String XML_INPUT_FACTORY_PROPERTY_KEY = "javax.xml.stream.XMLInputFactory";
Expand All @@ -77,6 +77,7 @@ public enum SerFileType {
temp.put("rdf.xml", SerFileType.RDFXML);
temp.put("rdf", SerFileType.RDFXML);
temp.put("xml", SerFileType.XML);
temp.put("ods", SerFileType.ODS);
temp.put("xls", SerFileType.XLS);
temp.put("xlsx", SerFileType.XLSX);
temp.put("yaml", SerFileType.YAML);
Expand Down Expand Up @@ -115,6 +116,9 @@ public static ISerializableModelStore fileTypeToStore(SerFileType fileType)
}
case TAG :
return new TagValueStore(new InMemSpdxStore());
case ODS :
return new SpreadsheetStore(new InMemSpdxStore(),
SpreadsheetFormatType.ODS);
case XLS :
return new SpreadsheetStore(new InMemSpdxStore(),
SpreadsheetFormatType.XLS);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/spdx/tools/SpdxViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class SpdxViewer {
*
* 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
* @param args args[0] SPDX file path; args[1] [RDFXML|JSON|ODS|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));
Expand All @@ -64,15 +64,15 @@ public static void main(String[] 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
* @param args args[0] SPDX file path; args[1] [RDFXML|JSON|ODS|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"
.println("Usage:\n SPDXViewer file [RDFXML|JSON|ODS|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"
+ "and [RDFXML|JSON|ODS|XLS|XLSX|YAML|TAG|JSONLD] is an optional file type\n"
+ "if not present, file type of the to file will be used");
return ExitCode.USAGE_ERROR;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/spdx/tools/Verify.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class Verify {
/**
* Main entry point for the Verify tool
*
* @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
* @param args args[0] SPDX file path; args[1] [RDFXML|JSON|ODS|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));
Expand All @@ -81,7 +81,7 @@ public static void main(String[] args) {
* Runs the Verify command logic and reports results to standard out/error,
* without terminating the JVM - allows the logic to be unit tested.
*
* @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
* @param args args[0] SPDX file path; args[1] [RDFXML|JSON|ODS|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) {
Expand Down Expand Up @@ -259,7 +259,7 @@ public static List<String> verifyRDFFile(String filePath) throws SpdxVerificatio
}

public void usage() {
System.out.println("Verify filepath [RDFXML|JSON|XLS|XLSX|YAML|TAG|JSONLD]");
System.out.println(" where filepath is a path to the SPDX file and [RDFXML|JSON|XLS|XLSX|YAML|TAG] is an optional file type - if not present, file type of the to file will be used");
System.out.println("Verify filepath [RDFXML|JSON|ODS|XLS|XLSX|YAML|TAG|JSONLD]");
System.out.println(" where filepath is a path to the SPDX file and [RDFXML|JSON|ODS|XLS|XLSX|YAML|TAG] is an optional file type - if not present, file type of the to file will be used");
}
}
53 changes: 52 additions & 1 deletion src/test/java/org/spdx/tools/SpdxConverterTestV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public class SpdxConverterTestV2 extends TestCase {
static final String TEST_JSON_FILE_PATH = TEST_DIR + File.separator + "SPDXJSONExample-v2.3.spdx.json";
static final String TEST_WITH_EXCEPTION_FILE_PATH = TEST_DIR + File.separator + "SPDXJSONExample-v2.3-with-exception.spdx.json";
static final String TEST_RDF_FILE_PATH = TEST_DIR + File.separator + "SPDXRdfExample-v2.3.spdx.rdf";
// Trailing empty rows removed from content.xml in the ODS spreadsheet,
// to avoid this bug https://github.com/spdx/spdx-java-spreadsheet-store/issues/109
static final String TEST_SPREADSHEET_ODS_FILE_PATH = TEST_DIR + File.separator + "SPDXSpreadsheetExample-v2.3.ods";
static final String TEST_SPREADSHEET_XLS_FILE_PATH = TEST_DIR + File.separator + "SPDXSpreadsheetExample-v2.3.xls";
static final String TEST_SPREADSHEET_XLSX_FILE_PATH = TEST_DIR + File.separator + "SPDXSpreadsheetExample-v2.3.xlsx";
static final String TEST_TAG_FILE_PATH = TEST_DIR + File.separator + "SPDXTagExample-v2.3.spdx";
Expand Down Expand Up @@ -103,7 +106,7 @@ public static void deleteDirAndFiles(Path dirOrFile) {
}
}

// Supported file types: JSON, XLS, XLSX, TAG, RDFXML, YAML or XML
// Supported file types: JSON, ODS, XLS, XLSX, TAG, RDFXML, YAML or XML

public void testXlsxToRDFXML() throws SpdxConverterException, InvalidSPDXAnalysisException, IOException, SpdxCompareException {
String outFileName = "result.rdf.xml";
Expand Down Expand Up @@ -224,6 +227,30 @@ public void testXlsToRDFXML() throws SpdxConverterException, InvalidSPDXAnalysis
comparer.compare(sourceDoc, resultDoc);
assertFalse(comparer.isDifferenceFound());
}

public void testOdsToRDFXML() throws SpdxConverterException, InvalidSPDXAnalysisException, IOException, SpdxCompareException {
String outFileName = "result.rdf.xml";
Path outFilePath = tempDirPath.resolve(outFileName);
SpdxConverter.convert(TEST_SPREADSHEET_ODS_FILE_PATH, outFilePath.toString(), SerFileType.ODS, SerFileType.RDFXML);
File result = new File(outFilePath.toString());
File source = new File(TEST_SPREADSHEET_ODS_FILE_PATH);
assertTrue(result.exists());
SpdxDocument sourceDoc = SpdxToolsHelper.deserializeDocumentCompatV2(source, SerFileType.ODS);
SpdxDocument resultDoc = SpdxToolsHelper.deserializeDocumentCompatV2(result, SerFileType.RDFXML);
SpdxComparer comparer = new SpdxComparer();
comparer.compare(sourceDoc, resultDoc);
assertFalse(comparer.isDifferenceFound());

// Try with no file types
Files.delete(outFilePath);
SpdxConverter.convert(TEST_SPREADSHEET_ODS_FILE_PATH, outFilePath.toString());
result = new File(outFilePath.toString());
assertTrue(result.exists());
resultDoc = SpdxToolsHelper.deserializeDocumentCompatV2(result, SerFileType.RDFXML);
comparer = new SpdxComparer();
comparer.compare(sourceDoc, resultDoc);
assertFalse(comparer.isDifferenceFound());
}

public void testJsonToXls() throws SpdxConverterException, InvalidSPDXAnalysisException, IOException, SpdxCompareException {
String xmlFileName = "result.rdf.xls";
Expand All @@ -248,6 +275,30 @@ public void testJsonToXls() throws SpdxConverterException, InvalidSPDXAnalysisEx
comparer.compare(sourceDoc, resultDoc);
assertFalse(comparer.isDifferenceFound());
}

public void testJsonToOds() throws SpdxConverterException, InvalidSPDXAnalysisException, IOException, SpdxCompareException {
String xmlFileName = "result.rdf.ods";
Path outFilePath = tempDirPath.resolve(xmlFileName);
SpdxConverter.convert(TEST_JSON_FILE_PATH, outFilePath.toString(), SerFileType.JSON, SerFileType.ODS);
File result = new File(outFilePath.toString());
File source = new File(TEST_JSON_FILE_PATH);
assertTrue(result.exists());
SpdxDocument sourceDoc = SpdxToolsHelper.deserializeDocumentCompatV2(source, SerFileType.JSON);
SpdxDocument resultDoc = SpdxToolsHelper.deserializeDocumentCompatV2(result, SerFileType.ODS);
SpdxComparer comparer = new SpdxComparer();
comparer.compare(sourceDoc, resultDoc);
assertFalse(comparer.isDifferenceFound());

// Try with no file types
Files.delete(outFilePath);
SpdxConverter.convert(TEST_JSON_FILE_PATH, outFilePath.toString());
result = new File(outFilePath.toString());
assertTrue(result.exists());
resultDoc = SpdxToolsHelper.deserializeDocumentCompatV2(result, SerFileType.ODS);
comparer = new SpdxComparer();
comparer.compare(sourceDoc, resultDoc);
assertFalse(comparer.isDifferenceFound());
}

public void testJsonToXlsx() throws SpdxConverterException, InvalidSPDXAnalysisException, IOException, SpdxCompareException {
String xmlFileName = "result.rdf.xlsx";
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/spdx/tools/VerifyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class VerifyTest extends TestCase {
static final String JSON_BAD_VERSION_FILE_PATH = TEST_DIR + File.separator + "SPDXJSONExample-wrongversion.spdx.json";
static final String TEST_V23_FIELDS_IN_V22_FILE = TEST_DIR + File.separator + "SPDXWrongVersion.spdx.json";
static final String TEST_RDF_FILE_PATH = TEST_DIR + File.separator + "SPDXRdfExample-v2.3.spdx.rdf";
static final String TEST_SPREADSHEET_ODS_FILE_PATH = TEST_DIR + File.separator + "SPDXSpreadsheetExample-v2.3.ods";
static final String TEST_SPREADSHEET_XLS_FILE_PATH = TEST_DIR + File.separator + "SPDXSpreadsheetExample-v2.3.xls";
static final String TEST_SPREADSHEET_XLSX_FILE_PATH = TEST_DIR + File.separator + "SPDXSpreadsheetExample-v2.3.xlsx";
static final String TEST_TAG_FILE_PATH = TEST_DIR + File.separator + "SPDXTagExample-v2.3.spdx";
Expand Down Expand Up @@ -66,6 +67,8 @@ public void testVerifyRDFFile() throws SpdxVerificationException {
public void testVerify() throws SpdxVerificationException {
List<String> result = Verify.verify(TEST_JSON_FILE_PATH, SerFileType.JSON);
assertEquals(0, result.size());
result = Verify.verify(TEST_SPREADSHEET_ODS_FILE_PATH, SerFileType.ODS);
assertEquals(0, result.size());
result = Verify.verify(TEST_SPREADSHEET_XLS_FILE_PATH, SerFileType.XLS);
assertEquals(0, result.size());
result = Verify.verify(TEST_SPREADSHEET_XLSX_FILE_PATH, SerFileType.XLSX);
Expand Down
Binary file added testResources/SPDXSpreadsheetExample-v2.3.ods
Binary file not shown.
Loading