|
78 | 78 | import org.spdx.library.model.v3_0_1.expandedlicensing.OrLaterOperator; |
79 | 79 | import org.spdx.library.model.v3_0_1.expandedlicensing.WithAdditionOperator; |
80 | 80 | import org.spdx.library.model.v3_0_1.simplelicensing.AnyLicenseInfo; |
| 81 | +import org.spdx.library.model.v3_0_1.simplelicensing.InvalidLicenseExpression; |
81 | 82 | import org.spdx.library.model.v3_0_1.simplelicensing.LicenseExpression; |
82 | 83 | import org.spdx.library.model.v3_0_1.software.ContentIdentifierType; |
83 | 84 | import org.spdx.library.model.v3_0_1.software.Snippet; |
@@ -844,6 +845,33 @@ public OrLaterOperator convertAndStore(org.spdx.library.model.v2.license.OrLater |
844 | 845 | toOrLaterOperator.setSubjectLicense((License)convertAndStore(fromOrLaterOperator.getLicense())); |
845 | 846 | return toOrLaterOperator; |
846 | 847 | } |
| 848 | + |
| 849 | + /** |
| 850 | + * Converts an SPDX spec version 2 SPDX InvalidLicenseExpression to an SPDX spec version 3 SPDX InvalidLicenseExpression and store the result |
| 851 | + * @param fromInvalidExpression an SPDX spec version 2 InvalidLicenseExpression |
| 852 | + * @return an SPDX spec version 3 InvalidLicenseExpression |
| 853 | + * @throws InvalidSPDXAnalysisException on any errors converting |
| 854 | + */ |
| 855 | + public InvalidLicenseExpression convertAndStore(org.spdx.library.model.v2.license.InvalidLicenseExpression fromInvalidExpression) throws InvalidSPDXAnalysisException { |
| 856 | + Optional<ModelObjectV3> existing = getExistingObject(fromInvalidExpression.getObjectUri(), |
| 857 | + "SimpleLicensing.InvalidLicenseExpression"); //TODO: This should be included in the SPDXV3 Constants file |
| 858 | + if (existing.isPresent()) { |
| 859 | + return (InvalidLicenseExpression)existing.get(); |
| 860 | + } |
| 861 | + String toObjectUri = toModelStore.getNextId(IdType.Anonymous); |
| 862 | + String existingUri = this.alreadyConverted.putIfAbsent(fromInvalidExpression.getObjectUri(), toObjectUri); |
| 863 | + if (Objects.nonNull(existingUri)) { |
| 864 | + // small window if conversion occurred since the last check already converted |
| 865 | + return (InvalidLicenseExpression)getExistingObject(fromInvalidExpression.getObjectUri(), |
| 866 | + "SimpleLicensing.InvalidLicenseExpression").get(); |
| 867 | + } |
| 868 | + InvalidLicenseExpression toInvalidLicExpression = (InvalidLicenseExpression)SpdxModelClassFactoryV3.getModelObject(toModelStore, |
| 869 | + toObjectUri, "SimpleLicensing.InvalidLicenseExpression", copyManager, true, defaultUriPrefix); |
| 870 | + toInvalidLicExpression.setCreationInfo(defaultCreationInfo); |
| 871 | + toInvalidLicExpression.setMessage(fromInvalidExpression.getMessage()); |
| 872 | + toInvalidLicExpression.setLicenseExpression(fromInvalidExpression.getMessage()); |
| 873 | + return toInvalidLicExpression; |
| 874 | + } |
847 | 875 |
|
848 | 876 | /** |
849 | 877 | * Converts an SPDX spec version 2 SPDX SpdxListedLicense to an SPDX spec version 3 SPDX ListedLicense and store the result |
@@ -1043,26 +1071,28 @@ public AnyLicenseInfo convertAndStore(org.spdx.library.model.v2.license.AnyLicen |
1043 | 1071 | if (!complexLicenses) { |
1044 | 1072 | return convertToLicenseExpression(fromLicense); |
1045 | 1073 | } else if (fromLicense instanceof org.spdx.library.model.v2.license.ConjunctiveLicenseSet) { |
1046 | | - return convertAndStore((org.spdx.library.model.v2.license.ConjunctiveLicenseSet)fromLicense); |
| 1074 | + return convertAndStore((org.spdx.library.model.v2.license.ConjunctiveLicenseSet) fromLicense); |
1047 | 1075 | } else if (fromLicense instanceof org.spdx.library.model.v2.license.DisjunctiveLicenseSet) { |
1048 | | - return convertAndStore((org.spdx.library.model.v2.license.DisjunctiveLicenseSet)fromLicense); |
| 1076 | + return convertAndStore((org.spdx.library.model.v2.license.DisjunctiveLicenseSet) fromLicense); |
1049 | 1077 | } else if (fromLicense instanceof org.spdx.library.model.v2.license.ExternalExtractedLicenseInfo) { |
1050 | | - String externalUri = ((org.spdx.library.model.v2.license.ExternalExtractedLicenseInfo)fromLicense).getIndividualURI(); |
1051 | | - logger.warn("Referencing an external SPDX 2 element with URI {} while converting from SPDX 2 to 3", externalUri); |
| 1078 | + String externalUri = ((org.spdx.library.model.v2.license.ExternalExtractedLicenseInfo) fromLicense).getIndividualURI(); |
| 1079 | + logger.warn("Referencing an external SPDX 2 element with URI {} while converting from SPDX 2 to 3", externalUri); |
1052 | 1080 | addExternalMapInfo(externalUri); |
1053 | 1081 | return new ExternalCustomLicense(externalUri); |
1054 | 1082 | } else if (fromLicense instanceof org.spdx.library.model.v2.license.ExtractedLicenseInfo) { |
1055 | | - return convertAndStore((org.spdx.library.model.v2.license.ExtractedLicenseInfo)fromLicense); |
| 1083 | + return convertAndStore((org.spdx.library.model.v2.license.ExtractedLicenseInfo) fromLicense); |
1056 | 1084 | } else if (fromLicense instanceof org.spdx.library.model.v2.license.OrLaterOperator) { |
1057 | | - return convertAndStore((org.spdx.library.model.v2.license.OrLaterOperator)fromLicense); |
| 1085 | + return convertAndStore((org.spdx.library.model.v2.license.OrLaterOperator) fromLicense); |
1058 | 1086 | } else if (fromLicense instanceof org.spdx.library.model.v2.license.SpdxListedLicense) { |
1059 | | - return convertAndStore((org.spdx.library.model.v2.license.SpdxListedLicense)fromLicense); |
| 1087 | + return convertAndStore((org.spdx.library.model.v2.license.SpdxListedLicense) fromLicense); |
1060 | 1088 | } else if (fromLicense instanceof org.spdx.library.model.v2.license.SpdxNoneLicense) { |
1061 | 1089 | return new NoneLicense(); |
1062 | 1090 | } else if (fromLicense instanceof org.spdx.library.model.v2.license.SpdxNoAssertionLicense) { |
1063 | 1091 | return new NoAssertionLicense(); |
1064 | 1092 | } else if (fromLicense instanceof org.spdx.library.model.v2.license.WithExceptionOperator) { |
1065 | | - return convertAndStore((org.spdx.library.model.v2.license.WithExceptionOperator)fromLicense); |
| 1093 | + return convertAndStore((org.spdx.library.model.v2.license.WithExceptionOperator) fromLicense); |
| 1094 | + } else if (fromLicense instanceof org.spdx.library.model.v2.license.InvalidLicenseExpression) { |
| 1095 | + return convertAndStore((org.spdx.library.model.v2.license.InvalidLicenseExpression) fromLicense); |
1066 | 1096 | } else { |
1067 | 1097 | throw new InvalidSPDXAnalysisException("Can not convert the from AnyLicenseInfo type "+fromLicense.getType()); |
1068 | 1098 | } |
|
0 commit comments