From e29c4bf5c2d31adfd48dbaf0f18f27cee1960285 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Tue, 15 Mar 2022 12:28:00 +0000 Subject: [PATCH] Fix #345 Only log override warning if licenseMerges provided. --- src/it/ISSUE-345-2/invoker.properties | 2 + src/it/ISSUE-345-2/license.merges | 1 + src/it/ISSUE-345-2/pom.xml | 72 +++++++++++++++++++ src/it/ISSUE-345-2/postbuild.groovy | 13 ++++ src/it/ISSUE-345/invoker.properties | 2 + src/it/ISSUE-345/license.merges | 1 + src/it/ISSUE-345/pom.xml | 67 +++++++++++++++++ src/it/ISSUE-345/postbuild.groovy | 13 ++++ .../license/AbstractAddThirdPartyMojo.java | 9 ++- 9 files changed, 177 insertions(+), 3 deletions(-) create mode 100644 src/it/ISSUE-345-2/invoker.properties create mode 100644 src/it/ISSUE-345-2/license.merges create mode 100644 src/it/ISSUE-345-2/pom.xml create mode 100644 src/it/ISSUE-345-2/postbuild.groovy create mode 100644 src/it/ISSUE-345/invoker.properties create mode 100644 src/it/ISSUE-345/license.merges create mode 100644 src/it/ISSUE-345/pom.xml create mode 100644 src/it/ISSUE-345/postbuild.groovy diff --git a/src/it/ISSUE-345-2/invoker.properties b/src/it/ISSUE-345-2/invoker.properties new file mode 100644 index 000000000..47be4e5d6 --- /dev/null +++ b/src/it/ISSUE-345-2/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals=clean license:add-third-party +invoker.failureBehavior=fail-fast diff --git a/src/it/ISSUE-345-2/license.merges b/src/it/ISSUE-345-2/license.merges new file mode 100644 index 000000000..45a53c8f8 --- /dev/null +++ b/src/it/ISSUE-345-2/license.merges @@ -0,0 +1 @@ +APACHE|The Apache Software License, Version 2.0 diff --git a/src/it/ISSUE-345-2/pom.xml b/src/it/ISSUE-345-2/pom.xml new file mode 100644 index 000000000..fd2e8a8ba --- /dev/null +++ b/src/it/ISSUE-345-2/pom.xml @@ -0,0 +1,72 @@ + + + + + + 4.0.0 + + org.codehaus.mojo.license.test + issue-345-2 + @pom.version@ + + License Test :: ISSUE-345-2 + + + UTF-8 + true + ${project.baseUri}license.merges + + + + + + + org.codehaus.mojo + license-maven-plugin + @pom.version@ + + + Apache-2.0|The Apache Software License, Version 2.0 + + + + + + + + + + commons-logging + commons-logging + 1.1.1 + + + org.apache.commons + commons-lang3 + 3.8.1 + + + + diff --git a/src/it/ISSUE-345-2/postbuild.groovy b/src/it/ISSUE-345-2/postbuild.groovy new file mode 100644 index 000000000..f1ff9c3ae --- /dev/null +++ b/src/it/ISSUE-345-2/postbuild.groovy @@ -0,0 +1,13 @@ +// Check that the licenseMergesUrl is used. +file = new File(basedir, 'target/generated-sources/license/THIRD-PARTY.txt') +assert file.exists() +content = file.text +assert !content.contains('the project has no dependencies.') +assert content.contains('(APACHE) Commons Logging (commons-logging:commons-logging:1.1.1 - http://commons.apache.org/logging)') + +// Check that there's a warning about licenseMerges being overridden. +file = new File(basedir, 'build.log') +assert file.exists() +content = file.text +assert content.contains('licenseMerges will be overridden by licenseMergesUrl.') +return true diff --git a/src/it/ISSUE-345/invoker.properties b/src/it/ISSUE-345/invoker.properties new file mode 100644 index 000000000..47be4e5d6 --- /dev/null +++ b/src/it/ISSUE-345/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals=clean license:add-third-party +invoker.failureBehavior=fail-fast diff --git a/src/it/ISSUE-345/license.merges b/src/it/ISSUE-345/license.merges new file mode 100644 index 000000000..45a53c8f8 --- /dev/null +++ b/src/it/ISSUE-345/license.merges @@ -0,0 +1 @@ +APACHE|The Apache Software License, Version 2.0 diff --git a/src/it/ISSUE-345/pom.xml b/src/it/ISSUE-345/pom.xml new file mode 100644 index 000000000..40a9b224f --- /dev/null +++ b/src/it/ISSUE-345/pom.xml @@ -0,0 +1,67 @@ + + + + + + 4.0.0 + + org.codehaus.mojo.license.test + issue-345 + @pom.version@ + + License Test :: ISSUE-345 + + + UTF-8 + true + ${project.baseUri}license.merges + + + + + + + org.codehaus.mojo + license-maven-plugin + @pom.version@ + + + + + + + + commons-logging + commons-logging + 1.1.1 + + + org.apache.commons + commons-lang3 + 3.8.1 + + + + diff --git a/src/it/ISSUE-345/postbuild.groovy b/src/it/ISSUE-345/postbuild.groovy new file mode 100644 index 000000000..88ec71e6b --- /dev/null +++ b/src/it/ISSUE-345/postbuild.groovy @@ -0,0 +1,13 @@ +// Check that the licenseMergesUrl is used. +file = new File(basedir, 'target/generated-sources/license/THIRD-PARTY.txt') +assert file.exists() +content = file.text +assert !content.contains('the project has no dependencies.') +assert content.contains('(APACHE) Commons Logging (commons-logging:commons-logging:1.1.1 - http://commons.apache.org/logging)') + +// Since no licenseMerges was provided then there should be no warning. +file = new File(basedir, 'build.log') +assert file.exists() +content = file.text +assert !content.contains('licenseMerges will be overridden by licenseMergesUrl.') +return true diff --git a/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java index 88a3d66a2..4071daa6a 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java @@ -766,9 +766,12 @@ protected void init() } else if ( licenseMergesUrl != null ) { - LOG.warn( "" ); - LOG.warn( "licenseMerges will be overridden by licenseMergesUrl." ); - LOG.warn( "" ); + if ( licenseMerges != null ) + { + LOG.warn( "" ); + LOG.warn( "licenseMerges will be overridden by licenseMergesUrl." ); + LOG.warn( "" ); + } if ( UrlRequester.isStringUrl( licenseMergesUrl ) ) { licenseMerges = Arrays.asList( UrlRequester.getFromUrl( licenseMergesUrl ).split( "[\n\r]+" ) );