Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/org/spdx/library/LicenseInfoFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}


Expand All @@ -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 {
Expand All @@ -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));
}


Expand All @@ -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));
}


Expand All @@ -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));
}


Expand All @@ -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));
}


Expand All @@ -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));
}


Expand All @@ -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));
}


Expand All @@ -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));
}


Expand All @@ -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));
}


Expand All @@ -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 {
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -251,4 +242,10 @@ public void testRegressionSameTerms() throws InvalidSPDXAnalysisException {
assertTrue(foundLicenseRef);
assertTrue(foundMit);
}

public void testInvalidExceptionOnly() throws InvalidSPDXAnalysisException {
AnyLicenseInfo result = LicenseInfoFactory.parseSPDXLicenseStringCompatV2("389-exception");
Comment thread
goneall marked this conversation as resolved.
assertTrue(result instanceof InvalidLicenseExpression);
assertEquals("389-exception", ((InvalidLicenseExpression)result).getLicenseExpression());
}
}
Loading