diff --git a/src/main/java/org/spdx/library/LicenseInfoFactory.java b/src/main/java/org/spdx/library/LicenseInfoFactory.java index 5d0b5802..89ff65f5 100644 --- a/src/main/java/org/spdx/library/LicenseInfoFactory.java +++ b/src/main/java/org/spdx/library/LicenseInfoFactory.java @@ -31,6 +31,7 @@ import org.spdx.core.InvalidSPDXAnalysisException; import org.spdx.library.model.v2.license.InvalidLicenseStringException; import org.spdx.library.model.v2.license.SpdxListedLicense; +import org.spdx.library.model.v3_0_1.SpdxModelClassFactoryV3; import org.spdx.library.model.v3_0_1.core.CreationInfo; import org.spdx.library.model.v3_0_1.core.DictionaryEntry; import org.spdx.library.model.v3_0_1.expandedlicensing.ListedLicense; @@ -143,14 +144,17 @@ public static org.spdx.library.model.v2.license.AnyLicenseInfo parseSPDXLicenseS * none exist for an ID, they will be added. If null, the default model store will be used. * @param customLicensePrefix Prefix to use for any custom licenses or addition IDs found in the string. If the resultant object URI does not exist * for an ID, they will be added. If null, the default model document URI + "#" will be used. + * @param creationInfo Creation information to use for newly created elements. If null, the default * @param copyManager allows for copying of any properties set which use other model stores or document URI's. If null, the default will be used. * @param customIdToUri Mapping of the id prefixes used in the license expression to the namespace preceding the external ID * @return an SPDXLicenseInfo created from the string. If the license expression is not parseable, a InvalidLicenseExpression is returned. * @throws DefaultStoreNotInitializedException if the default model store is not initialized */ - public static AnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nullable IModelStore store, - @Nullable String customLicensePrefix, @Nullable IModelCopyManager copyManager, - @Nullable List customIdToUri) throws InvalidLicenseStringException, DefaultStoreNotInitializedException { + public static AnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nullable IModelStore store, + @Nullable String customLicensePrefix, + @Nullable CreationInfo creationInfo, + @Nullable IModelCopyManager copyManager, + @Nullable List customIdToUri) throws InvalidLicenseStringException, DefaultStoreNotInitializedException { if (Objects.isNull(store)) { store = DefaultModelStore.getDefaultModelStore(); } @@ -160,9 +164,18 @@ public static AnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nulla if (Objects.isNull(copyManager)) { copyManager = DefaultModelStore.getDefaultCopyManager(); } + if (Objects.isNull(creationInfo)) { + try { + creationInfo = SpdxModelClassFactoryV3.createCreationInfo( + store, customLicensePrefix + "licenseinfo-creator", "LicenseInfoFactory", + copyManager); + } catch (InvalidSPDXAnalysisException e) { + throw new RuntimeException(e); + } + } try { return LicenseExpressionParser.parseLicenseExpression(licenseString, store, customLicensePrefix, - copyManager, customIdToUri); + creationInfo, copyManager, customIdToUri); } catch (LicenseParserException e) { try { InvalidLicenseExpression retval = new InvalidLicenseExpression(store, store.getNextId(IModelStore.IdType.Anonymous), @@ -185,6 +198,34 @@ public static AnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nulla } + /** + * Parses a license string and converts it into a SPDXLicenseInfo object using the default creation information + * Syntax - A license set must start and end with a parenthesis "(" + * A conjunctive license set will have and AND after the first + * licenseInfo term + * A disjunctive license set will have an OR after the first + * licenseInfo term + * If there is no And or Or, then it is converted to a simple + * license type + * A space or tab must be used between license ID's and the + * keywords AND and OR + * A licenseID must NOT be "AND" or "OR" + * @param licenseString String conforming to the syntax + * @param store Store containing any extractedLicenseInfos - if any extractedLicenseInfos by ID already exist, they will be used. If + * none exist for an ID, they will be added. If null, the default model store will be used. + * @param customLicensePrefix Prefix to use for any custom licenses or addition IDs found in the string. If the resultant object URI does not exist + * for an ID, they will be added. If null, the default model document URI + "#" will be used. + * @param copyManager allows for copying of any properties set which use other model stores or document URI's. If null, the default will be used. + * @param customIdToUri Mapping of the id prefixes used in the license expression to the namespace preceding the external ID + * @return an SPDXLicenseInfo created from the string. If the license expression is not parseable, a InvalidLicenseExpression is returned. + * @throws DefaultStoreNotInitializedException if the default model store is not initialized + */ + public static AnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nullable IModelStore store, + @Nullable String customLicensePrefix, + @Nullable IModelCopyManager copyManager, + @Nullable List customIdToUri) throws InvalidLicenseStringException, DefaultStoreNotInitializedException { + return parseSPDXLicenseString(licenseString, store, customLicensePrefix, null, copyManager, customIdToUri); + } /** * Parses a license string and converts it into a SPDXLicenseInfo object * Syntax - A license set must start and end with a parenthesis "(" @@ -203,7 +244,7 @@ public static AnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nulla * @throws DefaultStoreNotInitializedException if the default model store is not initialized */ public static AnyLicenseInfo parseSPDXLicenseString(String licenseString) throws InvalidLicenseStringException, DefaultStoreNotInitializedException { - return parseSPDXLicenseString(licenseString, null, null, null, null); + return parseSPDXLicenseString(licenseString, null, null, null, null, null); } /** diff --git a/src/main/java/org/spdx/utility/license/LicenseExpressionParser.java b/src/main/java/org/spdx/utility/license/LicenseExpressionParser.java index 8f232435..07dc2e22 100644 --- a/src/main/java/org/spdx/utility/license/LicenseExpressionParser.java +++ b/src/main/java/org/spdx/utility/license/LicenseExpressionParser.java @@ -44,6 +44,7 @@ import org.spdx.library.model.v2.license.SpdxNoneLicense; import org.spdx.library.model.v2.license.WithExceptionOperator; import org.spdx.library.model.v3_0_1.SpdxConstantsV3; +import org.spdx.library.model.v3_0_1.core.CreationInfo; import org.spdx.library.model.v3_0_1.core.DictionaryEntry; import org.spdx.library.model.v3_0_1.expandedlicensing.ConjunctiveLicenseSet; import org.spdx.library.model.v3_0_1.expandedlicensing.CustomLicense; @@ -100,13 +101,15 @@ enum Operator { * none exist for an ID, they will be added. If null, the default model store will be used. * @param customLicenseUriPrefix Prefix for Object URI's created when appending custom license ID's or custom license additions. If any custom licenses or additions already exist, they will be used. * If none exist for an ID, they will be added. If null, the default model document URI will be used. + * @param creationInfo Creation information to use for newly created elements * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's * @param customIdToUri Mapping of the id prefixes used in the license expression to the namespace preceding the external ID * @return the parsed license expression * @throws InvalidSPDXAnalysisException on SPDX parsing errors */ - public static AnyLicenseInfo parseLicenseExpression(String expression, IModelStore store, - String customLicenseUriPrefix, @Nullable IModelCopyManager copyManager, + public static AnyLicenseInfo parseLicenseExpression(String expression, IModelStore store, + String customLicenseUriPrefix, CreationInfo creationInfo, + @Nullable IModelCopyManager copyManager, @Nullable List customIdToUri) throws InvalidSPDXAnalysisException { if (expression == null || expression.trim().isEmpty()) { throw new LicenseParserException("Empty license expression"); @@ -122,7 +125,8 @@ public static AnyLicenseInfo parseLicenseExpression(String expression, IModelSto return new NoneLicense(); } else { try { - return parseLicenseExpression(tokens, store, customLicenseUriPrefix, copyManager, customIdToUri); + return parseLicenseExpression(tokens, store, customLicenseUriPrefix, creationInfo, + copyManager, customIdToUri); } catch (LicenseParserException ex) { // Add the expression to the error message to provide additional information to the user throw new LicenseParserException(ex.getMessage()+" License expression: '"+expression+"'", ex); @@ -208,16 +212,18 @@ private static void processPreToken(String preToken, * Parses a tokenized license expression into a license for use in the RDF Parser * @param tokens array of tokens * @param store model store for non-listed licenses - * @param customLicenseUriPrefix Prefix for Object URI's created when appending custom license ID's or custom license additions. If any custom licenses or additions already exist, they will be used. + * @param customLicenseUriPrefix Prefix for Object URI's created when creating any new IDs. If any custom licenses or additions already exist, they will be used. * If none exist for an ID, they will be added. If null, the default model document URI will be used. + * @param creationInfo Creation information to use for newly created elements * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's * @param customIdToUri Mapping of the id prefixes used in the license expression to the namespace preceding the external ID - required for any external additions or licenses * @return a license info representing the fully parsed list of tokens * @throws InvalidSPDXAnalysisException on SPDX parsing errors */ - private static AnyLicenseInfo parseLicenseExpression(String[] tokens, IModelStore store, - String customLicenseUriPrefix, @Nullable IModelCopyManager copyManager, - @Nullable List customIdToUri) throws InvalidSPDXAnalysisException { + private static AnyLicenseInfo parseLicenseExpression(String[] tokens, IModelStore store, + String customLicenseUriPrefix, CreationInfo creationInfo, + @Nullable IModelCopyManager copyManager, + @Nullable List customIdToUri) throws InvalidSPDXAnalysisException { if (tokens == null || tokens.length == 0) { throw new LicenseParserException("Expected license expression"); } @@ -235,24 +241,26 @@ private static AnyLicenseInfo parseLicenseExpression(String[] tokens, IModelStor } String[] nestedTokens = Arrays.copyOfRange(tokens, tokenIndex, rightParenIndex); operandStack.push(parseLicenseExpression(nestedTokens, store, customLicenseUriPrefix, - copyManager, customIdToUri)); + creationInfo, copyManager, customIdToUri)); tokenIndex = rightParenIndex + 1; } else if (OPERATOR_MAP.get(token) == null) { // assumed to be a simple licensing type - operandStack.push(parseSimpleLicenseToken(token, store, customLicenseUriPrefix, copyManager, customIdToUri)); + operandStack.push(parseSimpleLicenseToken(token, store, customLicenseUriPrefix, + creationInfo, copyManager, customIdToUri)); } else { Operator operator = OPERATOR_MAP.get(token); if (operator == Operator.WITH) { // special processing here since With must be with an exception, not a licenseInfo if (!operatorStack.isEmpty() && Operator.OR_LATER.equals(operatorStack.peek())) { Operator tosOperator = operatorStack.pop(); - evaluateExpression(tosOperator, operandStack, store, customLicenseUriPrefix, copyManager); + evaluateExpression(tosOperator, operandStack, store, customLicenseUriPrefix, + creationInfo, copyManager); } if (tokenIndex >= tokens.length) { throw new LicenseParserException("Missing exception clause"); } token = tokens[tokenIndex++]; LicenseAddition licenseAddition = parseSimpleLicenseAdditionToken(token, - store, customLicenseUriPrefix, copyManager, customIdToUri); + store, customLicenseUriPrefix, creationInfo, copyManager, customIdToUri); AnyLicenseInfo operand = operandStack.pop(); if (operand == null) { throw new LicenseParserException("Missing license for with clause"); @@ -261,7 +269,8 @@ private static AnyLicenseInfo parseLicenseExpression(String[] tokens, IModelStor throw new LicenseParserException("License with exception is not of type License or OrLaterOperator"); } WithAdditionOperator weo = new WithAdditionOperator(store, - store.getNextId(IdType.Anonymous), copyManager, true, customLicenseUriPrefix); + customLicenseUriPrefix + store.getNextId(IdType.SpdxId), copyManager, true, customLicenseUriPrefix); + weo.setCreationInfo(creationInfo); weo.setSubjectExtendableLicense((ExtendableLicense)operand); weo.setSubjectAddition(licenseAddition); operandStack.push(weo); @@ -270,7 +279,8 @@ private static AnyLicenseInfo parseLicenseExpression(String[] tokens, IModelStor while (!operatorStack.isEmpty() && operatorStack.peek().ordinal() <= operator.ordinal()) { Operator tosOperator = operatorStack.pop(); - evaluateExpression(tosOperator, operandStack, store, customLicenseUriPrefix, copyManager); + evaluateExpression(tosOperator, operandStack, store, customLicenseUriPrefix, + creationInfo, copyManager); } operatorStack.push(operator); } @@ -279,7 +289,7 @@ private static AnyLicenseInfo parseLicenseExpression(String[] tokens, IModelStor // go through the rest of the stack while (!operatorStack.isEmpty()) { Operator tosOperator = operatorStack.pop(); - evaluateExpression(tosOperator, operandStack, store, customLicenseUriPrefix, copyManager); + evaluateExpression(tosOperator, operandStack, store, customLicenseUriPrefix, creationInfo, copyManager); } AnyLicenseInfo retval = operandStack.pop(); if (!operandStack.isEmpty()) { @@ -409,13 +419,17 @@ private static int findMatchingParen(String[] tokens, int startToken) { * @param token Token to translate to the equivalent license addition * @param store Store for the licenses * @param customLicenseUriPrefix Prefix to use for any created local licenses or additions + * @param creationInfo Creation information to use for newly created elements * @param copyManager to use when copying from the listed license store * @param customIdToUri Mapping of the id prefixes used in the license expression to the namespace preceding the external ID - required for any external additions or licenses * @return a CustomLicenseAddition, ListedLicense, ListedLicenseException or CustomLicense depending on what is in the store * @throws InvalidSPDXAnalysisException on SPDX parsing errors */ - private static LicenseAddition parseSimpleLicenseAdditionToken(String token, IModelStore store, String customLicenseUriPrefix, - @Nullable IModelCopyManager copyManager, @Nullable List customIdToUri) throws InvalidSPDXAnalysisException { + private static LicenseAddition parseSimpleLicenseAdditionToken(String token, IModelStore store, + String customLicenseUriPrefix, + CreationInfo creationInfo, + @Nullable IModelCopyManager copyManager, + @Nullable List customIdToUri) throws InvalidSPDXAnalysisException { Objects.requireNonNull(token, "Token can not be null"); Objects.requireNonNull(store, "Model store can not be null"); Objects.requireNonNull(customLicenseUriPrefix, "URI Prefix can not be null"); @@ -449,6 +463,7 @@ private static LicenseAddition parseSimpleLicenseAdditionToken(String token, IMo } else { localAddition = new CustomLicenseAddition(store, objectUri, copyManager, true, customLicenseUriPrefix); localAddition.setAdditionText(UNINITIALIZED_LICENSE_TEXT); + localAddition.setCreationInfo(creationInfo); } return localAddition; } else { @@ -461,13 +476,17 @@ private static LicenseAddition parseSimpleLicenseAdditionToken(String token, IMo * @param token Token to translate to the equivalent license * @param store Store for the licenses * @param customLicenseUriPrefix Prefix to use for any created local licenses or additions + * @param creationInfo Creation information to use for newly created elements * @param copyManager to use when copying from the listed license store * @param customIdToUri Mapping of the id prefixes used in the license expression to the namespace preceding the external ID * @return a CustomLicenseAddition, ListedLicense, ListedLicenseException or CustomLicense depending on what is in the store * @throws InvalidSPDXAnalysisException on SPDX parsing errors */ - private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore store, String customLicenseUriPrefix, - @Nullable IModelCopyManager copyManager, @Nullable List customIdToUri) throws InvalidSPDXAnalysisException { + private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore store, + String customLicenseUriPrefix, + CreationInfo creationInfo, + @Nullable IModelCopyManager copyManager, + @Nullable List customIdToUri) throws InvalidSPDXAnalysisException { Objects.requireNonNull(token, "Token can not be null"); Objects.requireNonNull(store, "Model store can not be null"); Objects.requireNonNull(customLicenseUriPrefix, "URI Prefix can not be null"); @@ -500,6 +519,7 @@ private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore } else { localLicense = new CustomLicense(store, objectUri, copyManager, true, customLicenseUriPrefix); localLicense.setLicenseText(UNINITIALIZED_LICENSE_TEXT); + localLicense.setCreationInfo(creationInfo); } return localLicense; } else if (LicenseInfoFactory.isSpdxListedExceptionId(token)) { @@ -610,19 +630,22 @@ private static org.spdx.library.model.v2.license.AnyLicenseInfo parseSimpleLicen * @param copyManager copy manager to use when copying listed licenses to local store * @param store model store to store non-listed licenses * @param customLicenseUriPrefix prefix to use for non-listed licenses + * @param creationInfo Creation information to use for newly created elements * @throws InvalidSPDXAnalysisException on SPDX parsing errors */ private static void evaluateExpression(Operator operator, - Stack operandStack, IModelStore store, - String customLicenseUriPrefix, IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + Stack operandStack, IModelStore store, + String customLicenseUriPrefix, CreationInfo creationInfo, + IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { if (operator == Operator.OR_LATER) { // unary operator AnyLicenseInfo license = operandStack.pop(); if (!(license instanceof License)) { throw new LicenseParserException("Missing license for the '+' or later operator"); } - OrLaterOperator olo = new OrLaterOperator(store, store.getNextId(IdType.Anonymous), copyManager, true, customLicenseUriPrefix); + OrLaterOperator olo = new OrLaterOperator(store, customLicenseUriPrefix + store.getNextId(IdType.SpdxId), copyManager, true, customLicenseUriPrefix); olo.setSubjectLicense((License)license); + olo.setCreationInfo(creationInfo); operandStack.push(olo); } else { // binary operator @@ -631,7 +654,8 @@ private static void evaluateExpression(Operator operator, if (operand1 == null || operand2 == null) { throw new LicenseParserException("Missing operands for the "+operator.toString()+" operator"); } - operandStack.push(evaluateBinary(operator, operand1, operand2, store, customLicenseUriPrefix, copyManager)); + operandStack.push(evaluateBinary(operator, operand1, operand2, store, customLicenseUriPrefix, + creationInfo, copyManager)); } } @@ -675,12 +699,15 @@ private static void evaluateExpressionCompatV2(Operator operator, * @param copyManager copy manager to use when copying listed licenses to local store * @param store model store to store non-listed licenses * @param customLicenseUriPrefix prefix to use for non-listed licenses + * @param creationInfo Creation information to use for newly created elements * @return resultant license representing the binary operation * @throws InvalidSPDXAnalysisException on SPDX parsing errors */ private static AnyLicenseInfo evaluateBinary(Operator tosOperator, - AnyLicenseInfo operand1, AnyLicenseInfo operand2, IModelStore store, - String customLicenseUriPrefix, IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + AnyLicenseInfo operand1, AnyLicenseInfo operand2, + IModelStore store, String customLicenseUriPrefix, + CreationInfo creationInfo, + IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { if (tosOperator == Operator.AND) { if (operand1 instanceof ConjunctiveLicenseSet) { // just merge into operand1 @@ -688,9 +715,10 @@ private static AnyLicenseInfo evaluateBinary(Operator tosOperator, return operand1; } else { ConjunctiveLicenseSet retval = new ConjunctiveLicenseSet(store, - store.getNextId(IdType.Anonymous), copyManager, true, customLicenseUriPrefix); + customLicenseUriPrefix + store.getNextId(IdType.SpdxId), copyManager, true, customLicenseUriPrefix); retval.getMembers().add(operand1); retval.getMembers().add(operand2); + retval.setCreationInfo(creationInfo); return retval; } } else if (tosOperator == Operator.OR) { @@ -699,10 +727,11 @@ private static AnyLicenseInfo evaluateBinary(Operator tosOperator, ((DisjunctiveLicenseSet) operand1).getMembers().add(operand2); return operand1; } else { - DisjunctiveLicenseSet retval = new DisjunctiveLicenseSet(store, - store.getNextId(IdType.Anonymous), copyManager, true, customLicenseUriPrefix); + DisjunctiveLicenseSet retval = new DisjunctiveLicenseSet(store, + customLicenseUriPrefix + store.getNextId(IdType.SpdxId), copyManager, true, customLicenseUriPrefix); retval.getMembers().add(operand1); retval.getMembers().add(operand2); + retval.setCreationInfo(creationInfo); return retval; } } else { diff --git a/src/test/java/org/spdx/utility/license/LicenseExpressionParserTest.java b/src/test/java/org/spdx/utility/license/LicenseExpressionParserTest.java index c085d668..278ea277 100644 --- a/src/test/java/org/spdx/utility/license/LicenseExpressionParserTest.java +++ b/src/test/java/org/spdx/utility/license/LicenseExpressionParserTest.java @@ -33,6 +33,8 @@ import org.spdx.library.SpdxModelFactory; import org.spdx.library.model.v2.SpdxConstantsCompatV2; import org.spdx.library.model.v2.license.InvalidLicenseStringException; +import org.spdx.library.model.v3_0_1.SpdxModelClassFactoryV3; +import org.spdx.library.model.v3_0_1.core.CreationInfo; import org.spdx.library.model.v3_0_1.core.DictionaryEntry; import org.spdx.library.model.v3_0_1.expandedlicensing.ConjunctiveLicenseSet; import org.spdx.library.model.v3_0_1.expandedlicensing.CustomLicense; @@ -117,6 +119,7 @@ public class LicenseExpressionParserTest extends TestCase { static final String DEFAULT_PREFIX = TEST_DOCUMENT_URI + "#"; ModelCopyManager copyManager; List idMap; + CreationInfo creationInfo; protected void setUp() throws Exception { super.setUp(); @@ -124,6 +127,8 @@ protected void setUp() throws Exception { modelStore = new InMemSpdxStore(); copyManager = new ModelCopyManager(); DefaultModelStore.initialize(new InMemSpdxStore(), TEST_DOCUMENT_URI, copyManager); + creationInfo = SpdxModelClassFactoryV3.createCreationInfo(modelStore, TEST_DOCUMENT_URI + "createdby", + "Test Creation Info", copyManager); NON_STD_LICENSES = new CustomLicense[NONSTD_IDS.length]; for (int i = 0; i < NONSTD_IDS.length; i++) { NON_STD_LICENSES[i] = new CustomLicense(modelStore, TEST_DOCUMENT_URI + "#" + @@ -176,7 +181,7 @@ public void testSingleStdLicense() throws InvalidSPDXAnalysisException { String parseString = STD_IDS[0]; AnyLicenseInfo expected = STANDARD_LICENSES[0]; AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, - modelStore, DEFAULT_PREFIX, + modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); assertTrue(expected.equals(result)); } @@ -186,14 +191,14 @@ public void testSingleExtractedLicense() throws InvalidSPDXAnalysisException { String parseString = NONSTD_IDS[0]; AnyLicenseInfo expected = NON_STD_LICENSES[0]; AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, - DEFAULT_PREFIX, copyManager, idMap); + DEFAULT_PREFIX, creationInfo, copyManager, idMap); assertTrue(expected.equals(result)); } public void testUninitializedExtractedLicense() throws InvalidSPDXAnalysisException { String parseString = "LicenseRef-3242"; AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, - DEFAULT_PREFIX, copyManager, idMap); + DEFAULT_PREFIX, creationInfo, copyManager, idMap); assertEquals(DEFAULT_PREFIX + parseString, result.getObjectUri()); } @@ -203,7 +208,7 @@ public void testOrLater() throws InvalidSPDXAnalysisException { OrLaterOperator expected = new OrLaterOperator(DefaultModelStore.getDefaultDocumentUri()); expected.setSubjectLicense(STANDARD_LICENSES[0]); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, - modelStore, DEFAULT_PREFIX, copyManager, idMap); + modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); assertTrue(expected.equals(result)); } @@ -214,14 +219,14 @@ public void testWithException() throws InvalidSPDXAnalysisException { expected.setSubjectAddition(NON_STD_LICENSE_ADDITIONS[0]); expected.setSubjectExtendableLicense(STANDARD_LICENSES[0]); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, - DEFAULT_PREFIX, copyManager, idMap); + DEFAULT_PREFIX, creationInfo, copyManager, idMap); 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, copyManager, idMap); + DEFAULT_PREFIX, creationInfo, copyManager, idMap); assertTrue(expected.equals(result)); } @@ -232,7 +237,7 @@ public void testSimpleAnd() throws InvalidSPDXAnalysisException { expected.getMembers().add(STANDARD_LICENSES[0]); expected.getMembers().add(NON_STD_LICENSES[0]); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, - modelStore, DEFAULT_PREFIX, copyManager, idMap); + modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); assertTrue(expected.equals(result)); } @@ -243,7 +248,7 @@ public void testSimpleOr() throws InvalidSPDXAnalysisException { expected.getMembers().add(STANDARD_LICENSES[0]); expected.getMembers().add(NON_STD_LICENSES[0]); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, - modelStore, DEFAULT_PREFIX, copyManager, idMap); + modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); assertTrue(expected.equals(result)); } @@ -255,7 +260,7 @@ public void testLargerAnd() throws InvalidSPDXAnalysisException { expected.getMembers().addAll(new ArrayList(Arrays.asList(new AnyLicenseInfo[] {STANDARD_LICENSES[1], NON_STD_LICENSES[1], STANDARD_LICENSES[2], STANDARD_LICENSES[3]}))); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, - DEFAULT_PREFIX, copyManager, idMap); + DEFAULT_PREFIX, creationInfo, copyManager, idMap); assertTrue(expected.equals(result)); } @@ -267,7 +272,7 @@ public void testLargerOr() throws InvalidSPDXAnalysisException { expected.getMembers().addAll(new ArrayList(Arrays.asList(new AnyLicenseInfo[] {STANDARD_LICENSES[1], NON_STD_LICENSES[1], STANDARD_LICENSES[2], STANDARD_LICENSES[3]}))); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, - DEFAULT_PREFIX, copyManager, idMap); + DEFAULT_PREFIX, creationInfo, copyManager, idMap); assertTrue(expected.equals(result)); } @@ -279,7 +284,7 @@ public void testOuterParens() throws InvalidSPDXAnalysisException { expected.getMembers().addAll(new ArrayList(Arrays.asList(new AnyLicenseInfo[] {STANDARD_LICENSES[1], NON_STD_LICENSES[1], STANDARD_LICENSES[2], STANDARD_LICENSES[3]}))); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, - modelStore, DEFAULT_PREFIX, copyManager, idMap); + modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); assertTrue(expected.equals(result)); } @@ -293,7 +298,7 @@ public void testInnerParens() throws InvalidSPDXAnalysisException { expected.getMembers().addAll(new ArrayList(Arrays.asList(new AnyLicenseInfo[] {STANDARD_LICENSES[1] , NON_STD_LICENSES[1], dls}))); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, modelStore, - DEFAULT_PREFIX, copyManager, idMap); + DEFAULT_PREFIX, creationInfo, copyManager, idMap); assertTrue(expected.equals(result)); } @@ -308,19 +313,19 @@ public void testAndOrPrecedence() throws InvalidSPDXAnalysisException { expected.getMembers().addAll(new ArrayList(Arrays.asList(new AnyLicenseInfo[] {STANDARD_LICENSES[1] , cls, STANDARD_LICENSES[3]}))); AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, - modelStore, DEFAULT_PREFIX, copyManager, idMap); + modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); assertTrue(expected.equals(result)); } public void testExternalCustomLicense() throws InvalidSPDXAnalysisException { String simpleParseString = EXTERNAL_CUSTOM_LICENSE_TOKENS[0]; AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(simpleParseString, - modelStore, DEFAULT_PREFIX, copyManager, idMap); + modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); assertTrue(result instanceof ExternalCustomLicense); assertEquals(EXTERNAL_CUSTOM_LICENSE_URIS[0], ((ExternalCustomLicense)result).getObjectUri()); String licenseWithAddition = EXTERNAL_CUSTOM_LICENSE_TOKENS[0] + " WITH 389-exception"; result = LicenseExpressionParser.parseLicenseExpression(licenseWithAddition, - modelStore, DEFAULT_PREFIX, copyManager, idMap); + modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); assertTrue(result instanceof WithAdditionOperator); ExtendableLicense subject = ((WithAdditionOperator)result).getSubjectExtendableLicense(); assertTrue(subject instanceof ExternalExtendableLicense); @@ -330,7 +335,7 @@ public void testExternalCustomLicense() throws InvalidSPDXAnalysisException { EXTERNAL_CUSTOM_LICENSE_TOKENS[2] + " AND " + EXTERNAL_CUSTOM_LICENSE_TOKENS[3]; result = LicenseExpressionParser.parseLicenseExpression(complexParseString, - modelStore, DEFAULT_PREFIX, copyManager, idMap); + modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); assertTrue(result instanceof ConjunctiveLicenseSet); Boolean[] found = new Boolean[] {false, false, false, false}; Collection members = ((ConjunctiveLicenseSet)result).getMembers(); @@ -351,7 +356,7 @@ public void testExternalCustomLicense() throws InvalidSPDXAnalysisException { public void testExternalLicenseAddition() throws InvalidSPDXAnalysisException { String simpleParseString = NONSTD_IDS[0] + " WITH " + EXTERNAL_CUSTOM_ADDITION_TOKENS[0]; AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(simpleParseString, - modelStore, DEFAULT_PREFIX, copyManager, idMap); + modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); assertTrue(result instanceof WithAdditionOperator); assertEquals(EXTERNAL_CUSTOM_ADDITION_URIS[0], ((WithAdditionOperator)result) @@ -361,7 +366,7 @@ public void testExternalLicenseAddition() throws InvalidSPDXAnalysisException { STD_IDS[1] + " WITH " + EXTERNAL_CUSTOM_ADDITION_TOKENS[2] + " AND " + STD_IDS[2] + " WITH " + EXTERNAL_CUSTOM_ADDITION_TOKENS[3]; result = LicenseExpressionParser.parseLicenseExpression(complexParseString, - modelStore, DEFAULT_PREFIX, copyManager, idMap); + modelStore, DEFAULT_PREFIX, creationInfo, copyManager, idMap); assertTrue(result instanceof ConjunctiveLicenseSet); Boolean[] found = new Boolean[] {false, false, false, false}; Collection members = ((ConjunctiveLicenseSet)result).getMembers();