Skip to content

Commit

Permalink
Add support for SPDX +
Browse files Browse the repository at this point in the history
  • Loading branch information
waynebeaton committed Jun 11, 2020
1 parent 3512922 commit d5f2f51
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ public boolean isAccepted(ClearlyDefinedContentData data) {
}

boolean isDiscoveredLicenseApproved(String license) {
if ("NOASSERTION".equals(license))
return true;
return licenseSupport.getStatus(license) == LicenseSupport.Status.Approved;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public SpdxExpression parse(String expression) {
StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(expression));
tokenizer.ordinaryChar('(');
tokenizer.ordinaryChar(')');
tokenizer.ordinaryChar('+');

return parse(tokenizer);
}
Expand Down Expand Up @@ -62,6 +63,9 @@ private SpdxExpression parse(StreamTokenizer tokenizer) {
break;
case ')':
return expression;
case '+':
expression = new SpdxPlus((SpdxIdentifier) expression);
break;
}
}
} catch (IOException e) {
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/org/eclipse/dash/licenses/spdx/SpdxPlus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*************************************************************************
* Copyright (c) 2020 The Eclipse Foundation and others.
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution, and is available at https://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*************************************************************************/
package org.eclipse.dash.licenses.spdx;

import java.util.Collection;

public class SpdxPlus extends SpdxExpression {
private SpdxIdentifier identifier;

public SpdxPlus(SpdxIdentifier identifier) {
this.identifier = identifier;
}

@Override
public boolean matchesApproved(Collection<String> approved) {
// TODO Implement this
// We need some means of identifying one license as being a later version of
// another.
return identifier.matchesApproved(approved);
}

@Override
public String toString() {
return "(" + identifier.toString() + ")+";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,29 @@ void testExceptionPrecedence4() {
}

@Test
void testMatchSimple() {
assertTrue(new SpdxExpressionParser().parse("EPL-2.0").matchesApproved(Collections.singleton("EPL-2.0")));
void testPlus() {
assertEquals("(EPL-1.0)+", new SpdxExpressionParser().parse("EPL-1.0+").toString());
}

@Test
void testPlusInExpression1() {
assertEquals("(Apache-2.0 OR (EPL-1.0)+)",
new SpdxExpressionParser().parse("Apache-2.0 OR EPL-1.0+").toString());
}

@Test
void testPlusInExpression2() {
assertEquals("((BSD0 AND Apache-2.0) OR (EPL-1.0)+)",
new SpdxExpressionParser().parse("BSD0 AND Apache-2.0 OR EPL-1.0+").toString());
}
}

@Nested
class TestMatching {
@Test
void testMatchSimple() {
assertTrue(new SpdxExpressionParser().parse("EPL-2.0").matchesApproved(Collections.singleton("EPL-2.0")));
}

@Test
void testMatchConjunction() {
Expand Down Expand Up @@ -183,5 +199,22 @@ void testMatchArbitrary() {

assertTrue(new SpdxExpressionParser().parse("EPL-2.0 AND (Apache-2.0 OR BSD0)").matchesApproved(approved));
}

@Test
void testMatchPlus1() {
Set<String> approved = new HashSet<>();
approved.add("EPL-1.0");

assertTrue(new SpdxExpressionParser().parse("EPL-1.0+").matchesApproved(approved));
}

// @Ignore("Not implemented yet.")
// @Test
// void testMatchPlus2() {
// Set<String> approved = new HashSet<>();
// approved.add("EPL-2.0");
//
// assertTrue(new SpdxExpressionParser().parse("EPL-1.0+").matchesApproved(approved));
// }
}
}

0 comments on commit d5f2f51

Please sign in to comment.