Skip to content

Commit

Permalink
Issue 145: Fix aggregate-add-third-party modifying project dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
srdo committed Oct 4, 2018
1 parent abeab62 commit 20a8aca
Show file tree
Hide file tree
Showing 19 changed files with 332 additions and 56 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<scriptVariables>
<projectVersion>${project.version}</projectVersion>
</scriptVariables>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Expand Down
23 changes: 23 additions & 0 deletions src/it/ISSUE-145/invoker.properties
Original file line number Diff line number Diff line change
@@ -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
# <http://www.gnu.org/licenses/lgpl-3.0.html>.
# #L%
###
invoker.goals=clean package
invoker.failureBehavior=fail-fast
65 changes: 65 additions & 0 deletions src/it/ISSUE-145/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>

<groupId>org.codehaus.mojo.license.test</groupId>
<artifactId>test-ISSUE-145</artifactId>
<version>@pom.version@</version>
<name>License Test :: ISSUE-145</name>
<packaging>pom</packaging>

<licenses>
<license>
<name>The GNU Lesser General Public License, Version 3.0</name>
<url>http://www.gnu.org/licenses/lgpl-3.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<license.verbose>true</license.verbose>
<license.sortByGroupIdAndArtifactId>true</license.sortByGroupIdAndArtifactId>
<licensesOutputFile>${project.build.directory}/licenses.xml</licensesOutputFile>
</properties>

<modules>
<module>submodule1</module>
<module>submodule2</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
</plugin>
</plugins>

<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>@pom.version@</version>
<executions>
<execution>
<id>aggregate-add-third-party</id>
<goals>
<goal>aggregate-add-third-party</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
27 changes: 27 additions & 0 deletions src/it/ISSUE-145/postbuild.groovy
Original file line number Diff line number Diff line change
@@ -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
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
import java.util.jar.JarFile

file = new JarFile(new File(basedir, 'submodule1/target/test-ISSUE-145-submodule1-' + projectVersion + '.jar'));
expectedLibPath = 'BOOT-INF/lib/test-ISSUE-145-submodule2-' + projectVersion + '.jar';
assert file.getJarEntry(expectedLibPath) != null;
return true;
46 changes: 46 additions & 0 deletions src/it/ISSUE-145/submodule1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.codehaus.mojo.license.test</groupId>
<artifactId>test-ISSUE-145</artifactId>
<version>@pom.version@</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>

<artifactId>test-ISSUE-145-submodule1</artifactId>

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.codehaus.mojo.license.test</groupId>
<artifactId>test-ISSUE-145-submodule2</artifactId>
<version>@pom.version@</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>

<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package de.jotb.playground;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
13 changes: 13 additions & 0 deletions src/it/ISSUE-145/submodule2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.codehaus.mojo.license.test</groupId>
<artifactId>test-ISSUE-145</artifactId>
<version>@pom.version@</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>test-ISSUE-145-submodule2</artifactId>
</project>
27 changes: 27 additions & 0 deletions src/it/ISSUE-145/submodule2/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Text-Service</title>
<base href="/"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="theme-color" content="#4e8ef7"/>
<link rel="manifest" href="manifest.json"/>
<link rel="icon" type="image/x-icon" href="favicon.ico"/>
<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png"/>
</head>
<body>
<!--[if lt IE 10]>
<p>
You are using an <strong>outdated</strong> browser.
Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.
</p>
<![endif]-->
<noscript>
<p>
This page requires JavaScript to work properly. Please enable JavaScript in your browser.
</p>
</noscript>
<app-root></app-root>
</body>
</html>
2 changes: 1 addition & 1 deletion src/it/ISSUE-80/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<artifactId>test-ISSUE-59</artifactId>
<version>@pom.version@</version>

<name>License Test :: ISSUE-59</name>
<name>License Test :: ISSUE-80</name>
<packaging>jar</packaging>

<licenses>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import org.apache.maven.model.Dependency;
import org.codehaus.mojo.license.api.LoadedProjectDependencies;

/*
* #%L
Expand Down Expand Up @@ -559,6 +561,12 @@ public abstract class AbstractAddThirdPartyMojo
* @since 1.4
*/
private Map<String, String> globalKnownLicenses;

boolean isAggregatorBuild;

Map<String, List<Dependency>> reactorProjectDependencies;

LoadedProjectDependencies dependencyArtifacts;

// ----------------------------------------------------------------------
// Abstract Methods
Expand Down Expand Up @@ -634,6 +642,12 @@ protected void init()
// not generating bundled file
doGenerateBundle = false;
}

if (isAggregatorBuild) {
dependencyArtifacts = dependenciesTool.loadProjectArtifacts( localRepository, remoteRepositories, project, reactorProjectDependencies );
} else {
dependencyArtifacts = new LoadedProjectDependencies(project.getArtifacts(), project.getDependencyArtifacts());
}

projectDependencies = loadDependencies();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import org.codehaus.mojo.license.api.LoadedProjectDependencies;

/**
* Created on 23/05/16.
Expand Down Expand Up @@ -263,7 +264,9 @@ protected MavenProject getProject()

protected SortedMap<String, MavenProject> getDependencies( MavenProject project )
{
return dependenciesTool.loadProjectDependencies( project, this, localRepository, remoteRepositories, null );
return dependenciesTool.loadProjectDependencies(
new LoadedProjectDependencies(project.getArtifacts(), project.getDependencyArtifacts()),
this, localRepository, remoteRepositories, null );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeSet;
import org.apache.maven.artifact.Artifact;
import org.codehaus.mojo.license.api.LoadedProjectDependencies;

/**
* Base class for third-party reports.
Expand Down Expand Up @@ -516,16 +518,19 @@ Collection<ThirdPartyDetails> createThirdPartyDetails( MavenProject project, boo
DependenciesToolException, MojoExecutionException
{

if ( loadArtifacts )
{
dependenciesTool.loadProjectArtifacts( localRepository, project.getRemoteArtifactRepositories(), project , null);
LoadedProjectDependencies loadedDependencies;
if ( loadArtifacts ) {
loadedDependencies = dependenciesTool.loadProjectArtifacts( localRepository, licenseMerges, project, null );
}

else {
loadedDependencies = new LoadedProjectDependencies(getProject().getArtifacts(), getProject().getDependencyArtifacts());
}

ThirdPartyHelper thirdPartyHelper =
new DefaultThirdPartyHelper( project, encoding, verbose, dependenciesTool, thirdPartyTool, localRepository,
project.getRemoteArtifactRepositories(), getLog() );
// load dependencies of the project
SortedMap<String, MavenProject> projectDependencies = thirdPartyHelper.loadDependencies( this );
SortedMap<String, MavenProject> projectDependencies = thirdPartyHelper.loadDependencies( this, loadedDependencies );

// create licenseMap from it
LicenseMap licenseMap = thirdPartyHelper.createLicenseMap( projectDependencies );
Expand All @@ -547,7 +552,7 @@ Collection<ThirdPartyDetails> createThirdPartyDetails( MavenProject project, boo
{
// Resolve unsafe dependencies using missing files, this will update licenseMap and unsafeDependencies
thirdPartyHelper.createUnsafeMapping( licenseMap, missingFile, missingFileUrl, useRepositoryMissingFiles,
dependenciesWithNoLicense, projectDependencies );
dependenciesWithNoLicense, projectDependencies, loadedDependencies.getAllDependencies() );
}
}

Expand Down
Loading

0 comments on commit 20a8aca

Please sign in to comment.