Skip to content

Commit

Permalink
Prefer found licenses when multiple provided
Browse files Browse the repository at this point in the history
Fixes #414
  • Loading branch information
derkoe committed Jan 26, 2024
1 parent 8dc4e1a commit bc5b253
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,27 +237,33 @@ private static Dependency loadLicense(
}

for (License license : licenses) {
licenseMatcher(licenseMap, dependency, license);
boolean found = licenseMatcher(licenseMap, dependency, license);
if (found) {
break;
}
}
}
return dependency;
}

private static void licenseMatcher(
/**
* @return true if license was found in defined license list, false otherwise
*/
private static boolean licenseMatcher(
Map<Pattern, String> licenseMap,
Dependency dependency,
License license
) {
String licenseName = license.getName();
if (StringUtils.isBlank(licenseName)) {
LOGGER.info("Dependency '{}' has an empty license.", dependency.getName());
return;
return false;
}

for (Entry<Pattern, String> entry : licenseMap.entrySet()) {
if (entry.getKey().matcher(licenseName).matches()) {
dependency.setLicense(entry.getValue());
return;
return true;
}
}

Expand All @@ -269,6 +275,8 @@ private static void licenseMatcher(
dependency.getName(),
dependency.getVersion()
);

return false;
}

private static MavenSettings getSettingsFromCommandLineArgs() {
Expand Down

0 comments on commit bc5b253

Please sign in to comment.