Skip to content

Commit

Permalink
Merge pull request #30 from spdx/v3
Browse files Browse the repository at this point in the history
Updates to support SPDX Spec version 3
  • Loading branch information
goneall authored Sep 5, 2024
2 parents b0469bb + 96f9e71 commit f88ee72
Show file tree
Hide file tree
Showing 33 changed files with 542 additions and 770 deletions.
Binary file modified TestFiles/SPDXSpreadsheetExample-2.0.xls
Binary file not shown.
Binary file modified TestFiles/SPDXSpreadsheetExample-2.0.xlsx
Binary file not shown.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.spdx</groupId>
<artifactId>spdx-spreadsheet-store</artifactId>
<version>1.1.8-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>spdx-spreadsheet-store</name>
Expand Down Expand Up @@ -139,7 +139,7 @@
<dependency>
<groupId>org.spdx</groupId>
<artifactId>java-spdx-library</artifactId>
<version>1.1.11</version>
<version>2.0.0-Alpha</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/spdx/spreadsheetstore/AbstractSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.spdx.library.InvalidSPDXAnalysisException;
import org.spdx.core.InvalidSPDXAnalysisException;
import org.spdx.library.ModelCopyManager;
import org.spdx.library.model.Checksum;
import org.spdx.library.model.enumerations.ChecksumAlgorithm;
import org.spdx.library.model.license.AnyLicenseInfo;
import org.spdx.library.model.v2.Checksum;
import org.spdx.library.model.v2.enumerations.ChecksumAlgorithm;
import org.spdx.library.model.v2.license.AnyLicenseInfo;
import org.spdx.storage.IModelStore;

import com.opencsv.CSVParser;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/spdx/spreadsheetstore/AnnotationsSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.spdx.library.InvalidSPDXAnalysisException;
import org.spdx.core.InvalidSPDXAnalysisException;
import org.spdx.library.ModelCopyManager;
import org.spdx.library.SpdxConstants;
import org.spdx.library.model.Annotation;
import org.spdx.library.model.enumerations.AnnotationType;
import org.spdx.library.model.v2.Annotation;
import org.spdx.library.model.v2.SpdxConstantsCompatV2;
import org.spdx.library.model.v2.enumerations.AnnotationType;
import org.spdx.storage.IModelStore;
import org.spdx.storage.IModelStore.IdType;

Expand Down Expand Up @@ -57,7 +57,7 @@ public class AnnotationsSheet extends AbstractSheet {

static final boolean[] REQUIRED = new boolean[] {true, true, true, true, true, false};

final SimpleDateFormat dateFormat = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT);
final SimpleDateFormat dateFormat = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT);


