Skip to content

Commit

Permalink
Fix #145 aggregate-add-third-party modifying project dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
srdo committed Jan 4, 2019
1 parent 3c70ce3 commit d47178b
Show file tree
Hide file tree
Showing 28 changed files with 808 additions and 102 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>
<plugin>
<groupId>org.ec4j.maven</groupId>
Expand Down
3 changes: 3 additions & 0 deletions src/it/ISSUE-145-2/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Demonstrates that the aggregateAddThirdParty goal can handle long sibling project dependency chains in the same reactor, and that it resolves dependencies based on the right remote repositories list.

The project has parent A and children B, C, D, E with B depending on C, C dependending on D and D depending on E. The D dependency has a custom repository specified, and a dependency from that repo. When the plugin generates the license list, it should pick up the license for the dependency from the custom repo. E has a custom license specified, which should also be picked up.
25 changes: 25 additions & 0 deletions src/it/ISSUE-145-2/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
###
# #%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
#Disable the default settings.xml for integration tests. This test needs to always resolve dependencies from remote repositories, not from the local.
invoker.profiles=!it-repo
66 changes: 66 additions & 0 deletions src/it/ISSUE-145-2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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>

<groupId>org.codehaus.mojo.license.test</groupId>
<artifactId>test-ISSUE-145-2</artifactId>
<version>@pom.version@</version>
<name>License Test :: ISSUE-145-2</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>
<module>submodule3</module>
<module>submodule4</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</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>
46 changes: 46 additions & 0 deletions src/it/ISSUE-145-2/postbuild.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* #%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%
*/

def assertExistsFile(file) {
if (!file.exists() || file.isDirectory()) {
println(file.getAbsolutePath() + " file is missing or a directory.")
assert false
}
assert true
}

def assertContains(file, content, expected) {
if (!content.contains(expected)) {
println(expected + " was not found in file [" + file + "]\n :" + content)
return false
}
return true
}

file = new File(basedir, 'target/generated-sources/license/THIRD-PARTY.txt');
assertExistsFile(file);

content = file.text;
assert assertContains(file, content, 'Eclipse Public License 1.0');
assert assertContains(file, content, 'Custom ISSUE-145 license');

return true;
24 changes: 24 additions & 0 deletions src/it/ISSUE-145-2/submodule1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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-2</artifactId>
<version>@pom.version@</version>
</parent>

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

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

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

</project>
21 changes: 21 additions & 0 deletions src/it/ISSUE-145-2/submodule2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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-2</artifactId>
<version>@pom.version@</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>test-ISSUE-145-2-submodule2</artifactId>

<dependencies>
<dependency>
<groupId>org.codehaus.mojo.license.test</groupId>
<artifactId>test-ISSUE-145-2-submodule3</artifactId>
<version>@pom.version@</version>
</dependency>
</dependencies>
</project>
34 changes: 34 additions & 0 deletions src/it/ISSUE-145-2/submodule3/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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-2</artifactId>
<version>@pom.version@</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>test-ISSUE-145-2-submodule3</artifactId>

<repositories>
<repository>
<id>clojars.org</id>
<url>https://repo.clojars.org</url>
</repository>
</repositories>

<dependencies>
<dependency>
<!-- This is not available on Central, which is essential to the test -->
<groupId>org.clojure-android</groupId>
<artifactId>tools.logging</artifactId>
<version>0.3.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo.license.test</groupId>
<artifactId>test-ISSUE-145-2-submodule4</artifactId>
<version>@pom.version@</version>
</dependency>
</dependencies>
</project>
19 changes: 19 additions & 0 deletions src/it/ISSUE-145-2/submodule4/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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-2</artifactId>
<version>@pom.version@</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>test-ISSUE-145-2-submodule4</artifactId>

<licenses>
<license>
<name>Custom ISSUE-145 license</name>
</license>
</licenses>
</project>
3 changes: 3 additions & 0 deletions src/it/ISSUE-145/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Demonstrates that the aggregateAddThirdParty goal does not cause Maven to drop dependencies.

The project has parent A and children B and C with B depending on C. The bug in the plugin caused B to lose its dependency on C at build time, because the plugin modified Maven's list of dependencies for B. The test verifies that the dependency is preserved.
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
64 changes: 64 additions & 0 deletions src/it/ISSUE-145/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?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>

<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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</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 = 'org/codehaus/mojo/license/AnImportantDependency.class';
assert file.getJarEntry(expectedLibPath) != null;
return true;
Loading

0 comments on commit d47178b

Please sign in to comment.