Skip to content

Commit

Permalink
Merge pull request #33 from spdx/downloadwarning
Browse files Browse the repository at this point in the history
Support for cpe data and more lenient download location
  • Loading branch information
goneall authored Sep 18, 2023
2 parents 08ec34f + 2f52756 commit eef430c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/main/java/org/spdx/cdx2spdx/CycloneSpdxConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,13 @@ private void addPackageProperties(SpdxPackage spdxPackage,
purl, null);
spdxPackage.addExternalRef(purlRef);
}
String cpe = component.getCpe();
if (Objects.nonNull(cpe) && !cpe.isBlank()) {
ExternalRef cpeRef = spdxPackage.createExternalRef(ReferenceCategory.SECURITY,
ListedReferenceTypes.getListedReferenceTypes().getListedReferenceTypeByName("cpe23Type"),
cpe, null);
spdxPackage.addExternalRef(cpeRef);
}
Evidence evidence = component.getEvidence();
if (Objects.nonNull(evidence)) {
List<Copyright> copyrights = evidence.getCopyright();
Expand Down Expand Up @@ -948,7 +955,7 @@ private static void copyExternalReferences(List<ExternalReference> externalRefer
for (ExternalReference externalRef:externalReferences) {
ExternalReference.Type type = externalRef.getType();
String url = externalRef.getUrl();
if (Objects.isNull(url) || Objects.isNull(type)) {
if (Objects.isNull(url) || url.isBlank() || Objects.isNull(type)) {
warnings.add("Skipping empty externalReference");
continue;
}
Expand Down Expand Up @@ -1018,8 +1025,13 @@ private static void copyExternalReferences(List<ExternalReference> externalRefer
new ReferenceType("http://cyclonedx.org/referenctype/support"), url, comment));
break;
case DISTRIBUTION:
spdxPackage.setDownloadLocation(url);
break;
try {
spdxPackage.setDownloadLocation(url);
}
catch (InvalidSPDXAnalysisException e) {
warnings.add("downloadLocation cannot be set a non-url value found in 'externalReference' of type 'distribution': " + url);
}
break;
case LICENSE:
spdxPackage.addExternalRef(spdxPackage.createExternalRef(ReferenceCategory.OTHER,
new ReferenceType("http://cyclonedx.org/referenctype/license"), url, comment));
Expand Down

0 comments on commit eef430c

Please sign in to comment.