diff --git a/apache-rat-core/src/main/java/org/apache/rat/analysis/matchers/SPDXMatcherFactory.java b/apache-rat-core/src/main/java/org/apache/rat/analysis/matchers/SPDXMatcherFactory.java index 5b6962782..2fbd7985e 100644 --- a/apache-rat-core/src/main/java/org/apache/rat/analysis/matchers/SPDXMatcherFactory.java +++ b/apache-rat-core/src/main/java/org/apache/rat/analysis/matchers/SPDXMatcherFactory.java @@ -55,11 +55,13 @@ public class SPDXMatcherFactory { */ public static final SPDXMatcherFactory INSTANCE = new SPDXMatcherFactory(); + static final String LICENSE_IDENTIFIER = "SPDX-License-Identifier:"; + /** * The regular expression to locate the SPDX license identifier in the text * stream */ - private static Pattern groupSelector = Pattern.compile(".*SPDX-License-Identifier:\\s([A-Za-z0-9\\.\\-]+)"); + private static Pattern groupSelector = Pattern.compile(".*"+LICENSE_IDENTIFIER+"\\s([A-Za-z0-9\\.\\-]+)"); /** * The last matcer to match the line. @@ -103,21 +105,20 @@ public Match create(String spdxId) { * @return true if the caller matches the text. */ private boolean check(String line, Match caller) { - // if the line has not been seen yet see if we can extract the SPDX id from the - // line. - // if so then see if that name has been registered. If so then we have a match - // and set - // lastMatch. + /* + If the line has not been seen yet see if we can extract the SPDX id from the line. + If so then see for each match extract and add the name to lastMatch + */ if (!checked) { checked = true; - if (line.contains("SPDX-License-Identifier")) { + if (line.contains(LICENSE_IDENTIFIER)) { Matcher matcher = groupSelector.matcher(line); while (matcher.find()) { lastMatch.add(matcher.group(1)); } } } - // see if the caller matches lastMatch. + // see if the caller is in the lastMatch. return lastMatch.contains(caller.spdxId); } diff --git a/apache-rat-core/src/main/java/org/apache/rat/license/LicenseSetFactory.java b/apache-rat-core/src/main/java/org/apache/rat/license/LicenseSetFactory.java index 87b3313cd..9321e32ad 100644 --- a/apache-rat-core/src/main/java/org/apache/rat/license/LicenseSetFactory.java +++ b/apache-rat-core/src/main/java/org/apache/rat/license/LicenseSetFactory.java @@ -77,7 +77,6 @@ public LicenseSetFactory(SortedSet licenses, Collection approv * @return An empty sorted set of ILicense objects. */ public static SortedSet emptyLicenseSet() { - //return new TreeSet<>((a,b) -> a.getLicenseFamily().compareTo(b.getLicenseFamily())); return new TreeSet<>(); } @@ -165,7 +164,6 @@ public SortedSet getLicenseFamilyIds(LicenseFilter filter) { * @return the matching license or {@code null} if not found. */ public static Optional search(String familyId, String licenseId, SortedSet licenses) { - // return licenses.stream().filter( l -> l.getId().equals(licenseId)).findFirst(); ILicenseFamily searchFamily = ILicenseFamily.builder().setLicenseFamilyCategory(familyId) .setLicenseFamilyName("searching proxy").build(); ILicense target = new ILicense() { diff --git a/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SPDXMatcherTest.java b/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SPDXMatcherTest.java index f952103c9..66facc904 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SPDXMatcherTest.java +++ b/apache-rat-core/src/test/java/org/apache/rat/analysis/matchers/SPDXMatcherTest.java @@ -40,8 +40,8 @@ public void setup() { @Test public void testMatch() { StringBuilder sb = new StringBuilder() - .append("SPDX-License-Identifier: world").append(System.lineSeparator()) - .append("SPDX-License-Identifier: hello").append(System.lineSeparator()); + .append(SPDXMatcherFactory.LICENSE_IDENTIFIER).append(" world").append(System.lineSeparator()) + .append(SPDXMatcherFactory.LICENSE_IDENTIFIER).append(" hello").append(System.lineSeparator()); IHeaders headers = AbstractMatcherTest.makeHeaders(sb.toString(),null);