Skip to content

Commit

Permalink
Merge pull request #297 from ppalaga/i296
Browse files Browse the repository at this point in the history
Fix #296 AbstractDownloadLicensesMojo should not download available f…
  • Loading branch information
ppalaga authored Feb 26, 2019
2 parents 3d74e20 + d1b4213 commit 3ba5163
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/it/download-licenses-configured/invoker.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
invoker.goals = clean validate -e
invoker.goals = validate -e -Dorg.slf4j.simpleLogger.log.org.codehaus.mojo.license=debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<licenseSummary>
<dependencies>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
<licenses>
<license>
<name>Public Domain</name>
</license>
</licenses>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.1</version>
<licenses>
<license>
<name>BSD 3-Clause ASM</name>
<url>https://gitlab.ow2.org/asm/asm/raw/ASM_3_1_MVN/LICENSE.txt</url>
<file>bsd-3-clause-asm-license.txt</file>
</license>
</licenses>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0</version>
<licenses>
<license>
<name>Apache License 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<file>apache-license-2.0-license-2.0.txt</file>
</license>
</licenses>
</dependency>
</dependencies>
</licenseSummary>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<licenses>
<license>
<name>Apache License 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<file>apache-license-2.0-license-2.0.txt</file>
</license>
</licenses>
Expand Down
21 changes: 20 additions & 1 deletion src/it/download-licenses-configured/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,33 @@
<writeVersions>false</writeVersions>
</configuration>
</execution>
<execution>
<id>no-download</id>
<phase>validate</phase>
<goals>
<goal>download-licenses</goal>
</goals>
<configuration>
<licensesConfigFile>${basedir}/src/license/licenses-config-no-download.xml</licensesConfigFile>
<licensesOutputDirectory>${project.build.directory}/no-download/licenses</licensesOutputDirectory>
<licensesOutputFile>${project.build.directory}/no-download/licenses.xml</licensesOutputFile>
<sortByGroupIdAndArtifactId>true</sortByGroupIdAndArtifactId>
<licenseUrlFileNameSanitizers>
<licenseUrlFileNameSanitizer>
<regexp>[\s-_]+</regexp>
<replacement>-</replacement>
</licenseUrlFileNameSanitizer>
</licenseUrlFileNameSanitizers>
</configuration>
</execution>
<execution>
<id>insert-versions</id>
<phase>validate</phase>
<goals>
<goal>licenses-xml-insert-versions</goal>
</goals>
<configuration>
<licensesInputFile>${project.build.directory}/artifact-filters-url/licenses.xml</licensesInputFile>
<licensesInputFile>${basedir}/src/license/licenses-input-insert-versions.xml</licensesInputFile>
<licensesOutputFile>${project.build.directory}/insert-versions/licenses.xml</licensesOutputFile>
</configuration>
</execution>
Expand Down
16 changes: 16 additions & 0 deletions src/it/download-licenses-configured/postbuild.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ return {
final Path bsdAsm = outputBase.resolve('licenses/bsd 3-clause asm - license.txt')
assert !Files.exists(bsdAsm)

final Path expectedLicensesXml = basePath.resolve('licenses-'+ id +'.expected.xml')
final Path licensesXml = outputBase.resolve('licenses.xml')
assert expectedLicensesXml.text.equals(licensesXml.text)
return true
}() && {
final String id = 'no-download'
final Path outputBase = basePath.resolve('target/' + id)

final Path asl2 = outputBase.resolve('licenses/apache-license-2.0-license-2.0.txt')
assert Files.exists(asl2)
assert asl2.text.contains('Fake content')

final Path bsdAsm = outputBase.resolve('licenses/bsd-3-clause-asm-license.txt')
assert Files.exists(bsdAsm)
assert bsdAsm.text.contains('Fake content')

final Path expectedLicensesXml = basePath.resolve('licenses-'+ id +'.expected.xml')
final Path licensesXml = outputBase.resolve('licenses.xml')
assert expectedLicensesXml.text.equals(licensesXml.text)
Expand Down
36 changes: 36 additions & 0 deletions src/it/download-licenses-configured/prebuild.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* #%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.
*
* 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
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/

import java.nio.file.Path;
import java.nio.file.Files;

Path basePath = basedir.toPath()

Files.move(basePath.resolve('target-initial'), basePath.resolve('target'))

Path asl2 = basePath.resolve('target/no-download/licenses/apache-license-2.0-license-2.0.txt')
assert Files.exists(asl2)
assert asl2.text.contains('Fake content')

Path bsd = basePath.resolve('target/no-download/licenses/bsd-3-clause-asm-license.txt')
assert Files.exists(bsd)
assert bsd.text.contains('Fake content')
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<licenseSummary>
<dependencies>
<dependency>
<groupId>\Qcommons-logging</groupId>
<artifactId>\Qcommons-logging</artifactId>
<matchLicenses>
<!-- match empty license list -->
</matchLicenses>
<licenses>
<license>
<name>Apache License 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
</license>
</licenses>
</dependency>
<dependency>
<groupId>\Qaopalliance\E</groupId>
<artifactId>\Qaopalliance\E</artifactId>
<matchLicenses>
<license>
<name>\QPublic Domain\E</name>
</license>
</matchLicenses>
<licenses approved="true" />
</dependency>
<dependency>
<groupId>\Qasm\E</groupId>
<artifactId>\Qasm\E</artifactId>
<matchLicenses>
<!-- match empty license list -->
</matchLicenses>
<licenses>
<license>
<name>BSD 3-Clause ASM</name>
<url>https://gitlab.ow2.org/asm/asm/raw/ASM_3_1_MVN/LICENSE.txt</url>
</license>
</licenses>
</dependency>
</dependencies>
</licenseSummary>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<licenses>
<license>
<name>Apache License 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
</license>
</licenses>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<licenseSummary>
<dependencies>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<licenses>
<license>
<name>Public Domain</name>
</license>
</licenses>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<licenses>
<!-- No license information available. -->
</licenses>
</dependency>
</dependencies>
</licenseSummary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<licenseSummary>
<dependencies>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
<licenses>
<license>
<name>Public Domain</name>
</license>
</licenses>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.1</version>
<licenses>
<license>
<name>BSD 3-Clause ASM</name>
<url>https://gitlab.ow2.org/asm/asm/raw/ASM_3_1_MVN/LICENSE.txt</url>
<file>bsd-3-clause-asm-license.txt</file>
</license>
</licenses>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0</version>
<licenses>
<license>
<name>Apache License 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<file>apache-license-2.0-license-2.0.txt</file>
</license>
</licenses>
</dependency>
</dependencies>
</licenseSummary>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fake content that should not get overwritten without forceDownload=true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fake content that should not get overwritten without forceDownload=true
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.codehaus.mojo.license.download.ProjectLicenseInfo;
import org.codehaus.mojo.license.download.LicenseDownloader.LicenseDownloadResult;
import org.codehaus.mojo.license.download.LicenseMatchers;
import org.codehaus.mojo.license.download.LicenseSummaryReader;
import org.codehaus.mojo.license.utils.FileUtil;

import java.io.File;
Expand Down Expand Up @@ -624,6 +625,37 @@ public void execute()

final LicenseMatchers matchers = LicenseMatchers.load( licensesConfigFile );

if ( !forceDownload )
{
try
{
final List<ProjectLicenseInfo> projectLicenseInfos =
LicenseSummaryReader.parseLicenseSummary( licensesOutputFile );
for ( ProjectLicenseInfo dep : projectLicenseInfos )
{
for ( ProjectLicense lic : dep.getLicenses() )
{
final String fileName = lic.getFile();
final String url = lic.getUrl();
if ( fileName != null && url != null )
{
final File file = new File( licensesOutputDirectory, fileName );
if ( file.exists() )
{
final LicenseDownloadResult entry =
LicenseDownloadResult.success( file, FileUtil.sha1( file.toPath() ), false );
cache.put( url, entry );
}
}
}
}
}
catch ( Exception e )
{
throw new MojoExecutionException( "Unable to process license summary file: " + licensesOutputFile, e );
}
}

final Set<MavenProject> dependencies = getDependencies();

// The resulting list of licenses after dependency resolution
Expand Down

0 comments on commit 3ba5163

Please sign in to comment.