/**
Expand Down Expand Up @@ -230,7 +230,7 @@ public Annotation getAnnotation(int rowNum) throws SpreadsheetException {
}
try {
Annotation retval = new Annotation(modelStore, documentUri,
modelStore.getNextId(IdType.Anonymous, documentUri), copyManager, true);
modelStore.getNextId(IdType.Anonymous), copyManager, true);
retval.setAnnotationDate(date);
retval.setAnnotationType(type);
retval.setAnnotator(annotator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Workbook;
import org.spdx.library.ModelCopyManager;
import org.spdx.library.model.ExternalDocumentRef;
import org.spdx.library.model.SpdxDocument;
import org.spdx.library.model.v2.ExternalDocumentRef;
import org.spdx.library.model.v2.SpdxDocument;
import org.spdx.storage.IModelStore;

/**
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/org/spdx/spreadsheetstore/DocumentInfoSheetV2d0.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.spdx.library.InvalidSPDXAnalysisException;
import org.spdx.core.InvalidSPDXAnalysisException;
import org.spdx.library.ModelCopyManager;
import org.spdx.library.SpdxConstants;
import org.spdx.library.model.Checksum;
import org.spdx.library.model.ExternalDocumentRef;
import org.spdx.library.model.SpdxCreatorInformation;
import org.spdx.library.model.SpdxDocument;
import org.spdx.library.model.SpdxElement;
import org.spdx.library.model.enumerations.ChecksumAlgorithm;
import org.spdx.library.model.license.AnyLicenseInfo;
import org.spdx.library.model.license.SimpleLicensingInfo;
import org.spdx.library.model.v2.Checksum;
import org.spdx.library.model.v2.ExternalDocumentRef;
import org.spdx.library.model.v2.SpdxConstantsCompatV2;
import org.spdx.library.model.v2.SpdxCreatorInformation;
import org.spdx.library.model.v2.SpdxDocument;
import org.spdx.library.model.v2.SpdxElement;
import org.spdx.library.model.v2.enumerations.ChecksumAlgorithm;
import org.spdx.library.model.v2.license.AnyLicenseInfo;
import org.spdx.library.model.v2.license.SimpleLicensingInfo;
import org.spdx.storage.IModelStore;

/**
Expand Down Expand Up @@ -381,7 +381,7 @@ public void addDocument(SpdxDocument doc) throws SpreadsheetException {
if (created == null) {
throw(new SpreadsheetException("Missing created date"));
}
DateFormat dateFormat = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT);
DateFormat dateFormat = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT);
try {
setCreated(dateFormat.parse(created));
} catch (ParseException e) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/spdx/spreadsheetstore/ExternalRefsSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
import org.apache.poi.ss.usermodel.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spdx.library.InvalidSPDXAnalysisException;
import org.spdx.core.InvalidSPDXAnalysisException;
import org.spdx.library.ModelCopyManager;
import org.spdx.library.model.ExternalRef;
import org.spdx.library.model.ReferenceType;
import org.spdx.library.model.enumerations.ReferenceCategory;
import org.spdx.library.model.v2.ExternalRef;
import org.spdx.library.model.v2.ReferenceType;
import org.spdx.library.model.v2.enumerations.ReferenceCategory;
import org.spdx.library.referencetype.ListedReferenceTypes;
import org.spdx.storage.IModelStore;
import org.spdx.storage.IModelStore.IdType;
Expand Down Expand Up @@ -249,7 +249,7 @@ public List<ExternalRef> getExternalRefsForPkgid(String id) throws SpreadsheetEx
try {
if (Objects.nonNull(pkgIdCell) && id.equals(pkgIdCell.getStringCellValue())) {
ExternalRef er = new ExternalRef(modelStore, documentUri,
modelStore.getNextId(IdType.Anonymous, documentUri), copyManager, true);
modelStore.getNextId(IdType.Anonymous), copyManager, true);

Cell refCategoryCell = row.getCell(REF_CATEGORY_COL);
if (refCategoryCell != null) {
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/org/spdx/spreadsheetstore/PackageInfoSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
import java.util.List;

import org.apache.poi.ss.usermodel.Workbook;
import org.spdx.library.InvalidSPDXAnalysisException;
import org.spdx.core.DefaultStoreNotInitialized;
import org.spdx.core.InvalidSPDXAnalysisException;
import org.spdx.library.ModelCopyManager;
import org.spdx.library.model.SpdxPackage;
import org.spdx.library.model.v2.SpdxPackage;
import org.spdx.storage.IModelStore;

/**
Expand Down Expand Up @@ -79,8 +80,9 @@ public static PackageInfoSheet openVersion(Workbook workbook,
/**
* @return
* @throws SpreadsheetException
* @throws DefaultStoreNotInitialized
*/
public abstract List<SpdxPackage> getPackages() throws SpreadsheetException;
public abstract List<SpdxPackage> getPackages() throws SpreadsheetException, DefaultStoreNotInitialized;

