Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@
<dependency>
<groupId>org.spdx</groupId>
<artifactId>spdx-rdf-store</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.spdx</groupId>
<artifactId>java-spdx-library</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.spdx</groupId>
<artifactId>spdx-v3jsonld-store</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
</dependencies>
<profiles>
Expand Down
57 changes: 3 additions & 54 deletions src/org/spdx/licenselistpublisher/LicenseRDFAGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public static void main(String[] args) {
for (String warning:warnings) {
boolean ignore = false;
for (String ignoreStr:ignoredWarnings) {
if (warning.equalsIgnoreCase(ignoreStr)) {
if (warning.toLowerCase().startsWith(ignoreStr.toLowerCase())) {
ignore = true;
System.out.println("Ignoring warning '"+ignoreStr+"'");
break;
Expand Down Expand Up @@ -597,7 +597,7 @@ private static Set<String> writeLicenseList(String version, String releaseDate,
licenseContainer.getV2ListedLicense().getLicenseText(),
new HashMap<>());
for (Entry<String, String[]> entry : addedLicIdTextMap.entrySet()) {
if (isLicenseTextEquivalent(entry.getValue(), licenseTokens)) {
if (LicenseTextHelper.isLicenseTextEquivalent(entry.getValue(), licenseTokens)) {
warnings.add("Duplicates licenses: " + licenseContainer.getV2ListedLicense().getLicenseId() + ", " + entry.getKey());
}
}
Expand All @@ -624,7 +624,7 @@ private static Set<String> writeLicenseList(String version, String releaseDate,
String[] stdLicenseTokens = LicenseTextHelper.tokenizeLicenseText(
ListedLicenses.getListedLicenses().getListedLicenseByIdCompatV2(stdLicenseId).getLicenseText(),
new HashMap<>());
if (isLicenseTextEquivalent(value, stdLicenseTokens)) {
if (LicenseTextHelper.isLicenseTextEquivalent(value, stdLicenseTokens)) {
warnings.add("Duplicates licenses: " + key + ", " + stdLicenseId);
}
}
Expand All @@ -643,57 +643,6 @@ private static Set<String> writeLicenseList(String version, String releaseDate,
}
}

/**
* Returns true if two sets of license tokens is considered a match per
* the SPDX License matching guidelines documented at spdx.org (currently <a href="https://spdx.github.io/spdx-spec/v2.3/license-matching-guidelines-and-templates/">license matching guidelines</a>)
* There are 2 unimplemented features - bullets/numbering is not considered and comments with no whitespace between text is not skipped
* @param licenseATokens normalized license tokens to compare
* @param licenseBTokens normalized license tokens to compare
* @return true if the license text is equivalent
*/
public static boolean isLicenseTextEquivalent(String[] licenseATokens, String[] licenseBTokens) {
//TODO: Move this to LicenseTextHelper and refactor
int bTokenCounter = 0;
int aTokenCounter = 0;
String nextAToken = LicenseTextHelper.getTokenAt(licenseATokens, aTokenCounter++);
String nextBToken = LicenseTextHelper.getTokenAt(licenseBTokens, bTokenCounter++);
while (nextAToken != null) {
if (nextBToken == null) {
// end of b stream
while (LicenseTextHelper.canSkip(nextAToken)) {
nextAToken = LicenseTextHelper.getTokenAt(licenseATokens, aTokenCounter++);
}
if (nextAToken != null) {
return false; // there is more stuff in the license text B, so not equal
}
} else if (LicenseTextHelper.tokensEquivalent(nextAToken, nextBToken)) {
// just move onto the next set of tokens
nextAToken = LicenseTextHelper.getTokenAt(licenseATokens, aTokenCounter++);
nextBToken = LicenseTextHelper.getTokenAt(licenseBTokens, bTokenCounter++);
} else {
// see if we can skip through some B tokens to find a match
while (LicenseTextHelper.canSkip(nextBToken)) {
nextBToken = LicenseTextHelper.getTokenAt(licenseBTokens, bTokenCounter++);
}
// just to be sure, skip forward on the A license
while (LicenseTextHelper.canSkip(nextAToken)) {
nextAToken = LicenseTextHelper.getTokenAt(licenseATokens, aTokenCounter++);
}
if (!LicenseTextHelper.tokensEquivalent(nextAToken, nextBToken)) {
return false;
} else {
nextAToken = LicenseTextHelper.getTokenAt(licenseATokens, aTokenCounter++);
nextBToken = LicenseTextHelper.getTokenAt(licenseBTokens, bTokenCounter++);
}
}
}
// need to make sure B is at the end
while (LicenseTextHelper.canSkip(nextBToken)) {
nextBToken = LicenseTextHelper.getTokenAt(licenseBTokens, bTokenCounter++);
}
return (nextBToken == null);
}

/**
* Update license fields based on information from external metadata
* @param licenseContainer
Expand Down