From c49bcbf92184a97cea6025ef5bead4b1e062576e Mon Sep 17 00:00:00 2001 From: Remis Baima Date: Sun, 1 May 2022 15:25:29 +0200 Subject: [PATCH] feat: log more details of invalid licenses --- .../remisbaima/cyclonedx/LicenseCheckerMojo.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/remisbaima/cyclonedx/LicenseCheckerMojo.java b/src/main/java/io/github/remisbaima/cyclonedx/LicenseCheckerMojo.java index 5fa1941..e4f0c85 100644 --- a/src/main/java/io/github/remisbaima/cyclonedx/LicenseCheckerMojo.java +++ b/src/main/java/io/github/remisbaima/cyclonedx/LicenseCheckerMojo.java @@ -18,6 +18,7 @@ import org.codehaus.plexus.util.xml.Xpp3Dom; import org.cyclonedx.exception.ParseException; import org.cyclonedx.model.Bom; +import org.cyclonedx.model.License; /** Goal which checks CycloneDX BOM licenses used by dependencies. */ @Mojo(name = "check", defaultPhase = LifecyclePhase.PACKAGE) @@ -47,7 +48,8 @@ public class LicenseCheckerMojo extends AbstractMojo { protected static final String MSG_ERROR_INVALID_JSON_CONFIG = "If is set, must also be set"; protected static final String MSG_ALLOWED_LICENSES = "List of allowed licenses: "; - protected static final String MSG_ERROR_NOT_ALLOWED = "Not allowed license <%s> used by <%s>"; + protected static final String MSG_ERROR_NOT_ALLOWED = + "Not allowed license used by: %1$s%n%5$8s- ID: %2$s%n%5$8s- URL: %3$s%n%5$8s- Name: %4$s"; protected static final String MSG_SUCCESS = "Success: all used licenses are allowed"; protected static final String MSG_SKIPING_DEPENDENCY = "Skipping license check for dependency: "; @@ -88,7 +90,8 @@ public void execute() throws MojoExecutionException { } // check licences - Map nonCompliantDependencies = licenseChecker.checkBom(bom, allowedLicensesSet); + Map nonCompliantDependencies = + licenseChecker.checkBom(bom, allowedLicensesSet); // check dependencies to ignore licenseChecker.checkIgnoredDependencies( @@ -100,8 +103,12 @@ public void execute() throws MojoExecutionException { if (nonCompliantDependencies.isEmpty()) { getLog().info(MSG_SUCCESS); } else { - for (Entry e : nonCompliantDependencies.entrySet()) { - getLog().error(String.format(MSG_ERROR_NOT_ALLOWED, e.getValue(), e.getKey())); + for (Entry e : nonCompliantDependencies.entrySet()) { + License l = e.getValue(); + String errorMsg = + String.format( + MSG_ERROR_NOT_ALLOWED, e.getKey(), l.getId(), l.getUrl(), l.getName(), ""); + getLog().error(errorMsg); } throw new MojoExecutionException(""); }