/**
* @param pkgInfo
Expand Down
38 changes: 20 additions & 18 deletions src/main/java/org/spdx/spreadsheetstore/PackageInfoSheetV2d0.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.spdx.library.InvalidSPDXAnalysisException;
import org.spdx.core.DefaultStoreNotInitialized;
import org.spdx.core.InvalidSPDXAnalysisException;
import org.spdx.library.LicenseInfoFactory;
import org.spdx.library.ModelCopyManager;
import org.spdx.library.SpdxVerificationHelper;
import org.spdx.library.model.Checksum;
import org.spdx.library.model.SpdxPackage;
import org.spdx.library.model.SpdxPackage.SpdxPackageBuilder;
import org.spdx.library.model.SpdxPackageVerificationCode;
import org.spdx.library.model.license.AnyLicenseInfo;
import org.spdx.library.model.license.InvalidLicenseStringException;
import org.spdx.library.model.license.LicenseInfoFactory;
import org.spdx.library.model.license.SpdxNoneLicense;
import org.spdx.library.model.v2.Checksum;
import org.spdx.library.model.v2.SpdxPackage;
import org.spdx.library.model.v2.SpdxPackage.SpdxPackageBuilder;
import org.spdx.library.model.v2.SpdxPackageVerificationCode;
import org.spdx.library.model.v2.SpdxVerificationHelper;
import org.spdx.library.model.v2.license.AnyLicenseInfo;
import org.spdx.library.model.v2.license.InvalidLicenseStringException;
import org.spdx.library.model.v2.license.SpdxNoneLicense;
import org.spdx.storage.IModelStore;
import org.spdx.storage.IModelStore.IdType;

Expand Down Expand Up @@ -150,7 +151,7 @@ private String validateRow(Row row) {
} else {
if (i == DECLARED_LICENSE_COL || i == CONCLUDED_LICENSE_COL) {
try {
LicenseInfoFactory.parseSPDXLicenseString(cell.getStringCellValue(), modelStore, documentUri, copyManager);
LicenseInfoFactory.parseSPDXLicenseStringCompatV2(cell.getStringCellValue(), modelStore, documentUri, copyManager);
} catch(InvalidSPDXAnalysisException ex) {
if (i == DECLARED_LICENSE_COL) {
return "Invalid declared license in row "+String.valueOf(row.getRowNum())+" detail: "+ex.getMessage() + " in PackageInfo sheet.";
Expand All @@ -165,7 +166,7 @@ private String validateRow(Row row) {
}
for (int j = 0; j < licenses.length; j++) {
try {
LicenseInfoFactory.parseSPDXLicenseString(licenses[j], modelStore, documentUri, copyManager);
LicenseInfoFactory.parseSPDXLicenseStringCompatV2(licenses[j], modelStore, documentUri, copyManager);
} catch(InvalidSPDXAnalysisException ex) {
return "Invalid license information in in files for license "+licenses[j]+ " row "+String.valueOf(row.getRowNum())+" detail: "+ex.getMessage() + " in PackageInfo sheet.";
}
Expand Down Expand Up @@ -317,7 +318,7 @@ public void add(SpdxPackage pkgInfo) throws InvalidSPDXAnalysisException {
/* (non-Javadoc)
* @see org.spdx.spreadsheetstore.PackageInfoSheet#getPackages()
*/
public List<SpdxPackage> getPackages() throws SpreadsheetException {
public List<SpdxPackage> getPackages() throws SpreadsheetException, DefaultStoreNotInitialized {
List<SpdxPackage> retval = new ArrayList<>();
for (int i = 0; i < getNumDataRows(); i++) {
retval.add(getPackage(getFirstDataRow() + i));
Expand All @@ -329,8 +330,9 @@ public List<SpdxPackage> getPackages() throws SpreadsheetException {
* @param rowNum
* @return SPDX package at the row rowNum, null if there is no package at that row
* @throws SpreadsheetException
* @throws DefaultStoreNotInitialized
*/
private SpdxPackage getPackage(int rowNum) throws SpreadsheetException {
private SpdxPackage getPackage(int rowNum) throws SpreadsheetException, DefaultStoreNotInitialized {
Row row = sheet.getRow(rowNum);
if (row == null) {
return null;
Expand All @@ -351,7 +353,7 @@ private SpdxPackage getPackage(int rowNum) throws SpreadsheetException {
Cell concludedLicensesCell = row.getCell(CONCLUDED_LICENSE_COL);
if (concludedLicensesCell != null && !concludedLicensesCell.getStringCellValue().isEmpty()) {
try {
concludedLicense = LicenseInfoFactory.parseSPDXLicenseString(concludedLicensesCell.getStringCellValue(), modelStore, documentUri, copyManager);
concludedLicense = LicenseInfoFactory.parseSPDXLicenseStringCompatV2(concludedLicensesCell.getStringCellValue(), modelStore, documentUri, copyManager);
} catch (InvalidLicenseStringException e) {
throw new SpreadsheetException("Invalid concluded license file for package "+declaredName, e);
}
Expand All @@ -367,7 +369,7 @@ private SpdxPackage getPackage(int rowNum) throws SpreadsheetException {

AnyLicenseInfo declaredLicenses;
try {
declaredLicenses = LicenseInfoFactory.parseSPDXLicenseString(row.getCell(DECLARED_LICENSE_COL).getStringCellValue(), modelStore, documentUri, copyManager);
declaredLicenses = LicenseInfoFactory.parseSPDXLicenseStringCompatV2(row.getCell(DECLARED_LICENSE_COL).getStringCellValue(), modelStore, documentUri, copyManager);
} catch (InvalidLicenseStringException e1) {
throw new SpreadsheetException("Invalid declared license for package "+declaredName, e1);
}
Expand Down Expand Up @@ -403,7 +405,7 @@ private SpdxPackage getPackage(int rowNum) throws SpreadsheetException {
Collection<AnyLicenseInfo> licenseInfosFromFiles = new ArrayList<>();
for (int i = 0; i < licenseStrings.length; i++) {
try {
licenseInfosFromFiles.add(LicenseInfoFactory.parseSPDXLicenseString(licenseStrings[i].trim(), modelStore, documentUri, copyManager));
licenseInfosFromFiles.add(LicenseInfoFactory.parseSPDXLicenseStringCompatV2(licenseStrings[i].trim(), modelStore, documentUri, copyManager));
} catch (InvalidLicenseStringException e) {
throw new SpreadsheetException("Invalid license infos from file for package "+declaredName, e);
}
Expand Down Expand Up @@ -447,7 +449,7 @@ private SpdxPackage getPackage(int rowNum) throws SpreadsheetException {
}
}
try {
SpdxPackageVerificationCode verificationCode = new SpdxPackageVerificationCode(modelStore, documentUri, modelStore.getNextId(IdType.Anonymous, documentUri), copyManager, true);
SpdxPackageVerificationCode verificationCode = new SpdxPackageVerificationCode(modelStore, documentUri, modelStore.getNextId(IdType.Anonymous), copyManager, true);
verificationCode.setValue(packageVerificationValue);
verificationCode.getExcludedFileNames().addAll(excludedFiles);
retval.setPackageVerificationCode(verificationCode);
Expand Down
38 changes: 20 additions & 18 deletions src/main/java/org/spdx/spreadsheetstore/PackageInfoSheetV2d1.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.spdx.library.InvalidSPDXAnalysisException;
import org.spdx.core.DefaultStoreNotInitialized;
import org.spdx.core.InvalidSPDXAnalysisException;
import org.spdx.library.LicenseInfoFactory;
import org.spdx.library.ModelCopyManager;
import org.spdx.library.SpdxVerificationHelper;
import org.spdx.library.model.Checksum;
import org.spdx.library.model.SpdxPackage;
import org.spdx.library.model.SpdxPackage.SpdxPackageBuilder;
import org.spdx.library.model.SpdxPackageVerificationCode;
import org.spdx.library.model.license.AnyLicenseInfo;
import org.spdx.library.model.license.InvalidLicenseStringException;
import org.spdx.library.model.license.LicenseInfoFactory;
import org.spdx.library.model.license.SpdxNoneLicense;
import org.spdx.library.model.v2.SpdxVerificationHelper;
import org.spdx.library.model.v2.Checksum;
import org.spdx.library.model.v2.SpdxPackage;
import org.spdx.library.model.v2.SpdxPackage.SpdxPackageBuilder;
import org.spdx.library.model.v2.SpdxPackageVerificationCode;
import org.spdx.library.model.v2.license.AnyLicenseInfo;
import org.spdx.library.model.v2.license.InvalidLicenseStringException;
import org.spdx.library.model.v2.license.SpdxNoneLicense;
import org.spdx.storage.IModelStore;
import org.spdx.storage.IModelStore.IdType;

Expand Down Expand Up @@ -152,7 +153,7 @@ private String validateRow(Row row) {
} else {
if (i == DECLARED_LICENSE_COL || i == CONCLUDED_LICENSE_COL) {
try {
LicenseInfoFactory.parseSPDXLicenseString(cell.getStringCellValue(), modelStore, documentUri, copyManager);
LicenseInfoFactory.parseSPDXLicenseStringCompatV2(cell.getStringCellValue(), modelStore, documentUri, copyManager);
} catch(InvalidSPDXAnalysisException ex) {
if (i == DECLARED_LICENSE_COL) {
return "Invalid declared license in row "+String.valueOf(row.getRowNum())+" detail: "+ex.getMessage() + " in PackageInfo sheet.";
Expand All @@ -167,7 +168,7 @@ private String validateRow(Row row) {
}
for (int j = 0; j < licenses.length; j++) {
try {
LicenseInfoFactory.parseSPDXLicenseString(licenses[j], modelStore, documentUri, copyManager);
LicenseInfoFactory.parseSPDXLicenseStringCompatV2(licenses[j], modelStore, documentUri, copyManager);
} catch(InvalidSPDXAnalysisException ex) {
return "Invalid license information in in files for license "+licenses[j]+ " row "+String.valueOf(row.getRowNum())+" detail: "+ex.getMessage() + " in PackageInfo sheet.";
}
Expand Down Expand Up @@ -335,7 +336,7 @@ public void add(SpdxPackage pkgInfo) throws InvalidSPDXAnalysisException {
/* (non-Javadoc)
* @see org.spdx.spreadsheetstore.PackageInfoSheet#getPackages()
*/
public List<SpdxPackage> getPackages() throws SpreadsheetException {
public List<SpdxPackage> getPackages() throws SpreadsheetException, DefaultStoreNotInitialized {
List<SpdxPackage> retval = new ArrayList<>();
for (int i = 0; i < getNumDataRows(); i++) {
retval.add(getPackage(getFirstDataRow() + i));
Expand All @@ -347,8 +348,9 @@ public List<SpdxPackage> getPackages() throws SpreadsheetException {
* @param rowNum
* @return SPDX package at the row rowNum, null if there is no package at that row
* @throws SpreadsheetException
* @throws DefaultStoreNotInitialized
*/
private SpdxPackage getPackage(int rowNum) throws SpreadsheetException {
private SpdxPackage getPackage(int rowNum) throws SpreadsheetException, DefaultStoreNotInitialized {
Row row = sheet.getRow(rowNum);
if (row == null) {
return null;
Expand All @@ -369,7 +371,7 @@ private SpdxPackage getPackage(int rowNum) throws SpreadsheetException {
Cell concludedLicensesCell = row.getCell(CONCLUDED_LICENSE_COL);
if (concludedLicensesCell != null && !concludedLicensesCell.getStringCellValue().isEmpty()) {
try {
concludedLicense = LicenseInfoFactory.parseSPDXLicenseString(concludedLicensesCell.getStringCellValue(), modelStore, documentUri, copyManager);
concludedLicense = LicenseInfoFactory.parseSPDXLicenseStringCompatV2(concludedLicensesCell.getStringCellValue(), modelStore, documentUri, copyManager);
} catch (InvalidLicenseStringException e) {
throw new SpreadsheetException("Invalid concluded license file for package "+declaredName, e);
}
Expand All @@ -385,7 +387,7 @@ private SpdxPackage getPackage(int rowNum) throws SpreadsheetException {

AnyLicenseInfo declaredLicenses;
try {
declaredLicenses = LicenseInfoFactory.parseSPDXLicenseString(row.getCell(DECLARED_LICENSE_COL).getStringCellValue(), modelStore, documentUri, copyManager);
declaredLicenses = LicenseInfoFactory.parseSPDXLicenseStringCompatV2(row.getCell(DECLARED_LICENSE_COL).getStringCellValue(), modelStore, documentUri, copyManager);
} catch (InvalidLicenseStringException e1) {
throw new SpreadsheetException("Invalid declared license for package "+declaredName, e1);
}
Expand Down Expand Up @@ -421,7 +423,7 @@ private SpdxPackage getPackage(int rowNum) throws SpreadsheetException {
Collection<AnyLicenseInfo> licenseInfosFromFiles = new ArrayList<>();
for (int i = 0; i < licenseStrings.length; i++) {
try {
licenseInfosFromFiles.add(LicenseInfoFactory.parseSPDXLicenseString(licenseStrings[i].trim(), modelStore, documentUri, copyManager));
licenseInfosFromFiles.add(LicenseInfoFactory.parseSPDXLicenseStringCompatV2(licenseStrings[i].trim(), modelStore, documentUri, copyManager));
} catch (InvalidLicenseStringException e) {
throw new SpreadsheetException("Invalid license infos from file for package "+declaredName, e);
}
Expand Down Expand Up @@ -465,7 +467,7 @@ private SpdxPackage getPackage(int rowNum) throws SpreadsheetException {
}
}
try {
SpdxPackageVerificationCode verificationCode = new SpdxPackageVerificationCode(modelStore, documentUri, modelStore.getNextId(IdType.Anonymous, documentUri), copyManager, true);
SpdxPackageVerificationCode verificationCode = new SpdxPackageVerificationCode(modelStore, documentUri, modelStore.getNextId(IdType.Anonymous), copyManager, true);
verificationCode.setValue(packageVerificationValue);
verificationCode.getExcludedFileNames().addAll(excludedFiles);
retval.setPackageVerificationCode(verificationCode);
Expand Down
Loading

0 comments on commit f88ee72

Please sign in to comment.