Skip to content
Merged
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
85 changes: 85 additions & 0 deletions src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -782,4 +782,89 @@ public static String[] matchingStandardLicenseIds(String licenseText) throws Inv
}
return matchingIds.toArray(new String[matchingIds.size()]);
}

private static <T> boolean contains(
T[] array,
T value
) {
for (T t : array) {
if (Objects.equals(t, value)) {
return true;
}
}
return false;
}

/**
* Detect if a license pass black lists
* @param license license
* @param blackList license black list
* @return if the license pass black lists
* @throws InvalidSPDXAnalysisException
*/
public static boolean isLicensePassBlackList(
AnyLicenseInfo license,
String... blackList
) throws InvalidSPDXAnalysisException {
if (license == null) {
return true;
}
if (blackList == null || blackList.length == 0) {
return true;
}
if (license instanceof ConjunctiveLicenseSet) {
for (AnyLicenseInfo member : ((ConjunctiveLicenseSet) license).getMembers()) {
if (!isLicensePassBlackList(member, blackList)) {
return false;
}
}
return true;
} else if (license instanceof DisjunctiveLicenseSet) {
for (AnyLicenseInfo member : ((DisjunctiveLicenseSet) license).getMembers()) {
if (isLicensePassBlackList(member, blackList)) {
return true;
}
}
return false;
} else {
return !contains(blackList, license.toString());
}
}

/**
* Detect if a license pass white lists
* @param license license
* @param whiteList license white list
* @return if the license pass white lists
* @throws InvalidSPDXAnalysisException
*/
public static boolean isLicensePassWhiteList(
AnyLicenseInfo license,
String... whiteList
) throws InvalidSPDXAnalysisException {
if (license == null) {
return false;
}
if (whiteList == null || whiteList.length == 0) {
return false;
}
if (license instanceof ConjunctiveLicenseSet) {
for (AnyLicenseInfo member : ((ConjunctiveLicenseSet) license).getMembers()) {
if (!isLicensePassWhiteList(member, whiteList)) {
return false;
}
}
return true;
} else if (license instanceof DisjunctiveLicenseSet) {
for (AnyLicenseInfo member : ((DisjunctiveLicenseSet) license).getMembers()) {
if (isLicensePassWhiteList(member, whiteList)) {
return true;
}
}
return false;
} else {
return contains(whiteList, license.toString());
}
}

}