Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ private LicensingRequirements mergeLicenseRequirements(List<LicensingRequirement
*/
protected boolean isDisliked(MavenProject mavenProject) {

if (!licensingRequirements.containsDislikedLicenses()) {
if (!licensingRequirements.containsDislikedLicenses()
&& !licensingRequirements.containsLikedLicenses()) {
return false;
}

Expand All @@ -262,6 +263,14 @@ protected boolean isDisliked(MavenProject mavenProject) {

Set<String> licenses = collectLicensesForMavenProject(mavenProject);

if (licensingRequirements.containsLikedLicenses()) {
for (String license : licenses) {

if (licensingRequirements.isLikedLicense(license))
return false;
}
return true;
}
for (String license : licenses) {

if (!licensingRequirements.isDislikedLicense(license))
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/org/linuxstuff/mojo/licensing/CheckMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public class CheckMojo extends AbstractLicensingMojo {
*/
protected boolean failIfDisliked;

/**
* If using liked licenses, only use those in the report.
*
* @parameter expression="${includeOnlyLikedInReport}" default-value="true"
* @since 1.0
*/
protected boolean includeOnlyLikedInReport;

/**
* Fail the build if any dependencies are either under disliked licenses or
* are missing licensing information.
Expand Down Expand Up @@ -84,7 +92,14 @@ protected LicensingReport generateReport(MavenProject project) {
aReport.addMissingLicense(entry);
} else {
for (String license : licenses) {
entry.addLicense(license);
if (includeOnlyLikedInReport && licensingRequirements.containsLikedLicenses()) {
if (licensingRequirements.isLikedLicense( license )) {
entry.addLicense(license);
}
}
else {
entry.addLicense(license);
}
}

if (isDisliked(mavenProject)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public class LicensingRequirements {
@XStreamImplicit(itemFieldName = "disliked-license")
private Set<String> dislikedLicenses = new HashSet<String>();

@XStreamAlias("liked-licenses")
@XStreamImplicit(itemFieldName = "liked-license")
private Set<String> likedLicenses = new HashSet<String>();

@XStreamAlias("dislike-exemptions")
@XStreamImplicit(itemFieldName = "dislike-exemption")
private Set<String> dislikeExemptions = new HashSet<String>();
Expand All @@ -35,6 +39,10 @@ public void addDislikedLicense(String licenseName) {
dislikedLicenses.add(licenseName);
}

public void addLikedLicense(String licenseName) {
likedLicenses.add(licenseName);
}

public void addDislikeExemption(String artifactId) {
dislikeExemptions.add(artifactId);
}
Expand All @@ -43,6 +51,10 @@ public boolean isDislikedLicense(String license) {
return dislikedLicenses.contains(license);
}

public boolean isLikedLicense(String license) {
return likedLicenses.contains(license);
}

public String getCorrectLicenseName(String name) {
for (CoalescedLicense coalesced : coalescedLicenses) {
if (coalesced.getFinalName().equalsIgnoreCase(name.trim()))
Expand Down Expand Up @@ -79,6 +91,10 @@ public boolean containsDislikedLicenses() {
return !dislikedLicenses.isEmpty();
}

public boolean containsLikedLicenses() {
return !likedLicenses.isEmpty();
}

public Set<ArtifactWithLicenses> getMissingLicenses() {
return missingLicenses;
}
Expand All @@ -91,6 +107,10 @@ public Set<String> getDislikedLicenses() {
return dislikedLicenses;
}

public Set<String> getLikedLicenses() {
return likedLicenses;
}

public Set<String> getDislikeExemptions() {
return dislikeExemptions;
}
Expand All @@ -103,6 +123,12 @@ public void combineWith(LicensingRequirements req) {
}
}

if (req.getLikedLicenses() != null) {
for (String source : req.getLikedLicenses()) {
addLikedLicense(source);
}
}

if (req.getDislikeExemptions() != null) {
for (String source : req.getDislikeExemptions()) {
addDislikeExemption(source);
Expand Down