Skip to content

Commit ef85a7e

Browse files
committed
Fix excessive warnings in license store
Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
1 parent c68e4c1 commit ef85a7e

File tree

2 files changed

+89
-56
lines changed

2 files changed

+89
-56
lines changed

src/main/java/org/spdx/library/conversion/Spdx2to3Converter.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,18 @@ public static Agent stringToAgent(String spdx2personOrgString, CreationInfo crea
413413
}
414414
}
415415

416+
/**
417+
* @param toModelStore modelStore to store any converted elements to
418+
* @param copyManager Copy manager to use for the conversion
419+
* @param defaultCreationInfo creationInfo to use for created SPDX elements
420+
* @param toSpecVersion specific spec version to convert to
421+
* @param defaultUriPrefix URI prefix to use when creating new elements
422+
*/
423+
public Spdx2to3Converter(IModelStore toModelStore, IModelCopyManager copyManager, CreationInfo defaultCreationInfo,
424+
String toSpecVersion, String defaultUriPrefix) {
425+
this(toModelStore, copyManager, defaultCreationInfo, toSpecVersion, defaultUriPrefix, true);
426+
}
427+
416428
/**
417429
* @param toModelStore modelStore to store any converted elements to
418430
* @param copyManager Copy manager to use for the conversion

src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java

Lines changed: 77 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ public void create(TypedValue typedValue) throws InvalidSPDXAnalysisException {
303303
*/
304304
@Override
305305
public List<PropertyDescriptor> getPropertyValueDescriptors(String objectUri) throws InvalidSPDXAnalysisException {
306+
if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
307+
return LicenseCreationInfo.ALL_PROPERTY_DESCRIPTORS;
308+
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
309+
return LicenseCreatorAgent.ALL_PROPERTY_DESCRIPTORS;
310+
}
306311
String id = objectUriToId(objectUri);
307312
listedLicenseModificationLock.readLock().lock();
308313
try {
@@ -316,10 +321,6 @@ public List<PropertyDescriptor> getPropertyValueDescriptors(String objectUri) th
316321
} else if (crossRefs.containsKey(id)) {
317322
return crossRefs.get(id).getPropertyValueDescriptors();
318323
// Currently, there is no SPDX 3 support for cross refs
319-
} else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
320-
return LicenseCreationInfo.ALL_PROPERTY_DESCRIPTORS;
321-
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
322-
return LicenseCreatorAgent.ALL_PROPERTY_DESCRIPTORS;
323324
} else {
324325
logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
325326
throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID. crossRef ID nor a listed exception ID");
@@ -477,6 +478,13 @@ private ExceptionJson fetchExceptionJson(String idCaseInsensitive) throws Invali
477478
*/
478479
@Override
479480
public void setValue(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException {
481+
if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
482+
logger.warn("Ignoring the setting of "+propertyDescriptor.getName()+" for license list creation info");
483+
return;
484+
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
485+
logger.warn("Ignoring the setting of "+propertyDescriptor.getName()+" for license list creator info");
486+
return;
487+
}
480488
String id = objectUriToId(objectUri);
481489
boolean isLicenseId = false;
482490
boolean isExceptionId = false;
@@ -501,10 +509,6 @@ public void setValue(String objectUri, PropertyDescriptor propertyDescriptor, Ob
501509
exc.setPrimativeValue(propertyDescriptor, value);
502510
} else if (Objects.nonNull(crossRef)) {
503511
crossRef.setPrimativeValue(propertyDescriptor, value);
504-
} else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
505-
logger.warn("Ignoring the setting of "+propertyDescriptor.getName()+" for license list creation info");
506-
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
507-
logger.warn("Ignoring the setting of "+propertyDescriptor.getName()+" for license list creator info");
508512
} else {
509513
logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
510514
throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
@@ -516,6 +520,13 @@ public void setValue(String objectUri, PropertyDescriptor propertyDescriptor, Ob
516520
*/
517521
@Override
518522
public void clearValueCollection(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException {
523+
if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
524+
logger.warn("Ignoring the clearing of collection for license list creation info");
525+
return;
526+
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
527+
logger.warn("Ignoring the clearing of collection for license list creator");
528+
return;
529+
}
519530
String id = objectUriToId(objectUri);
520531
boolean isLicenseId = false;
521532
boolean isExceptionId = false;
@@ -540,10 +551,6 @@ public void clearValueCollection(String objectUri, PropertyDescriptor propertyDe
540551
exc.clearPropertyValueList(propertyDescriptor);
541552
} else if (Objects.nonNull(crossRef)) {
542553
crossRef.clearPropertyValueList(propertyDescriptor);
543-
} else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
544-
logger.warn("Ignoring the clearing of collection for license list creation info");
545-
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
546-
logger.warn("Ignoring the clearing of collection for license list creator");
547554
} else {
548555
logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
549556
throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
@@ -555,6 +562,13 @@ public void clearValueCollection(String objectUri, PropertyDescriptor propertyDe
555562
*/
556563
@Override
557564
public boolean addValueToCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException {
565+
if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
566+
logger.warn("Ignoring the adding to collection for license list creation info");
567+
return false;
568+
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
569+
logger.warn("Ignoring the adding to collection for license list creator");
570+
return false;
571+
}
558572
String id = objectUriToId(objectUri);
559573
boolean isLicenseId = false;
560574
boolean isExceptionId = false;
@@ -597,12 +611,6 @@ public boolean addValueToCollection(String objectUri, PropertyDescriptor propert
597611
return exc.addPrimitiveValueToList(propertyDescriptor, value);
598612
} else if (Objects.nonNull(crossRef)) {
599613
return crossRef.addPrimitiveValueToList(propertyDescriptor, value);
600-
} else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
601-
logger.warn("Ignoring the adding to collection for license list creation info");
602-
return false;
603-
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
604-
logger.warn("Ignoring the adding to collection for license list creator");
605-
return false;
606614
} else {
607615
logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
608616
throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
@@ -612,6 +620,13 @@ public boolean addValueToCollection(String objectUri, PropertyDescriptor propert
612620
@Override
613621
public boolean removeValueFromCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value)
614622
throws InvalidSPDXAnalysisException {
623+
if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
624+
logger.warn("Ignoring the removing from collection for license list creation info");
625+
return false;
626+
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
627+
logger.warn("Ignoring the removing from collection for license list creator");
628+
return false;
629+
}
615630
String id = objectUriToId(objectUri);
616631
boolean isLicenseId = false;
617632
boolean isExceptionId = false;
@@ -654,12 +669,6 @@ public boolean removeValueFromCollection(String objectUri, PropertyDescriptor pr
654669
return exc.removePrimitiveValueToList(propertyDescriptor, value);
655670
} else if (Objects.nonNull(crossRef)) {
656671
return crossRef.removePrimitiveValueToList(propertyDescriptor, value);
657-
} else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
658-
logger.warn("Ignoring the removing from collection for license list creation info");
659-
return false;
660-
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
661-
logger.warn("Ignoring the removing from collection for license list creator");
662-
return false;
663672
} else {
664673
logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
665674
throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
@@ -672,6 +681,11 @@ public boolean removeValueFromCollection(String objectUri, PropertyDescriptor pr
672681
@SuppressWarnings("unchecked")
673682
@Override
674683
public Iterator<Object> listValues(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException {
684+
if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
685+
return ((List<Object>)(List<?>)licenseCreationInfo.getValueList(propertyDescriptor)).iterator();
686+
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
687+
return ((List<Object>)(List<?>)licenseCreator.getValueList(propertyDescriptor)).iterator();
688+
}
675689
String id = objectUriToId(objectUri);
676690
boolean isLicenseId = false;
677691
boolean isExceptionId = false;
@@ -743,10 +757,6 @@ public Object next() {
743757
return ((List<Object>)(List<?>)exc.getValueList(propertyDescriptor)).iterator();
744758
} else if (Objects.nonNull(crossRef)) {
745759
return ((List<Object>)(List<?>)crossRef.getValueList(propertyDescriptor)).iterator();
746-
} else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
747-
return ((List<Object>)(List<?>)licenseCreationInfo.getValueList(propertyDescriptor)).iterator();
748-
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
749-
return ((List<Object>)(List<?>)licenseCreator.getValueList(propertyDescriptor)).iterator();
750760
} else {
751761
logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
752762
throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
@@ -758,6 +768,11 @@ public Object next() {
758768
*/
759769
@Override
760770
public Optional<Object> getValue(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException {
771+
if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
772+
return Optional.ofNullable(licenseCreationInfo.getValue(propertyDescriptor));
773+
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
774+
return Optional.ofNullable(licenseCreator.getValue(propertyDescriptor));
775+
}
761776
String id = objectUriToId(objectUri);
762777
boolean isLicenseId = false;
763778
boolean isExceptionId = false;
@@ -784,10 +799,6 @@ public Optional<Object> getValue(String objectUri, PropertyDescriptor propertyDe
784799
return Optional.ofNullable(exc.getValue(propertyDescriptor));
785800
} else if (Objects.nonNull(crossRef)) {
786801
return Optional.ofNullable(crossRef.getValue(propertyDescriptor));
787-
} else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
788-
return Optional.ofNullable(licenseCreationInfo.getValue(propertyDescriptor));
789-
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
790-
return Optional.ofNullable(licenseCreator.getValue(propertyDescriptor));
791802
} else {
792803
logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
793804
throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
@@ -914,6 +925,13 @@ public Optional<TypedValue> getTypedValue(String objectUri) throws InvalidSPDXAn
914925

915926
@Override
916927
public void removeProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException {
928+
if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
929+
logger.warn("Ignoring remove property "+propertyDescriptor.getName()+" for license list creation info");
930+
return;
931+
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
932+
logger.warn("Ignoring remove property "+propertyDescriptor.getName()+" for license list creator");
933+
return;
934+
}
917935
String id = objectUriToId(objectUri);
918936
boolean isLicenseId = false;
919937
boolean isExceptionId = false;
@@ -938,10 +956,6 @@ public void removeProperty(String objectUri, PropertyDescriptor propertyDescript
938956
exc.removeProperty(propertyDescriptor);
939957
} else if (Objects.nonNull(crossRef)) {
940958
crossRef.removeProperty(propertyDescriptor);
941-
} else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
942-
logger.warn("Ignoring remove property "+propertyDescriptor.getName()+" for license list creation info");
943-
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
944-
logger.warn("Ignoring remove property "+propertyDescriptor.getName()+" for license list creator");
945959
} else {
946960
logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
947961
throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
@@ -997,6 +1011,11 @@ public Stream<TypedValue> getAllItems(String documentUri, @Nullable String typeF
9971011
@SuppressWarnings("unchecked")
9981012
@Override
9991013
public int collectionSize(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException {
1014+
if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
1015+
return ((List<Object>)(List<?>)licenseCreationInfo.getValueList(propertyDescriptor)).size();
1016+
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
1017+
return ((List<Object>)(List<?>)licenseCreator.getValueList(propertyDescriptor)).size();
1018+
}
10001019
String id = objectUriToId(objectUri);
10011020
boolean isLicenseId = false;
10021021
boolean isExceptionId = false;
@@ -1021,10 +1040,6 @@ public int collectionSize(String objectUri, PropertyDescriptor propertyDescripto
10211040
return ((List<Object>)(List<?>)exc.getValueList(propertyDescriptor)).size();
10221041
} else if (Objects.nonNull(crossRef)) {
10231042
return ((List<Object>)(List<?>)crossRef.getValueList(propertyDescriptor)).size();
1024-
} else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
1025-
return ((List<Object>)(List<?>)licenseCreationInfo.getValueList(propertyDescriptor)).size();
1026-
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
1027-
return ((List<Object>)(List<?>)licenseCreator.getValueList(propertyDescriptor)).size();
10281043
} else {
10291044
logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
10301045
throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
@@ -1035,6 +1050,11 @@ public int collectionSize(String objectUri, PropertyDescriptor propertyDescripto
10351050
@Override
10361051
public boolean collectionContains(String objectUri, PropertyDescriptor propertyDescriptor, Object value)
10371052
throws InvalidSPDXAnalysisException {
1053+
if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
1054+
return ((List<Object>)(List<?>)licenseCreationInfo.getValueList(propertyDescriptor)).contains(value);
1055+
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
1056+
return ((List<Object>)(List<?>)licenseCreator.getValueList(propertyDescriptor)).contains(value);
1057+
}
10381058
String id = objectUriToId(objectUri);
10391059
boolean isLicenseId = false;
10401060
boolean isExceptionId = false;
@@ -1069,10 +1089,6 @@ public boolean collectionContains(String objectUri, PropertyDescriptor propertyD
10691089
return ((List<Object>)(List<?>)exc.getValueList(propertyDescriptor)).contains(value);
10701090
} else if (Objects.nonNull(crossRef)) {
10711091
return ((List<Object>)(List<?>)crossRef.getValueList(propertyDescriptor)).contains(value);
1072-
} else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
1073-
return ((List<Object>)(List<?>)licenseCreationInfo.getValueList(propertyDescriptor)).contains(value);
1074-
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
1075-
return ((List<Object>)(List<?>)licenseCreator.getValueList(propertyDescriptor)).contains(value);
10761092
} else {
10771093
logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
10781094
throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
@@ -1121,6 +1137,11 @@ public boolean isCollectionMembersAssignableTo(String objectUri, PropertyDescrip
11211137
public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor,
11221138
Class<?> clazz, String specVersion)
11231139
throws InvalidSPDXAnalysisException {
1140+
if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
1141+
return licenseCreationInfo.isPropertyValueAssignableTo(propertyDescriptor, clazz);
1142+
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
1143+
return licenseCreator.isPropertyValueAssignableTo(propertyDescriptor, clazz);
1144+
}
11241145
String id = objectUriToId(objectUri);
11251146
boolean isLicenseId = false;
11261147
boolean isExceptionId = false;
@@ -1145,10 +1166,6 @@ public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor
11451166
return exc.isPropertyValueAssignableTo(propertyDescriptor, clazz);
11461167
} else if (Objects.nonNull(crossRef)) {
11471168
return crossRef.isPropertyValueAssignableTo(propertyDescriptor, clazz);
1148-
} else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
1149-
return licenseCreationInfo.isPropertyValueAssignableTo(propertyDescriptor, clazz);
1150-
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
1151-
return licenseCreator.isPropertyValueAssignableTo(propertyDescriptor, clazz);
11521169
} else {
11531170
logger.error("ID "+id+" is not a listed license ID, CrossRef ID nor a listed exception ID");
11541171
throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, CrossRef ID nor a listed exception ID");
@@ -1158,6 +1175,11 @@ public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor
11581175
@Override
11591176
public boolean isCollectionProperty(String objectUri, PropertyDescriptor propertyDescriptor)
11601177
throws InvalidSPDXAnalysisException {
1178+
if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
1179+
return this.licenseCreationInfo.isCollectionProperty(propertyDescriptor);
1180+
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
1181+
return licenseCreator.isCollectionProperty(propertyDescriptor);
1182+
}
11611183
String id = objectUriToId(objectUri);
11621184
boolean isLicenseId = false;
11631185
boolean isExceptionId = false;
@@ -1182,10 +1204,6 @@ public boolean isCollectionProperty(String objectUri, PropertyDescriptor propert
11821204
return exc.isCollectionProperty(propertyDescriptor);
11831205
} else if (Objects.nonNull(crossRef)) {
11841206
return crossRef.isCollectionProperty(propertyDescriptor.getName());
1185-
} else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
1186-
return this.licenseCreationInfo.isCollectionProperty(propertyDescriptor);
1187-
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
1188-
return licenseCreator.isCollectionProperty(propertyDescriptor);
11891207
} else {
11901208
logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
11911209
throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
@@ -1260,6 +1278,13 @@ public Optional<String> getCaseSensisitiveId(String documentUri, String caseInse
12601278

12611279
@Override
12621280
public void delete(String objectUri) throws InvalidSPDXAnalysisException {
1281+
if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
1282+
logger.warn("Ignoring the removal of the creation info for the license list");
1283+
return;
1284+
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
1285+
logger.warn("Ignoring the removal of the creator for the license list");
1286+
return;
1287+
}
12631288
String id = objectUriToId(objectUri);
12641289
listedLicenseModificationLock.writeLock().lock();
12651290
try {
@@ -1271,10 +1296,6 @@ public void delete(String objectUri) throws InvalidSPDXAnalysisException {
12711296
this.exceptionIds.remove(id.toLowerCase());
12721297
} else if (crossRefs.containsKey(id)) {
12731298
this.crossRefs.remove(id);
1274-
} else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) {
1275-
logger.warn("Ignoring the removal of the creation info for the license list");
1276-
} else if (licenseCreator.getObjectUri().equals(objectUri)) {
1277-
logger.warn("Ignoring the removal of the creator for the license list");
12781299
} else {
12791300
logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");
12801301
throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID");

0 commit comments

Comments
 (0)