From f727264fc8945d03ba60d2b3d80f9fb84c3ebcc6 Mon Sep 17 00:00:00 2001 From: Anders Nawroth Date: Thu, 19 Apr 2012 15:49:00 +0200 Subject: [PATCH] Adds liked-license approach to make it easier to handle licenseing requirements. Fixes #5. --- .../mojo/licensing/AbstractLicensingMojo.java | 11 +++++++- .../linuxstuff/mojo/licensing/CheckMojo.java | 17 +++++++++++- .../model/LicensingRequirements.java | 26 +++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/linuxstuff/mojo/licensing/AbstractLicensingMojo.java b/src/main/java/org/linuxstuff/mojo/licensing/AbstractLicensingMojo.java index aaaabbc..f62c6b6 100644 --- a/src/main/java/org/linuxstuff/mojo/licensing/AbstractLicensingMojo.java +++ b/src/main/java/org/linuxstuff/mojo/licensing/AbstractLicensingMojo.java @@ -252,7 +252,8 @@ private LicensingRequirements mergeLicenseRequirements(List 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)) diff --git a/src/main/java/org/linuxstuff/mojo/licensing/CheckMojo.java b/src/main/java/org/linuxstuff/mojo/licensing/CheckMojo.java index a421bd2..443013b 100644 --- a/src/main/java/org/linuxstuff/mojo/licensing/CheckMojo.java +++ b/src/main/java/org/linuxstuff/mojo/licensing/CheckMojo.java @@ -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. @@ -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)) { diff --git a/src/main/java/org/linuxstuff/mojo/licensing/model/LicensingRequirements.java b/src/main/java/org/linuxstuff/mojo/licensing/model/LicensingRequirements.java index 0f720d1..e4f2b5b 100644 --- a/src/main/java/org/linuxstuff/mojo/licensing/model/LicensingRequirements.java +++ b/src/main/java/org/linuxstuff/mojo/licensing/model/LicensingRequirements.java @@ -19,6 +19,10 @@ public class LicensingRequirements { @XStreamImplicit(itemFieldName = "disliked-license") private Set dislikedLicenses = new HashSet(); + @XStreamAlias("liked-licenses") + @XStreamImplicit(itemFieldName = "liked-license") + private Set likedLicenses = new HashSet(); + @XStreamAlias("dislike-exemptions") @XStreamImplicit(itemFieldName = "dislike-exemption") private Set dislikeExemptions = new HashSet(); @@ -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); } @@ -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())) @@ -79,6 +91,10 @@ public boolean containsDislikedLicenses() { return !dislikedLicenses.isEmpty(); } + public boolean containsLikedLicenses() { + return !likedLicenses.isEmpty(); + } + public Set getMissingLicenses() { return missingLicenses; } @@ -91,6 +107,10 @@ public Set getDislikedLicenses() { return dislikedLicenses; } + public Set getLikedLicenses() { + return likedLicenses; + } + public Set getDislikeExemptions() { return dislikeExemptions; } @@ -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);