Skip to content

Commit

Permalink
Changes as per review
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudenw committed May 14, 2024
1 parent 3e92e50 commit dfece89
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public LicenseSetFactory(SortedSet<ILicense> licenses, Collection<String> approv
* @return An empty sorted set of ILicense objects.
*/
public static SortedSet<ILicense> emptyLicenseSet() {
//return new TreeSet<>((a,b) -> a.getLicenseFamily().compareTo(b.getLicenseFamily()));
return new TreeSet<>();
}

Expand Down Expand Up @@ -165,7 +164,6 @@ public SortedSet<String> getLicenseFamilyIds(LicenseFilter filter) {
* @return the matching license or {@code null} if not found.
*/
public static Optional<ILicense> search(String familyId, String licenseId, SortedSet<ILicense> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit dfece89

Please sign in to comment.