diff --git a/.gitignore b/.gitignore
index 5f18d50..ceb4641 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,3 +18,4 @@ buildNumber.properties
# IntelliJ IDE
.idea
+.DS_Store
diff --git a/README.md b/README.md
index 86186c7..a004a28 100644
--- a/README.md
+++ b/README.md
@@ -45,6 +45,7 @@ The following converter tools support SPDX format:
* Tag
* RDF/XML
+* ODS Spreadsheet
* XLSX Spreadsheet
* XLS Spreadsheet
* JSON
diff --git a/src/main/java/org/spdx/tools/SpdxConverter.java b/src/main/java/org/spdx/tools/SpdxConverter.java
index b1876c9..6454d37 100644
--- a/src/main/java/org/spdx/tools/SpdxConverter.java
+++ b/src/main/java/org/spdx/tools/SpdxConverter.java
@@ -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 covert(...) methods can be called programmatically to convert files
@@ -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");
}
diff --git a/src/main/java/org/spdx/tools/SpdxToolsHelper.java b/src/main/java/org/spdx/tools/SpdxToolsHelper.java
index 59ab84e..50d7529 100644
--- a/src/main/java/org/spdx/tools/SpdxToolsHelper.java
+++ b/src/main/java/org/spdx/tools/SpdxToolsHelper.java
@@ -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";
@@ -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);
@@ -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);
diff --git a/src/main/java/org/spdx/tools/SpdxViewer.java b/src/main/java/org/spdx/tools/SpdxViewer.java
index 5316c4e..609cdb6 100644
--- a/src/main/java/org/spdx/tools/SpdxViewer.java
+++ b/src/main/java/org/spdx/tools/SpdxViewer.java
@@ -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));
@@ -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;
}
diff --git a/src/main/java/org/spdx/tools/Verify.java b/src/main/java/org/spdx/tools/Verify.java
index 64056b7..dbfe847 100644
--- a/src/main/java/org/spdx/tools/Verify.java
+++ b/src/main/java/org/spdx/tools/Verify.java
@@ -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));
@@ -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) {
@@ -259,7 +259,7 @@ public static List 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");
}
}
diff --git a/src/test/java/org/spdx/tools/SpdxConverterTestV2.java b/src/test/java/org/spdx/tools/SpdxConverterTestV2.java
index ce8402c..6ae0a8b 100644
--- a/src/test/java/org/spdx/tools/SpdxConverterTestV2.java
+++ b/src/test/java/org/spdx/tools/SpdxConverterTestV2.java
@@ -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";
@@ -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";
@@ -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";
@@ -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";
diff --git a/src/test/java/org/spdx/tools/VerifyTest.java b/src/test/java/org/spdx/tools/VerifyTest.java
index f2d03fe..8e33fc4 100644
--- a/src/test/java/org/spdx/tools/VerifyTest.java
+++ b/src/test/java/org/spdx/tools/VerifyTest.java
@@ -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";
@@ -66,6 +67,8 @@ public void testVerifyRDFFile() throws SpdxVerificationException {
public void testVerify() throws SpdxVerificationException {
List 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);
diff --git a/testResources/SPDXSpreadsheetExample-v2.3.ods b/testResources/SPDXSpreadsheetExample-v2.3.ods
new file mode 100644
index 0000000..4b5280c
Binary files /dev/null and b/testResources/SPDXSpreadsheetExample-v2.3.ods differ