From a799c774d2d70ff6820800f0739981b25e4cf919 Mon Sep 17 00:00:00 2001 From: Johann Schmitz Date: Wed, 27 Feb 2019 07:44:23 +0100 Subject: [PATCH 01/11] #201 - Reduce log level for unknown dependencies to debug to reduce log spam when using a shared missing file --- .../org/codehaus/mojo/license/api/DefaultThirdPartyTool.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java index e292e5208..c6d08b9cb 100644 --- a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java +++ b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java @@ -549,7 +549,7 @@ public SortedProperties loadUnsafeMapping( LicenseMap licenseMap, // there is some unknown dependencies in the missing file, remove them for ( String id : unknownDependenciesId ) { - getLogger().warn( + getLogger().debug( "dependency [" + id + "] does not exist in project, remove it from the missing file." ); unsafeMappings.remove( id ); } From f05f7a2b64a8360d0202343633f9dcafa707f7c5 Mon Sep 17 00:00:00 2001 From: Wolfgang Wachsmuth Date: Wed, 26 Feb 2020 18:17:58 +0100 Subject: [PATCH 02/11] reduce log level by parameter --- .../license/AbstractAddThirdPartyMojo.java | 14 +++++++ .../license/AbstractThirdPartyReportMojo.java | 22 ++++++++--- .../mojo/license/AddThirdPartyMojo.java | 2 +- .../license/AggregatorAddThirdPartyMojo.java | 2 +- .../mojo/license/UnkownFileRemedy.java | 30 +++++++++++++++ .../license/api/DefaultThirdPartyHelper.java | 21 +++++----- .../license/api/DefaultThirdPartyTool.java | 38 +++++++++++++++---- .../mojo/license/api/ThirdPartyHelper.java | 17 +++++---- .../mojo/license/api/ThirdPartyTool.java | 6 ++- 9 files changed, 119 insertions(+), 33 deletions(-) create mode 100644 src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java diff --git a/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java index 88a3d66a2..b3c4048f2 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java @@ -600,6 +600,20 @@ public abstract class AbstractAddThirdPartyMojo @Parameter( property = "project.artifacts", required = true, readonly = true ) protected Set dependencies; + + /** + * What to do on defined files not found in project. The possible values are: + *
  • + *
      {@link UnkownFileRemedy#debug}: unkown files are logged debug
    + *
      {@link UnkownFileRemedy#warn}: unkown files are output to the log as warnings
    + *
      {@link UnkownFileRemedy#failFast}: a {@link MojoExecutionException} is thrown on the + * file not found in project
    + *
  • + * @since 2.0.1 + */ + @Parameter( property = "license.unkownFileRemedy", defaultValue = "warn" ) + protected UnkownFileRemedy unkownFileRemedy; + // ---------------------------------------------------------------------- // Plexus components // ---------------------------------------------------------------------- diff --git a/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java index 61c529c90..bacf682c9 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java @@ -229,9 +229,9 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport private String overrideUrl; /** - * A {@link URL} prepared either our of {@link #overrideFile} or {@link #overrideUrl} or the default value. + * A {@link String} prepared either our of {@link #overrideFile} or {@link #overrideUrl} or the default value. * - * @see LicenseMojoUtils#prepareThirdPartyOverrideUrl(URL, File, String, File) + * @see LicenseMojoUtils#prepareThirdPartyOverrideUrl(String, File, String, File) */ String resolvedOverrideUrl; @@ -311,6 +311,19 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport @Parameter( defaultValue = "${project}", readonly = true ) private MavenProject project; + /** + * What to do on defined files not found in project. The possible values are: + *
  • + *
      {@link UnkownFileRemedy#debug}: unkown files are logged debug
    + *
      {@link UnkownFileRemedy#warn}: unkown files are output to the log as warnings
    + *
      {@link UnkownFileRemedy#failFast}: a {@link MojoExecutionException} is thrown on the + * file not found in project
    + *
  • + * @since 2.0.1 + */ + @Parameter( property = "license.unkownFileRemedy", defaultValue = "warn" ) + protected UnkownFileRemedy unkownFileRemedy; + // ---------------------------------------------------------------------- // Plexus Components // ---------------------------------------------------------------------- @@ -385,7 +398,7 @@ protected abstract Collection createThirdPartyDetails() /** * Method to initialize the mojo before doing any concrete actions. * - * Note: The method is invoked before the {@link #executeReport()} method. + * Note: The method is invoked before the {@link #executeReport(Locale)} method. * @throws IOException */ protected void init() @@ -593,7 +606,7 @@ Collection createThirdPartyDetails( MavenProject project, boo // Resolve unsafe dependencies using missing files, this will update licenseMap and unsafeDependencies thirdPartyHelper.createUnsafeMapping( licenseMap, missingFile, missingFileUrl, useRepositoryMissingFiles, dependenciesWithNoLicense, - projectDependencies, loadedDependencies.getAllDependencies() ); + projectDependencies, loadedDependencies.getAllDependencies(), unkownFileRemedy); } } @@ -639,5 +652,4 @@ public String getEncoding() { return encoding; } - } diff --git a/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java index 1e5bec0d5..40f790890 100644 --- a/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java @@ -264,7 +264,7 @@ protected SortedProperties createUnsafeMapping() getHelper().createUnsafeMapping( licenseMap, missingFile, missingFileUrl, useRepositoryMissingFiles, unsafeDependencies, projectDependencies, - resolveDependencyArtifacts().getAllDependencies() ); + resolveDependencyArtifacts().getAllDependencies(), unkownFileRemedy); if ( isVerbose() ) { LOG.info( "found {} unsafe mappings", unsafeMappings.size() ); diff --git a/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java index 2c5745e0c..2a5f14cdf 100644 --- a/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java @@ -314,7 +314,7 @@ protected SortedProperties createUnsafeMapping() if ( file.exists() ) { - SortedProperties tmp = getHelper().loadUnsafeMapping( licenseMap, file, null, projectDependencies ); + SortedProperties tmp = getHelper().loadUnsafeMapping( licenseMap, file, null, projectDependencies, unkownFileRemedy ); unsafeMappings.putAll( tmp ); } diff --git a/src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java b/src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java new file mode 100644 index 000000000..ed2039029 --- /dev/null +++ b/src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java @@ -0,0 +1,30 @@ +/****************************************************************************** + * COMINTO GmbH + * Klosterstr. 49 + * 40211 Düsseldorf + * Germany + * + * (c) Copyright 2020 by COMINTO GmbH + * ALL RIGHTS RESERVED + * + ******************************************************************************/ +package org.codehaus.mojo.license; + +import org.apache.maven.plugin.MojoExecutionException; + +/** + * What to do in case of a file not found in project. + * + * @since 2.0.1 + */ +public enum UnkownFileRemedy +{ + /** Unkown files will be logged debug */ + debug, + /** Unkown files are output to the log as warnings */ + warn, + /** + * The first encountered unkown file is logged and a {@link MojoExecutionException} is thrown + */ + failFast, +} \ No newline at end of file diff --git a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyHelper.java b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyHelper.java index a0c5ec70b..45fd6ede6 100644 --- a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyHelper.java +++ b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyHelper.java @@ -29,6 +29,7 @@ import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuildingException; +import org.codehaus.mojo.license.UnkownFileRemedy; import org.codehaus.mojo.license.model.LicenseMap; import org.codehaus.mojo.license.utils.SortedProperties; @@ -169,12 +170,13 @@ public SortedProperties loadThirdPartyDescriptorForUnsafeMapping( Set /** * {@inheritDoc} */ - public SortedProperties loadUnsafeMapping( LicenseMap licenseMap, File missingFile, String missingFileUrl, - SortedMap projectDependencies ) + public SortedProperties loadUnsafeMapping(LicenseMap licenseMap, File missingFile, String missingFileUrl, + SortedMap projectDependencies, + UnkownFileRemedy unkownFileRemedy) throws IOException, MojoExecutionException { return thirdPartyTool.loadUnsafeMapping( licenseMap, projectDependencies, encoding, missingFile, - missingFileUrl ); + missingFileUrl, unkownFileRemedy ); } /** @@ -213,16 +215,17 @@ public SortedSet getProjectsWithNoLicense( LicenseMap licenseMap ) /** * {@inheritDoc} */ - public SortedProperties createUnsafeMapping( LicenseMap licenseMap, File missingFile, String missingFileUrl, - boolean useRepositoryMissingFiles, - SortedSet unsafeDependencies, - SortedMap projectDependencies, - Set dependencyArtifacts ) + public SortedProperties createUnsafeMapping(LicenseMap licenseMap, File missingFile, String missingFileUrl, + boolean useRepositoryMissingFiles, + SortedSet unsafeDependencies, + SortedMap projectDependencies, + Set dependencyArtifacts, + UnkownFileRemedy unkownFileRemedy) throws ProjectBuildingException, IOException, ThirdPartyToolException, MojoExecutionException { SortedProperties unsafeMappings = loadUnsafeMapping( licenseMap, missingFile, missingFileUrl, - projectDependencies ); + projectDependencies, unkownFileRemedy); if ( CollectionUtils.isNotEmpty( unsafeDependencies ) ) { diff --git a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java index 966aa7ed1..ab9f17f19 100644 --- a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java +++ b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java @@ -52,6 +52,7 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; import org.codehaus.mojo.license.LicenseMojoUtils; +import org.codehaus.mojo.license.UnkownFileRemedy; import org.codehaus.mojo.license.model.LicenseMap; import org.codehaus.mojo.license.utils.FileUtil; import org.codehaus.mojo.license.utils.MojoHelper; @@ -450,11 +451,13 @@ public void mergeLicenses( LicenseMap licenseMap, String mainLicense, Set artifactCache, - String encoding, - File missingFile, - String missingFileUrl ) throws IOException, MojoExecutionException + public SortedProperties loadUnsafeMapping(LicenseMap licenseMap, + SortedMap artifactCache, + String encoding, + File missingFile, + String missingFileUrl, + UnkownFileRemedy unkownFileRemedy) + throws IOException, MojoExecutionException { Map snapshots = new HashMap<>(); @@ -536,8 +539,7 @@ public SortedProperties loadUnsafeMapping( LicenseMap licenseMap, // there is some unknown dependencies in the missing file, remove them for ( String id : unknownDependenciesId ) { - LOG.warn( - "dependency [{}] does not exist in project, remove it from the missing file.", id ); + handleUnkownDependency(unkownFileRemedy,"dependency [" + id + "] does not exist in project, remove it from the missing file."); unsafeMappings.remove( id ); } @@ -552,7 +554,7 @@ public SortedProperties loadUnsafeMapping( LicenseMap licenseMap, MavenProject project = artifactCache.get( id ); if ( project == null ) { - LOG.warn( "dependency [{}] does not exist in project.", id ); + handleUnkownDependency(unkownFileRemedy, "dependency [" + id + "] does not exist in project." ); continue; } @@ -594,6 +596,26 @@ public SortedProperties loadUnsafeMapping( LicenseMap licenseMap, return unsafeMappings; } + private void handleUnkownDependency(final UnkownFileRemedy unkownFileRemedy, final String message) + throws MojoExecutionException { + + switch ( unkownFileRemedy ) + { + case debug: + LOG.debug( message ); + break; + case failFast: + throw new MojoExecutionException(message); + case warn: + LOG.warn( message ); + break; + default: + throw new IllegalStateException( "Unexpected value of " + UnkownFileRemedy.class.getName() + ": " + + unkownFileRemedy ); + } + + } + /** * {@inheritDoc} */ diff --git a/src/main/java/org/codehaus/mojo/license/api/ThirdPartyHelper.java b/src/main/java/org/codehaus/mojo/license/api/ThirdPartyHelper.java index 4f6c9ced2..48a389950 100644 --- a/src/main/java/org/codehaus/mojo/license/api/ThirdPartyHelper.java +++ b/src/main/java/org/codehaus/mojo/license/api/ThirdPartyHelper.java @@ -27,6 +27,7 @@ import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuildingException; +import org.codehaus.mojo.license.UnkownFileRemedy; import org.codehaus.mojo.license.model.LicenseMap; import org.codehaus.mojo.license.utils.SortedProperties; @@ -86,11 +87,12 @@ SortedProperties loadThirdPartyDescriptorForUnsafeMapping( Set topLeve * resource hoster and that will be merged with the content of the missing file. * @param projectDependencies project dependencies used to detect which dependencies in the missing file * are unknown to the project. + * @param unkownFileRemedy * @return the map of all unsafe mapping * @throws IOException if could not load missing file */ - SortedProperties loadUnsafeMapping( LicenseMap licenseMap, File missingFile, String missingFileUrl, - SortedMap projectDependencies ) + SortedProperties loadUnsafeMapping(LicenseMap licenseMap, File missingFile, String missingFileUrl, + SortedMap projectDependencies, final UnkownFileRemedy unkownFileRemedy) throws IOException, MojoExecutionException; /** @@ -147,16 +149,17 @@ SortedProperties loadUnsafeMapping( LicenseMap licenseMap, File missingFile, Str * @param unsafeDependencies all unsafe dependencies * @param projectDependencies all project dependencies * @param dependencyArtifacts all project dependency artifacts + * @param unkownFileRemedy * @return the loaded unsafe mapping * @throws ProjectBuildingException if could not build some dependencies maven project * @throws IOException if could not load missing file * @throws ThirdPartyToolException if pb with third-party tool */ - SortedProperties createUnsafeMapping( LicenseMap licenseMap, File missingFile, String missingFileUrl, - boolean useRepositoryMissingFiles, - SortedSet unsafeDependencies, - SortedMap projectDependencies, - Set dependencyArtifacts ) + SortedProperties createUnsafeMapping(LicenseMap licenseMap, File missingFile, String missingFileUrl, + boolean useRepositoryMissingFiles, + SortedSet unsafeDependencies, + SortedMap projectDependencies, + Set dependencyArtifacts, final UnkownFileRemedy unkownFileRemedy) throws ProjectBuildingException, IOException, ThirdPartyToolException, MojoExecutionException; /** diff --git a/src/main/java/org/codehaus/mojo/license/api/ThirdPartyTool.java b/src/main/java/org/codehaus/mojo/license/api/ThirdPartyTool.java index 8ce799e2d..6077262bf 100644 --- a/src/main/java/org/codehaus/mojo/license/api/ThirdPartyTool.java +++ b/src/main/java/org/codehaus/mojo/license/api/ThirdPartyTool.java @@ -26,6 +26,7 @@ import org.apache.maven.model.License; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; +import org.codehaus.mojo.license.UnkownFileRemedy; import org.codehaus.mojo.license.model.LicenseMap; import org.codehaus.mojo.license.utils.SortedProperties; @@ -138,11 +139,12 @@ File resolveMissingLicensesDescriptor( String groupId, String artifactId, String * @param missingFile location of the optional missing file * @param missingFileUrl location of an optional missing file extension that can be downloaded from some * resource hoster and that will be merged with the content of the missing file. + * @param unkownFileRemedy * @return the unsafe mapping * @throws IOException if pb while reading missing file */ - SortedProperties loadUnsafeMapping( LicenseMap licenseMap, SortedMap artifactCache, - String encoding, File missingFile, String missingFileUrl ) + SortedProperties loadUnsafeMapping(LicenseMap licenseMap, SortedMap artifactCache, + String encoding, File missingFile, String missingFileUrl, final UnkownFileRemedy unkownFileRemedy) throws IOException, MojoExecutionException; /** From 5d542377e9fc91621c64900b4b756ed0fc24cc73 Mon Sep 17 00:00:00 2001 From: Wolfgang Wachsmuth Date: Thu, 27 Feb 2020 14:16:20 +0100 Subject: [PATCH 03/11] fix license javaDoc --- .../mojo/license/UnkownFileRemedy.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java b/src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java index ed2039029..01d8e80e7 100644 --- a/src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java +++ b/src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java @@ -1,14 +1,26 @@ -/****************************************************************************** - * COMINTO GmbH - * Klosterstr. 49 - * 40211 Düsseldorf - * Germany +package org.codehaus.mojo.license; + +/* + * #%L + * License Maven Plugin + * %% + * Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit, Tony chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * - * (c) Copyright 2020 by COMINTO GmbH - * ALL RIGHTS RESERVED + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. * - ******************************************************************************/ -package org.codehaus.mojo.license; + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ import org.apache.maven.plugin.MojoExecutionException; From ce39c035effc97078bb994a244eb63a8724b1b73 Mon Sep 17 00:00:00 2001 From: Wolfgang Wachsmuth Date: Thu, 27 Feb 2020 14:17:03 +0100 Subject: [PATCH 04/11] make postbuild comparisons runnable under windows --- src/it/ISSUE-154/postbuild.groovy | 4 ++-- src/it/ISSUE-80/postbuild.groovy | 2 +- .../postbuild.groovy | 16 ++++++++-------- .../postbuild.groovy | 6 +++--- src/it/download-licenses-force/postbuild.groovy | 4 ++-- src/it/download-licenses-proxy/postbuild.groovy | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/it/ISSUE-154/postbuild.groovy b/src/it/ISSUE-154/postbuild.groovy index ec843b266..7c57fef25 100644 --- a/src/it/ISSUE-154/postbuild.groovy +++ b/src/it/ISSUE-154/postbuild.groovy @@ -22,8 +22,8 @@ file = new File(basedir, 'target/licenses.xml'); expectedFile = new File(basedir, 'expected_licenses.xml'); -assert expectedFile.text.equals(file.text); +assert expectedFile.text.equals(file.text.replace("\r\n", "\n").replace('\r', '\n')); licenseFile = new File(basedir, 'target/generated-resources/licenses/public domain - alternative.txt'); expectedLicenseTxt = new File(basedir, 'src/alternative.txt'); -assert expectedLicenseTxt.text.equals(licenseFile.text); +assert expectedLicenseTxt.text.equals(licenseFile.text.replace("\r\n", "\n").replace('\r', '\n')); diff --git a/src/it/ISSUE-80/postbuild.groovy b/src/it/ISSUE-80/postbuild.groovy index 9419f31c3..6caead01f 100644 --- a/src/it/ISSUE-80/postbuild.groovy +++ b/src/it/ISSUE-80/postbuild.groovy @@ -22,5 +22,5 @@ file = new File(basedir, 'target/licenses.xml'); expectedFile = new File(basedir, 'expected_licenses.xml'); -assert expectedFile.text.equals(file.text); +assert expectedFile.text.equals(file.text.replace("\r\n", "\n").replace('\r', '\n')); return true; \ No newline at end of file diff --git a/src/it/download-licenses-configured/postbuild.groovy b/src/it/download-licenses-configured/postbuild.groovy index 9a34c32e2..bf0cf3c3b 100644 --- a/src/it/download-licenses-configured/postbuild.groovy +++ b/src/it/download-licenses-configured/postbuild.groovy @@ -39,7 +39,7 @@ return { final Path expectedLicensesXml = basePath.resolve('licenses-'+ id +'.expected.xml') final Path licensesXml = outputBase.resolve('licenses.xml') - assert expectedLicensesXml.text.equals(licensesXml.text) + assert expectedLicensesXml.text.equals(licensesXml.text.replace("\r\n", "\n").replace('\r', '\n')) return true }() && { final String id = 'since-1.18' @@ -55,7 +55,7 @@ return { final Path expectedLicensesXml = basePath.resolve('licenses-'+ id +'.expected.xml') final Path licensesXml = outputBase.resolve('licenses.xml') - assert expectedLicensesXml.text.equals(licensesXml.text) + assert expectedLicensesXml.text.equals(licensesXml.text.replace("\r\n", "\n").replace('\r', '\n')) return true }() && { final String id = 'artifact-filters-url' @@ -66,7 +66,7 @@ return { final Path expectedLicensesXml = basePath.resolve('licenses-'+ id +'.expected.xml') final Path licensesXml = outputBase.resolve('licenses.xml') - assert expectedLicensesXml.text.equals(licensesXml.text) + assert expectedLicensesXml.text.equals(licensesXml.text.replace("\r\n", "\n").replace('\r', '\n')) return true }() && { final String id = 'no-download' @@ -82,7 +82,7 @@ return { final Path expectedLicensesXml = basePath.resolve('licenses-'+ id +'.expected.xml') final Path licensesXml = outputBase.resolve('licenses.xml') - assert expectedLicensesXml.text.equals(licensesXml.text) + assert expectedLicensesXml.text.equals(licensesXml.text.replace("\r\n", "\n").replace('\r', '\n')) return true }() && { final String id = 'delete-orphans' @@ -101,7 +101,7 @@ return { final Path expectedLicensesXml = basePath.resolve('licenses-'+ id +'.expected.xml') final Path licensesXml = outputBase.resolve('licenses.xml') - assert expectedLicensesXml.text.equals(licensesXml.text) + assert expectedLicensesXml.text.equals(licensesXml.text.replace("\r\n", "\n").replace('\r', '\n')) return true }() && { final String id = 'insert-versions' @@ -109,7 +109,7 @@ return { final Path expectedLicensesXml = basePath.resolve('licenses-'+ id +'.expected.xml') final Path licensesXml = outputBase.resolve('licenses.xml') - assert expectedLicensesXml.text.equals(licensesXml.text) + assert expectedLicensesXml.text.equals(licensesXml.text.replace("\r\n", "\n").replace('\r', '\n')) return true }() && { final String id = 'content-sanitizers' @@ -118,12 +118,12 @@ return { final Path asl2 = outputBase.resolve('licenses/apache-license-2.0-apache-2.0.txt') assert Files.exists(asl2) final Path expectedAsl2 = basePath.resolve('src/license/'+ id +'/apache-2.0.expected.txt') - assert expectedAsl2.text.equals(asl2.text) + assert expectedAsl2.text.equals(asl2.text.replace("\r\n", "\n").replace('\r', '\n')) final Path bsdAsm = outputBase.resolve('licenses/bsd-3-clause-asm-bsd3-asm.txt') assert Files.exists(bsdAsm) final Path expectedBsdAsm = basePath.resolve('src/license/'+ id +'/bsd3-asm.expected.txt') - assert expectedBsdAsm.text.equals(bsdAsm.text) + assert expectedBsdAsm.text.equals(bsdAsm.text.replace("\r\n", "\n").replace('\r', '\n')) return true }() diff --git a/src/it/download-licenses-file-names/postbuild.groovy b/src/it/download-licenses-file-names/postbuild.groovy index fc70ca6ef..147a71cd2 100644 --- a/src/it/download-licenses-file-names/postbuild.groovy +++ b/src/it/download-licenses-file-names/postbuild.groovy @@ -47,7 +47,7 @@ return { final Path expectedLicensesXml = basePath.resolve('licenses-'+ id +'.expected.xml') final Path licensesXml = outputBase.resolve('licenses.xml') - assert expectedLicensesXml.text.equals(licensesXml.text) + assert expectedLicensesXml.text.equals(licensesXml.text.replace("\r\n", "\n").replace('\r', '\n')) return true }() && { final String id = 'spdx' @@ -67,7 +67,7 @@ return { final Path expectedLicensesXml = basePath.resolve('licenses-'+ id +'.expected.xml') final Path licensesXml = outputBase.resolve('licenses.xml') - assert expectedLicensesXml.text.equals(licensesXml.text) + assert expectedLicensesXml.text.equals(licensesXml.text.replace("\r\n", "\n").replace('\r', '\n')) return true }() && { @@ -89,7 +89,7 @@ return { final Path expectedLicensesXml = basePath.resolve('licenses-'+ id +'.expected.xml') final Path licensesXml = outputBase.resolve('licenses.xml') - assert expectedLicensesXml.text.equals(licensesXml.text) + assert expectedLicensesXml.text.equals(licensesXml.text.replace("\r\n", "\n").replace('\r', '\n')) final Path foo = basePath.resolve('target/cleanLicDir/licenses/foo.txt') assert !Files.exists(foo) diff --git a/src/it/download-licenses-force/postbuild.groovy b/src/it/download-licenses-force/postbuild.groovy index 7294695c5..b118f0d83 100644 --- a/src/it/download-licenses-force/postbuild.groovy +++ b/src/it/download-licenses-force/postbuild.groovy @@ -36,11 +36,11 @@ assert lgpl21.text.contains('Version 2.1, February 1999') final Path expectedLicensesXml = basePath.resolve('licenses.expected.xml') final Path licensesXml = basePath.resolve('target/generated-resources/licenses.xml') -assert expectedLicensesXml.text.equals(licensesXml.text) +assert expectedLicensesXml.text.equals(licensesXml.text.replace("\r\n", "\n").replace('\r', '\n')) final Path expectedLicensesErrorsXml = basePath.resolve('licenses-errors.expected.xml') final Path licensesErrorsXml = basePath.resolve('target/generated-resources/licenses-errors.xml') -assert expectedLicensesErrorsXml.text.equals(licensesErrorsXml.text) +assert expectedLicensesErrorsXml.text.equals(licensesErrorsXml.text.replace("\r\n", "\n").replace('\r', '\n')) final Path log = basePath.resolve('build.log') assert Files.exists(log) diff --git a/src/it/download-licenses-proxy/postbuild.groovy b/src/it/download-licenses-proxy/postbuild.groovy index 04a6e8896..1efbe1133 100644 --- a/src/it/download-licenses-proxy/postbuild.groovy +++ b/src/it/download-licenses-proxy/postbuild.groovy @@ -31,4 +31,4 @@ assert asl2.text.contains('Proxied via LittleProxy') final Path expectedLicensesXml = basePath.resolve('licenses.expected.xml') final Path licensesXml = basePath.resolve('target/generated-resources/licenses.xml') -assert expectedLicensesXml.text.equals(licensesXml.text) +assert expectedLicensesXml.text.equals(licensesXml.text.replace("\r\n", "\n").replace('\r', '\n')) From 74bac01bd06aa7197a5b36f3242f5ab76900894a Mon Sep 17 00:00:00 2001 From: Wolfgang Wachsmuth Date: Thu, 27 Feb 2020 14:17:53 +0100 Subject: [PATCH 05/11] also use unkownFileRemedy when unkown dependency in use --- .../codehaus/mojo/license/AbstractAddThirdPartyMojo.java | 5 ++--- .../mojo/license/AbstractThirdPartyReportMojo.java | 2 +- .../codehaus/mojo/license/api/DefaultThirdPartyTool.java | 8 ++++---- .../org/codehaus/mojo/license/api/ThirdPartyTool.java | 6 ++++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java index b3c4048f2..a5436e02e 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java @@ -1086,9 +1086,8 @@ void writeThirdPartyFile() } } - void overrideLicenses() throws IOException - { - thirdPartyTool.overrideLicenses( licenseMap, projectDependencies, getEncoding(), resolvedOverrideUrl ); + void overrideLicenses() throws IOException, MojoExecutionException { + thirdPartyTool.overrideLicenses( licenseMap, projectDependencies, getEncoding(), resolvedOverrideUrl, unkownFileRemedy ); } private boolean isFailOnMissing() diff --git a/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java index bacf682c9..9a2d8c214 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java @@ -614,7 +614,7 @@ Collection createThirdPartyDetails( MavenProject project, boo thirdPartyHelper.mergeLicenses( licenseMerges, licenseMap ); // Add override licenses - thirdPartyTool.overrideLicenses( licenseMap, projectDependencies, encoding, resolvedOverrideUrl ); + thirdPartyTool.overrideLicenses( licenseMap, projectDependencies, encoding, resolvedOverrideUrl, unkownFileRemedy); // let's build third party details for each dependencies Collection details = new ArrayList<>(); diff --git a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java index ab9f17f19..7fb503417 100644 --- a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java +++ b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java @@ -619,9 +619,9 @@ private void handleUnkownDependency(final UnkownFileRemedy unkownFileRemedy, fin /** * {@inheritDoc} */ - public void overrideLicenses( LicenseMap licenseMap, SortedMap artifactCache, String encoding, - String overrideUrl ) throws IOException - { + public void overrideLicenses(LicenseMap licenseMap, SortedMap artifactCache, String encoding, + String overrideUrl, final UnkownFileRemedy unkownFileRemedy) + throws IOException, MojoExecutionException { if ( LicenseMojoUtils.isValid( overrideUrl ) ) { final SortedProperties overrideMappings = new SortedProperties( encoding ); @@ -636,7 +636,7 @@ public void overrideLicenses( LicenseMap licenseMap, SortedMap artifactCache, String encoding, - String overrideUrl ) throws IOException; + void overrideLicenses(LicenseMap licenseMap, SortedMap artifactCache, String encoding, + String overrideUrl, final UnkownFileRemedy unkownFileRemedy) + throws IOException, MojoExecutionException; /** * Add one or more licenses (name and url are {@code licenseNames}) to the given {@code licenseMap} for the given From c218bd2967d2164dd7ae1aaeed7bcc933bf47b7d Mon Sep 17 00:00:00 2001 From: Wolfgang Wachsmuth Date: Thu, 27 Feb 2020 14:41:43 +0100 Subject: [PATCH 06/11] respect checkstyle --- .../license/AbstractAddThirdPartyMojo.java | 9 +++-- .../license/AbstractThirdPartyReportMojo.java | 8 +++-- .../mojo/license/AddThirdPartyMojo.java | 2 +- .../license/AggregatorAddThirdPartyMojo.java | 3 +- .../license/api/DefaultThirdPartyHelper.java | 28 +++++++++------ .../license/api/DefaultThirdPartyTool.java | 35 +++++++++++-------- .../mojo/license/api/ThirdPartyHelper.java | 17 ++++----- .../mojo/license/api/ThirdPartyTool.java | 9 ++--- 8 files changed, 63 insertions(+), 48 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java index a5436e02e..a45f338df 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java @@ -881,7 +881,8 @@ protected ThirdPartyHelper getHelper() { helper = new DefaultThirdPartyHelper( getProject(), getEncoding(), isVerbose(), dependenciesTool, thirdPartyTool, getProject().getRemoteArtifactRepositories(), - getProject().getRemoteProjectRepositories() ); + getProject().getRemoteProjectRepositories(), + unkownFileRemedy ); } return helper; } @@ -1086,8 +1087,10 @@ void writeThirdPartyFile() } } - void overrideLicenses() throws IOException, MojoExecutionException { - thirdPartyTool.overrideLicenses( licenseMap, projectDependencies, getEncoding(), resolvedOverrideUrl, unkownFileRemedy ); + void overrideLicenses() throws IOException, MojoExecutionException + { + thirdPartyTool.overrideLicenses( licenseMap, projectDependencies, getEncoding(), resolvedOverrideUrl, + unkownFileRemedy ); } private boolean isFailOnMissing() diff --git a/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java index 9a2d8c214..579356a60 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReportMojo.java @@ -580,7 +580,8 @@ Collection createThirdPartyDetails( MavenProject project, boo ThirdPartyHelper thirdPartyHelper = new DefaultThirdPartyHelper( project, encoding, verbose, dependenciesTool, thirdPartyTool, - project.getRemoteArtifactRepositories(), project.getRemoteProjectRepositories() ); + project.getRemoteArtifactRepositories(), project.getRemoteProjectRepositories(), + unkownFileRemedy ); // load dependencies of the project SortedMap projectDependencies = thirdPartyHelper.loadDependencies( this, loadedDependencies ); @@ -606,7 +607,7 @@ Collection createThirdPartyDetails( MavenProject project, boo // Resolve unsafe dependencies using missing files, this will update licenseMap and unsafeDependencies thirdPartyHelper.createUnsafeMapping( licenseMap, missingFile, missingFileUrl, useRepositoryMissingFiles, dependenciesWithNoLicense, - projectDependencies, loadedDependencies.getAllDependencies(), unkownFileRemedy); + projectDependencies, loadedDependencies.getAllDependencies() ); } } @@ -614,7 +615,8 @@ Collection createThirdPartyDetails( MavenProject project, boo thirdPartyHelper.mergeLicenses( licenseMerges, licenseMap ); // Add override licenses - thirdPartyTool.overrideLicenses( licenseMap, projectDependencies, encoding, resolvedOverrideUrl, unkownFileRemedy); + thirdPartyTool.overrideLicenses( licenseMap, projectDependencies, encoding, resolvedOverrideUrl, + unkownFileRemedy ); // let's build third party details for each dependencies Collection details = new ArrayList<>(); diff --git a/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java index 40f790890..1e5bec0d5 100644 --- a/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java @@ -264,7 +264,7 @@ protected SortedProperties createUnsafeMapping() getHelper().createUnsafeMapping( licenseMap, missingFile, missingFileUrl, useRepositoryMissingFiles, unsafeDependencies, projectDependencies, - resolveDependencyArtifacts().getAllDependencies(), unkownFileRemedy); + resolveDependencyArtifacts().getAllDependencies() ); if ( isVerbose() ) { LOG.info( "found {} unsafe mappings", unsafeMappings.size() ); diff --git a/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java index 2a5f14cdf..2334851a2 100644 --- a/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java @@ -314,7 +314,8 @@ protected SortedProperties createUnsafeMapping() if ( file.exists() ) { - SortedProperties tmp = getHelper().loadUnsafeMapping( licenseMap, file, null, projectDependencies, unkownFileRemedy ); + SortedProperties tmp = getHelper().loadUnsafeMapping( licenseMap, file, null, + projectDependencies ); unsafeMappings.putAll( tmp ); } diff --git a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyHelper.java b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyHelper.java index 45fd6ede6..10d115b9e 100644 --- a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyHelper.java +++ b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyHelper.java @@ -84,6 +84,11 @@ public class DefaultThirdPartyHelper */ private final List remoteRepositories; + /** + * how to handle unknown files + */ + private final UnkownFileRemedy unkownFileRemedy; + /** * Current maven project. */ @@ -114,12 +119,14 @@ public class DefaultThirdPartyHelper * @param thirdPartyTool tool to load third-parties descriptors * @param remoteRepositoriesCoreApi maven remote repositories, in the core api format * @param remoteRepositories maven remote repositories + * @param unkownFileRemedy how to react if a file or dependency is declared but not in project */ // CHECKSTYLE_OFF: ParameterNumber public DefaultThirdPartyHelper( MavenProject project, String encoding, boolean verbose, DependenciesTool dependenciesTool, ThirdPartyTool thirdPartyTool, List remoteRepositoriesCoreApi, - List remoteRepositories ) + List remoteRepositories, + UnkownFileRemedy unkownFileRemedy ) { // CHECKSTYLE_ON: ParameterNumber this.project = project; @@ -129,6 +136,7 @@ public DefaultThirdPartyHelper( MavenProject project, String encoding, boolean v this.thirdPartyTool = thirdPartyTool; this.remoteRepositoriesCoreApi = remoteRepositoriesCoreApi; this.remoteRepositories = remoteRepositories; + this.unkownFileRemedy = unkownFileRemedy; this.thirdPartyTool.setVerbose( verbose ); } @@ -170,9 +178,8 @@ public SortedProperties loadThirdPartyDescriptorForUnsafeMapping( Set /** * {@inheritDoc} */ - public SortedProperties loadUnsafeMapping(LicenseMap licenseMap, File missingFile, String missingFileUrl, - SortedMap projectDependencies, - UnkownFileRemedy unkownFileRemedy) + public SortedProperties loadUnsafeMapping( LicenseMap licenseMap, File missingFile, String missingFileUrl, + SortedMap projectDependencies ) throws IOException, MojoExecutionException { return thirdPartyTool.loadUnsafeMapping( licenseMap, projectDependencies, encoding, missingFile, @@ -215,17 +222,16 @@ public SortedSet getProjectsWithNoLicense( LicenseMap licenseMap ) /** * {@inheritDoc} */ - public SortedProperties createUnsafeMapping(LicenseMap licenseMap, File missingFile, String missingFileUrl, - boolean useRepositoryMissingFiles, - SortedSet unsafeDependencies, - SortedMap projectDependencies, - Set dependencyArtifacts, - UnkownFileRemedy unkownFileRemedy) + public SortedProperties createUnsafeMapping( LicenseMap licenseMap, File missingFile, String missingFileUrl, + boolean useRepositoryMissingFiles, + SortedSet unsafeDependencies, + SortedMap projectDependencies, + Set dependencyArtifacts ) throws ProjectBuildingException, IOException, ThirdPartyToolException, MojoExecutionException { SortedProperties unsafeMappings = loadUnsafeMapping( licenseMap, missingFile, missingFileUrl, - projectDependencies, unkownFileRemedy); + projectDependencies ); if ( CollectionUtils.isNotEmpty( unsafeDependencies ) ) { diff --git a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java index 7fb503417..4da89ffba 100644 --- a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java +++ b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java @@ -451,12 +451,12 @@ public void mergeLicenses( LicenseMap licenseMap, String mainLicense, Set artifactCache, - String encoding, - File missingFile, - String missingFileUrl, - UnkownFileRemedy unkownFileRemedy) + public SortedProperties loadUnsafeMapping( LicenseMap licenseMap, + SortedMap artifactCache, + String encoding, + File missingFile, + String missingFileUrl, + UnkownFileRemedy unkownFileRemedy ) throws IOException, MojoExecutionException { Map snapshots = new HashMap<>(); @@ -539,7 +539,8 @@ public SortedProperties loadUnsafeMapping(LicenseMap licenseMap, // there is some unknown dependencies in the missing file, remove them for ( String id : unknownDependenciesId ) { - handleUnkownDependency(unkownFileRemedy,"dependency [" + id + "] does not exist in project, remove it from the missing file."); + handleUnkownDependency( unkownFileRemedy, "dependency [" + id + + "] does not exist in project, remove it from the missing file." ); unsafeMappings.remove( id ); } @@ -554,7 +555,7 @@ public SortedProperties loadUnsafeMapping(LicenseMap licenseMap, MavenProject project = artifactCache.get( id ); if ( project == null ) { - handleUnkownDependency(unkownFileRemedy, "dependency [" + id + "] does not exist in project." ); + handleUnkownDependency( unkownFileRemedy, "dependency [" + id + "] does not exist in project." ); continue; } @@ -596,8 +597,9 @@ public SortedProperties loadUnsafeMapping(LicenseMap licenseMap, return unsafeMappings; } - private void handleUnkownDependency(final UnkownFileRemedy unkownFileRemedy, final String message) - throws MojoExecutionException { + private void handleUnkownDependency( final UnkownFileRemedy unkownFileRemedy, final String message ) + throws MojoExecutionException + { switch ( unkownFileRemedy ) { @@ -605,7 +607,7 @@ private void handleUnkownDependency(final UnkownFileRemedy unkownFileRemedy, fin LOG.debug( message ); break; case failFast: - throw new MojoExecutionException(message); + throw new MojoExecutionException( message ); case warn: LOG.warn( message ); break; @@ -619,9 +621,11 @@ private void handleUnkownDependency(final UnkownFileRemedy unkownFileRemedy, fin /** * {@inheritDoc} */ - public void overrideLicenses(LicenseMap licenseMap, SortedMap artifactCache, String encoding, - String overrideUrl, final UnkownFileRemedy unkownFileRemedy) - throws IOException, MojoExecutionException { + public void overrideLicenses( LicenseMap licenseMap, SortedMap artifactCache, + String encoding, String overrideUrl, + UnkownFileRemedy unkownFileRemedy ) + throws IOException, MojoExecutionException + { if ( LicenseMojoUtils.isValid( overrideUrl ) ) { final SortedProperties overrideMappings = new SortedProperties( encoding ); @@ -636,7 +640,8 @@ public void overrideLicenses(LicenseMap licenseMap, SortedMap topLeve * resource hoster and that will be merged with the content of the missing file. * @param projectDependencies project dependencies used to detect which dependencies in the missing file * are unknown to the project. - * @param unkownFileRemedy * @return the map of all unsafe mapping * @throws IOException if could not load missing file */ - SortedProperties loadUnsafeMapping(LicenseMap licenseMap, File missingFile, String missingFileUrl, - SortedMap projectDependencies, final UnkownFileRemedy unkownFileRemedy) + SortedProperties loadUnsafeMapping( LicenseMap licenseMap, File missingFile, String missingFileUrl, + SortedMap projectDependencies ) throws IOException, MojoExecutionException; /** @@ -149,17 +147,16 @@ SortedProperties loadUnsafeMapping(LicenseMap licenseMap, File missingFile, Stri * @param unsafeDependencies all unsafe dependencies * @param projectDependencies all project dependencies * @param dependencyArtifacts all project dependency artifacts - * @param unkownFileRemedy * @return the loaded unsafe mapping * @throws ProjectBuildingException if could not build some dependencies maven project * @throws IOException if could not load missing file * @throws ThirdPartyToolException if pb with third-party tool */ - SortedProperties createUnsafeMapping(LicenseMap licenseMap, File missingFile, String missingFileUrl, - boolean useRepositoryMissingFiles, - SortedSet unsafeDependencies, - SortedMap projectDependencies, - Set dependencyArtifacts, final UnkownFileRemedy unkownFileRemedy) + SortedProperties createUnsafeMapping( LicenseMap licenseMap, File missingFile, String missingFileUrl, + boolean useRepositoryMissingFiles, + SortedSet unsafeDependencies, + SortedMap projectDependencies, + Set dependencyArtifacts ) throws ProjectBuildingException, IOException, ThirdPartyToolException, MojoExecutionException; /** diff --git a/src/main/java/org/codehaus/mojo/license/api/ThirdPartyTool.java b/src/main/java/org/codehaus/mojo/license/api/ThirdPartyTool.java index d7be56198..9492145ba 100644 --- a/src/main/java/org/codehaus/mojo/license/api/ThirdPartyTool.java +++ b/src/main/java/org/codehaus/mojo/license/api/ThirdPartyTool.java @@ -143,8 +143,9 @@ File resolveMissingLicensesDescriptor( String groupId, String artifactId, String * @return the unsafe mapping * @throws IOException if pb while reading missing file */ - SortedProperties loadUnsafeMapping(LicenseMap licenseMap, SortedMap artifactCache, - String encoding, File missingFile, String missingFileUrl, final UnkownFileRemedy unkownFileRemedy) + SortedProperties loadUnsafeMapping( LicenseMap licenseMap, SortedMap artifactCache, + String encoding, File missingFile, String missingFileUrl, + UnkownFileRemedy unkownFileRemedy ) throws IOException, MojoExecutionException; /** @@ -158,8 +159,8 @@ SortedProperties loadUnsafeMapping(LicenseMap licenseMap, SortedMap artifactCache, String encoding, - String overrideUrl, final UnkownFileRemedy unkownFileRemedy) + void overrideLicenses( LicenseMap licenseMap, SortedMap artifactCache, String encoding, + String overrideUrl, final UnkownFileRemedy unkownFileRemedy ) throws IOException, MojoExecutionException; /** From bdba126f024b07d2f14df6f5e49a57cd78860752 Mon Sep 17 00:00:00 2001 From: Wolfgang Wachsmuth Date: Thu, 27 Feb 2020 14:47:27 +0100 Subject: [PATCH 07/11] respect checkstyle --- src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java b/src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java index 01d8e80e7..f2106e4f0 100644 --- a/src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java +++ b/src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java @@ -22,8 +22,6 @@ * #L% */ -import org.apache.maven.plugin.MojoExecutionException; - /** * What to do in case of a file not found in project. * @@ -36,7 +34,7 @@ public enum UnkownFileRemedy /** Unkown files are output to the log as warnings */ warn, /** - * The first encountered unkown file is logged and a {@link MojoExecutionException} is thrown + * The first encountered unkown file is logged and a {@link org.apache.maven.plugin.MojoExecutionException} is thrown */ failFast, } \ No newline at end of file From fd395b85e4e70244630367a4940b4be011730077 Mon Sep 17 00:00:00 2001 From: Wolfgang Wachsmuth Date: Thu, 27 Feb 2020 15:06:20 +0100 Subject: [PATCH 08/11] respect checkstyle --- src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java b/src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java index f2106e4f0..222761297 100644 --- a/src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java +++ b/src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java @@ -34,7 +34,8 @@ public enum UnkownFileRemedy /** Unkown files are output to the log as warnings */ warn, /** - * The first encountered unkown file is logged and a {@link org.apache.maven.plugin.MojoExecutionException} is thrown + * The first encountered unkown file is logged and a {@link org.apache.maven.plugin.MojoExecutionException} is + * thrown */ failFast, } \ No newline at end of file From 138485d194af5943a45f119efeebb9a1e86d1ec5 Mon Sep 17 00:00:00 2001 From: Wolfgang Wachsmuth Date: Thu, 27 Feb 2020 17:25:53 +0100 Subject: [PATCH 09/11] enable unit test for windows --- .../org/codehaus/mojo/license/api/FreeMarkerHelperTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/codehaus/mojo/license/api/FreeMarkerHelperTest.java b/src/test/java/org/codehaus/mojo/license/api/FreeMarkerHelperTest.java index 7f285c95f..8e464e96d 100644 --- a/src/test/java/org/codehaus/mojo/license/api/FreeMarkerHelperTest.java +++ b/src/test/java/org/codehaus/mojo/license/api/FreeMarkerHelperTest.java @@ -138,8 +138,10 @@ public void testRenderTemplateForUpdateFileHeader() properties.put( "addSvnKeyWords", true ); String s = - helper.renderTemplate( "/org/codehaus/mojo/license/default-file-header-description.ftl", properties ); - Assert.assertEquals( "projectName\n$Id:$\n$HeadURL:$", s ); + helper.renderTemplate( "/org/codehaus/mojo/license/default-file-header-description.ftl", + properties ); + Assert.assertEquals( "projectName\n$Id:$\n$HeadURL:$", + s.replace( "\r\n", "\n" ).replace( '\r', '\n' ) ); LOG.info( "{}", s ); } } From 51b0b49fe83fbd1a3cd8d4eecb35d3d25ac8fd59 Mon Sep 17 00:00:00 2001 From: Wolfgang Wachsmuth Date: Tue, 3 Mar 2020 13:22:51 +0100 Subject: [PATCH 10/11] pass ID to handleUnkownDependency to have a cleaner API --- .../license/api/DefaultThirdPartyTool.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java index 4da89ffba..b9f1828a8 100644 --- a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java +++ b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java @@ -539,8 +539,8 @@ public SortedProperties loadUnsafeMapping( LicenseMap licenseMap, // there is some unknown dependencies in the missing file, remove them for ( String id : unknownDependenciesId ) { - handleUnkownDependency( unkownFileRemedy, "dependency [" + id - + "] does not exist in project, remove it from the missing file." ); + handleUnknownDependency( unkownFileRemedy, "dependency [%s]" + + " does not exist in project, remove it from the missing file.", id ); unsafeMappings.remove( id ); } @@ -555,7 +555,7 @@ public SortedProperties loadUnsafeMapping( LicenseMap licenseMap, MavenProject project = artifactCache.get( id ); if ( project == null ) { - handleUnkownDependency( unkownFileRemedy, "dependency [" + id + "] does not exist in project." ); + handleUnknownDependency( unkownFileRemedy, "dependency [%s] does not exist in project.", id ); continue; } @@ -597,19 +597,21 @@ public SortedProperties loadUnsafeMapping( LicenseMap licenseMap, return unsafeMappings; } - private void handleUnkownDependency( final UnkownFileRemedy unkownFileRemedy, final String message ) + private void handleUnknownDependency( final UnkownFileRemedy unkownFileRemedy, final String message, + final String id ) throws MojoExecutionException { + final String completeMessage = String.format( message, id ); switch ( unkownFileRemedy ) { case debug: - LOG.debug( message ); + LOG.debug( completeMessage ); break; case failFast: - throw new MojoExecutionException( message ); + throw new MojoExecutionException( completeMessage ); case warn: - LOG.warn( message ); + LOG.warn( completeMessage ); break; default: throw new IllegalStateException( "Unexpected value of " + UnkownFileRemedy.class.getName() + ": " @@ -640,8 +642,8 @@ public void overrideLicenses( LicenseMap licenseMap, SortedMap unsafeDependencies, Licen /** * @param project not null - * @param localRepository not null - * @param repositories not null + * @param remoteRepositories not null * @return the resolved site descriptor * @throws IOException if any * @throws ArtifactResolutionException if any From 9032b2d2ad0d2a8e08028a6fc348d0fa42b1a406 Mon Sep 17 00:00:00 2001 From: Wolfgang Wachsmuth Date: Tue, 3 Mar 2020 17:12:09 +0100 Subject: [PATCH 11/11] add some integration tests to assert unkownFileRemedy --- .../invoker.properties | 23 ++++++ .../licenses.properties | 1 + .../missing-licenses.properties | 1 + .../pom.xml | 82 +++++++++++++++++++ .../postbuild.groovy | 27 ++++++ .../invoker.properties | 23 ++++++ .../licenses.properties | 1 + .../missing-licenses.properties | 1 + .../pom.xml | 82 +++++++++++++++++++ .../invoker.properties | 23 ++++++ .../licenses.properties | 1 + .../missing-licenses.properties | 1 + .../pom.xml | 81 ++++++++++++++++++ .../postbuild.groovy | 27 ++++++ 14 files changed, 374 insertions(+) create mode 100644 src/it/file-does-not-exist-in-project-debug/invoker.properties create mode 100644 src/it/file-does-not-exist-in-project-debug/licenses.properties create mode 100644 src/it/file-does-not-exist-in-project-debug/missing-licenses.properties create mode 100644 src/it/file-does-not-exist-in-project-debug/pom.xml create mode 100644 src/it/file-does-not-exist-in-project-debug/postbuild.groovy create mode 100644 src/it/file-does-not-exist-in-project-fail/invoker.properties create mode 100644 src/it/file-does-not-exist-in-project-fail/licenses.properties create mode 100644 src/it/file-does-not-exist-in-project-fail/missing-licenses.properties create mode 100644 src/it/file-does-not-exist-in-project-fail/pom.xml create mode 100644 src/it/file-does-not-exist-in-project-warn/invoker.properties create mode 100644 src/it/file-does-not-exist-in-project-warn/licenses.properties create mode 100644 src/it/file-does-not-exist-in-project-warn/missing-licenses.properties create mode 100644 src/it/file-does-not-exist-in-project-warn/pom.xml create mode 100644 src/it/file-does-not-exist-in-project-warn/postbuild.groovy diff --git a/src/it/file-does-not-exist-in-project-debug/invoker.properties b/src/it/file-does-not-exist-in-project-debug/invoker.properties new file mode 100644 index 000000000..fbe14b904 --- /dev/null +++ b/src/it/file-does-not-exist-in-project-debug/invoker.properties @@ -0,0 +1,23 @@ +### +# #%L +# License Maven Plugin +# %% +# Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Lesser Public License for more details. +# +# You should have received a copy of the GNU General Lesser Public +# License along with this program. If not, see +# . +# #L% +### +invoker.goals=clean license:add-third-party +invoker.failureBehavior=fail-fast diff --git a/src/it/file-does-not-exist-in-project-debug/licenses.properties b/src/it/file-does-not-exist-in-project-debug/licenses.properties new file mode 100644 index 000000000..bcdae4c1a --- /dev/null +++ b/src/it/file-does-not-exist-in-project-debug/licenses.properties @@ -0,0 +1 @@ +commons-logging--commons-logging--1.1.1=The Apache Software License, Version 2.0 \ No newline at end of file diff --git a/src/it/file-does-not-exist-in-project-debug/missing-licenses.properties b/src/it/file-does-not-exist-in-project-debug/missing-licenses.properties new file mode 100644 index 000000000..8f8c049eb --- /dev/null +++ b/src/it/file-does-not-exist-in-project-debug/missing-licenses.properties @@ -0,0 +1 @@ +org.apache.commons--commons-lang3--3.3.2=The Apache Software License, Version 2.0 \ No newline at end of file diff --git a/src/it/file-does-not-exist-in-project-debug/pom.xml b/src/it/file-does-not-exist-in-project-debug/pom.xml new file mode 100644 index 000000000..10c10cac3 --- /dev/null +++ b/src/it/file-does-not-exist-in-project-debug/pom.xml @@ -0,0 +1,82 @@ + + + + + + 4.0.0 + + org.codehaus.mojo.license.test + file-does-not-exist-in-project-debug + 1.0 + + License Test :: file-does-not-exist-in-project-debug + + no-url + + UTF-8 + true + + + + + commons-logging + commons-logging + 1.1.1 + + + + org.json + json + 20070829 + + + + + + + + + + org.codehaus.mojo + license-maven-plugin + @pom.version@ + + + + + + + org.codehaus.mojo + license-maven-plugin + + true + missing-licenses.properties + licenses.properties + debug + + + + + diff --git a/src/it/file-does-not-exist-in-project-debug/postbuild.groovy b/src/it/file-does-not-exist-in-project-debug/postbuild.groovy new file mode 100644 index 000000000..a971853c0 --- /dev/null +++ b/src/it/file-does-not-exist-in-project-debug/postbuild.groovy @@ -0,0 +1,27 @@ +/* + * #%L + * License Maven Plugin + * %% + * Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ +file = new File(basedir, "build.log") +assert file.exists() +content = file.text +assert !content.contains("dependency [org.apache.commons--commons-lang3--3.3.2] does not exist in project, remove it from the missing file.") + +return true \ No newline at end of file diff --git a/src/it/file-does-not-exist-in-project-fail/invoker.properties b/src/it/file-does-not-exist-in-project-fail/invoker.properties new file mode 100644 index 000000000..c93eaaca2 --- /dev/null +++ b/src/it/file-does-not-exist-in-project-fail/invoker.properties @@ -0,0 +1,23 @@ +### +# #%L +# License Maven Plugin +# %% +# Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Lesser Public License for more details. +# +# You should have received a copy of the GNU General Lesser Public +# License along with this program. If not, see +# . +# #L% +### +invoker.goals=clean license:add-third-party +invoker.buildResult = failure diff --git a/src/it/file-does-not-exist-in-project-fail/licenses.properties b/src/it/file-does-not-exist-in-project-fail/licenses.properties new file mode 100644 index 000000000..bcdae4c1a --- /dev/null +++ b/src/it/file-does-not-exist-in-project-fail/licenses.properties @@ -0,0 +1 @@ +commons-logging--commons-logging--1.1.1=The Apache Software License, Version 2.0 \ No newline at end of file diff --git a/src/it/file-does-not-exist-in-project-fail/missing-licenses.properties b/src/it/file-does-not-exist-in-project-fail/missing-licenses.properties new file mode 100644 index 000000000..8f8c049eb --- /dev/null +++ b/src/it/file-does-not-exist-in-project-fail/missing-licenses.properties @@ -0,0 +1 @@ +org.apache.commons--commons-lang3--3.3.2=The Apache Software License, Version 2.0 \ No newline at end of file diff --git a/src/it/file-does-not-exist-in-project-fail/pom.xml b/src/it/file-does-not-exist-in-project-fail/pom.xml new file mode 100644 index 000000000..17e8416e7 --- /dev/null +++ b/src/it/file-does-not-exist-in-project-fail/pom.xml @@ -0,0 +1,82 @@ + + + + + + 4.0.0 + + org.codehaus.mojo.license.test + file-does-not-exist-in-project-fail + 1.0 + + License Test :: file-does-not-exist-in-project-fail + + no-url + + UTF-8 + true + + + + + commons-logging + commons-logging + 1.1.1 + + + + org.json + json + 20070829 + + + + + + + + + + org.codehaus.mojo + license-maven-plugin + @pom.version@ + + + + + + + org.codehaus.mojo + license-maven-plugin + + true + missing-licenses.properties + licenses.properties + failFast + + + + + diff --git a/src/it/file-does-not-exist-in-project-warn/invoker.properties b/src/it/file-does-not-exist-in-project-warn/invoker.properties new file mode 100644 index 000000000..fbe14b904 --- /dev/null +++ b/src/it/file-does-not-exist-in-project-warn/invoker.properties @@ -0,0 +1,23 @@ +### +# #%L +# License Maven Plugin +# %% +# Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Lesser Public License for more details. +# +# You should have received a copy of the GNU General Lesser Public +# License along with this program. If not, see +# . +# #L% +### +invoker.goals=clean license:add-third-party +invoker.failureBehavior=fail-fast diff --git a/src/it/file-does-not-exist-in-project-warn/licenses.properties b/src/it/file-does-not-exist-in-project-warn/licenses.properties new file mode 100644 index 000000000..bcdae4c1a --- /dev/null +++ b/src/it/file-does-not-exist-in-project-warn/licenses.properties @@ -0,0 +1 @@ +commons-logging--commons-logging--1.1.1=The Apache Software License, Version 2.0 \ No newline at end of file diff --git a/src/it/file-does-not-exist-in-project-warn/missing-licenses.properties b/src/it/file-does-not-exist-in-project-warn/missing-licenses.properties new file mode 100644 index 000000000..8f8c049eb --- /dev/null +++ b/src/it/file-does-not-exist-in-project-warn/missing-licenses.properties @@ -0,0 +1 @@ +org.apache.commons--commons-lang3--3.3.2=The Apache Software License, Version 2.0 \ No newline at end of file diff --git a/src/it/file-does-not-exist-in-project-warn/pom.xml b/src/it/file-does-not-exist-in-project-warn/pom.xml new file mode 100644 index 000000000..cafb821ed --- /dev/null +++ b/src/it/file-does-not-exist-in-project-warn/pom.xml @@ -0,0 +1,81 @@ + + + + + + 4.0.0 + + org.codehaus.mojo.license.test + file-does-not-exist-in-project-warn + 1.0 + + License Test :: file-does-not-exist-in-project-warn + + no-url + + UTF-8 + true + + + + + commons-logging + commons-logging + 1.1.1 + + + + org.json + json + 20070829 + + + + + + + + + + org.codehaus.mojo + license-maven-plugin + @pom.version@ + + + + + + + org.codehaus.mojo + license-maven-plugin + + true + missing-licenses.properties + licenses.properties + + + + + diff --git a/src/it/file-does-not-exist-in-project-warn/postbuild.groovy b/src/it/file-does-not-exist-in-project-warn/postbuild.groovy new file mode 100644 index 000000000..09edb2b74 --- /dev/null +++ b/src/it/file-does-not-exist-in-project-warn/postbuild.groovy @@ -0,0 +1,27 @@ +/* + * #%L + * License Maven Plugin + * %% + * Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ +file = new File(basedir, "build.log") +assert file.exists() +content = file.text +assert content.contains("dependency [org.apache.commons--commons-lang3--3.3.2] does not exist in project, remove it from the missing file.") + +return true \ No newline at end of file