diff --git a/src/main/java/org/spdx/library/LicenseInfoFactory.java b/src/main/java/org/spdx/library/LicenseInfoFactory.java index c285d652..5d425a20 100644 --- a/src/main/java/org/spdx/library/LicenseInfoFactory.java +++ b/src/main/java/org/spdx/library/LicenseInfoFactory.java @@ -249,6 +249,7 @@ public static AnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nulla InvalidLicenseExpression retval = new InvalidLicenseExpression(store, store.getNextId(IModelStore.IdType.Anonymous), copyManager, true, customLicensePrefix); retval.setMessage(e.getMessage()); + retval.setLicenseExpression(licenseString); return retval; } catch (InvalidSPDXAnalysisException e1) { throw new RuntimeException(e1); @@ -258,6 +259,7 @@ public static AnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nulla InvalidLicenseExpression retval = new InvalidLicenseExpression(store, store.getNextId(IModelStore.IdType.Anonymous), copyManager, true, customLicensePrefix); retval.setMessage(String.format("Unexpected SPDX error parsing license string: %s", e.getMessage())); + retval.setLicenseExpression(licenseString); return retval; } catch (InvalidSPDXAnalysisException e1) { throw new RuntimeException(e1); diff --git a/src/main/java/org/spdx/library/conversion/Spdx2to3Converter.java b/src/main/java/org/spdx/library/conversion/Spdx2to3Converter.java index 15b67360..f83f32f8 100644 --- a/src/main/java/org/spdx/library/conversion/Spdx2to3Converter.java +++ b/src/main/java/org/spdx/library/conversion/Spdx2to3Converter.java @@ -870,7 +870,7 @@ public InvalidLicenseExpression convertAndStore(org.spdx.library.model.v2.licens toObjectUri, "SimpleLicensing.InvalidLicenseExpression", copyManager, true, defaultUriPrefix); toInvalidLicExpression.setCreationInfo(defaultCreationInfo); toInvalidLicExpression.setMessage(fromInvalidLicenseExpression.getMessage()); - toInvalidLicExpression.setLicenseExpression(fromInvalidLicenseExpression.getMessage()); + toInvalidLicExpression.setLicenseExpression(fromInvalidLicenseExpression.getLicenseExpression()); return toInvalidLicExpression; } diff --git a/src/test/java/org/spdx/utility/license/LicenseExpressionParserTest.java b/src/test/java/org/spdx/utility/license/LicenseExpressionParserTest.java index 43148fcc..84f22063 100644 --- a/src/test/java/org/spdx/utility/license/LicenseExpressionParserTest.java +++ b/src/test/java/org/spdx/utility/license/LicenseExpressionParserTest.java @@ -48,6 +48,7 @@ import org.spdx.library.model.v3_0_1.expandedlicensing.OrLaterOperator; import org.spdx.library.model.v3_0_1.expandedlicensing.WithAdditionOperator; import org.spdx.library.model.v3_0_1.simplelicensing.AnyLicenseInfo; +import org.spdx.library.model.v3_0_1.simplelicensing.InvalidLicenseExpression; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; @@ -183,7 +184,7 @@ public void testSingleStdLicense() throws InvalidSPDXAnalysisException { AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); - assertEquals(expected, result); + assertTrue(expected.equals(result)); } @@ -192,7 +193,7 @@ public void testSingleExtractedLicense() throws InvalidSPDXAnalysisException { AnyLicenseInfo expected = NON_STD_LICENSES[0]; AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); - assertEquals(expected, result); + assertTrue(expected.equals(result)); } public void testUninitializedExtractedLicense() throws InvalidSPDXAnalysisException { @@ -209,7 +210,7 @@ public void testOrLater() throws InvalidSPDXAnalysisException { expected.setSubjectLicense(STANDARD_LICENSES[0]); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); - assertEquals(expected, result); + assertTrue(expected.equals(result)); } @@ -220,14 +221,14 @@ public void testWithException() throws InvalidSPDXAnalysisException { expected.setSubjectExtendableLicense(STANDARD_LICENSES[0]); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); - assertEquals(expected, result); + assertTrue(expected.equals(result)); parseString = STD_IDS[0]+" WITH " + STD_EXCEPTION_IDS[0]; expected = new WithAdditionOperator(); expected.setSubjectAddition(STD_LICENSE_EXCEPTIONS[0]); expected.setSubjectExtendableLicense(STANDARD_LICENSES[0]); result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); - assertEquals(expected, result); + assertTrue(expected.equals(result)); } @@ -238,7 +239,7 @@ public void testSimpleAnd() throws InvalidSPDXAnalysisException { expected.getMembers().add(NON_STD_LICENSES[0]); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); - assertEquals(expected, result); + assertTrue(expected.equals(result)); } @@ -249,7 +250,7 @@ public void testSimpleOr() throws InvalidSPDXAnalysisException { expected.getMembers().add(NON_STD_LICENSES[0]); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); - assertEquals(expected, result); + assertTrue(expected.equals(result)); } @@ -261,7 +262,7 @@ public void testLargerAnd() throws InvalidSPDXAnalysisException { NON_STD_LICENSES[1], STANDARD_LICENSES[2], STANDARD_LICENSES[3]}))); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); - assertEquals(expected, result); + assertTrue(expected.equals(result)); } @@ -273,7 +274,7 @@ public void testLargerOr() throws InvalidSPDXAnalysisException { NON_STD_LICENSES[1], STANDARD_LICENSES[2], STANDARD_LICENSES[3]}))); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); - assertEquals(expected, result); + assertTrue(expected.equals(result)); } @@ -285,7 +286,7 @@ public void testOuterParens() throws InvalidSPDXAnalysisException { NON_STD_LICENSES[1], STANDARD_LICENSES[2], STANDARD_LICENSES[3]}))); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); - assertEquals(expected, result); + assertTrue(expected.equals(result)); } @@ -299,7 +300,7 @@ public void testInnerParens() throws InvalidSPDXAnalysisException { NON_STD_LICENSES[1], dls}))); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); - assertEquals(expected, result); + assertTrue(expected.equals(result)); } @@ -314,7 +315,7 @@ public void testAndOrPrecedence() throws InvalidSPDXAnalysisException { cls, STANDARD_LICENSES[3]}))); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); - assertEquals(expected, result); + assertTrue(expected.equals(result)); } public void testExternalCustomLicense() throws InvalidSPDXAnalysisException { @@ -405,4 +406,11 @@ public void testRegressionSameTerms() throws InvalidSPDXAnalysisException { assertTrue(((DisjunctiveLicenseSet)result).getMembers().contains(NON_STD_LICENSES[1])); assertTrue(((DisjunctiveLicenseSet)result).getMembers().contains(STANDARD_LICENSES[1])); } + + public void testInvalidExceptionOnly() throws InvalidSPDXAnalysisException { + AnyLicenseInfo result = LicenseInfoFactory.parseSPDXLicenseString(STD_EXCEPTION_IDS[0], modelStore, + DEFAULT_PREFIX, creationInfo, copyManager, idMap); + assertTrue(result instanceof InvalidLicenseExpression); + assertEquals(STD_EXCEPTION_IDS[0], ((InvalidLicenseExpression)result).getLicenseExpression()); + } } diff --git a/src/test/java/org/spdx/utility/license/LicenseExpressionParserTestV2.java b/src/test/java/org/spdx/utility/license/LicenseExpressionParserTestV2.java index 2465e461..6f8a322a 100644 --- a/src/test/java/org/spdx/utility/license/LicenseExpressionParserTestV2.java +++ b/src/test/java/org/spdx/utility/license/LicenseExpressionParserTestV2.java @@ -31,16 +31,7 @@ import org.spdx.library.model.v2.SpdxConstantsCompatV2; import org.spdx.library.model.v2.SpdxDocument; import org.spdx.library.model.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.v2.license.AnyLicenseInfo; -import org.spdx.library.model.v2.license.ConjunctiveLicenseSet; -import org.spdx.library.model.v2.license.DisjunctiveLicenseSet; -import org.spdx.library.model.v2.license.ExternalExtractedLicenseInfo; -import org.spdx.library.model.v2.license.ExtractedLicenseInfo; -import org.spdx.library.model.v2.license.LicenseException; -import org.spdx.library.model.v2.license.ListedLicenseException; -import org.spdx.library.model.v2.license.OrLaterOperator; -import org.spdx.library.model.v2.license.SpdxListedLicense; -import org.spdx.library.model.v2.license.WithExceptionOperator; +import org.spdx.library.model.v2.license.*; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -251,4 +242,10 @@ public void testRegressionSameTerms() throws InvalidSPDXAnalysisException { assertTrue(foundLicenseRef); assertTrue(foundMit); } + + public void testInvalidExceptionOnly() throws InvalidSPDXAnalysisException { + AnyLicenseInfo result = LicenseInfoFactory.parseSPDXLicenseStringCompatV2("389-exception"); + assertTrue(result instanceof InvalidLicenseExpression); + assertEquals("389-exception", ((InvalidLicenseExpression)result).getLicenseExpression()); + } }