Skip to content

Commit ff5d6b7

Browse files
MrBanana05Bjarne Corneliusslawekjaranowski
authored
Implement Optional Parameters to include and exclude submodules (#620)
* Implement Optional Parameters to include and exclude submodules * Implement unit tests for the ModuleHelper * Fix filter when not specifying included or excluded modules * Add integration test * exclude transitive dependencies in IT --------- Co-authored-by: Bjarne Cornelius <[email protected]> Co-authored-by: Slawomir Jaranowski <[email protected]>
1 parent d722db8 commit ff5d6b7

File tree

11 files changed

+486
-4
lines changed

11 files changed

+486
-4
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
#%L
4+
License Maven Plugin
5+
%%
6+
Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
7+
%%
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU Lesser General Public License as
10+
published by the Free Software Foundation, either version 3 of the
11+
License, or (at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Lesser Public License for more details.
17+
18+
You should have received a copy of the GNU General Lesser Public
19+
License along with this program. If not, see
20+
<http://www.gnu.org/licenses/lgpl-3.0.html>.
21+
#L%
22+
-->
23+
24+
<project xmlns="http://maven.apache.org/POM/4.0.0"
25+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
26+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
27+
28+
<modelVersion>4.0.0</modelVersion>
29+
30+
<parent>
31+
<groupId>org.codehaus.mojo.license.test</groupId>
32+
<artifactId>test-aggregate-add-third-party-filtered</artifactId>
33+
<version>@project.version@</version>
34+
</parent>
35+
36+
<artifactId>test-aggregate-add-third-party-filtered-child1</artifactId>
37+
38+
<name>License Test :: filtered-modules - child 1</name>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>commons-logging</groupId>
43+
<artifactId>commons-logging</artifactId>
44+
<version>1.1.1</version>
45+
</dependency>
46+
</dependencies>
47+
</project>
48+
49+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
#%L
4+
License Maven Plugin
5+
%%
6+
Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
7+
%%
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU Lesser General Public License as
10+
published by the Free Software Foundation, either version 3 of the
11+
License, or (at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Lesser Public License for more details.
17+
18+
You should have received a copy of the GNU General Lesser Public
19+
License along with this program. If not, see
20+
<http://www.gnu.org/licenses/lgpl-3.0.html>.
21+
#L%
22+
-->
23+
24+
<project xmlns="http://maven.apache.org/POM/4.0.0"
25+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
26+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
27+
28+
<modelVersion>4.0.0</modelVersion>
29+
30+
<parent>
31+
<groupId>org.codehaus.mojo.license.test</groupId>
32+
<artifactId>test-aggregate-add-third-party-filtered</artifactId>
33+
<version>@project.version@</version>
34+
</parent>
35+
36+
<artifactId>test-aggregate-add-third-party-filtered-child2</artifactId>
37+
38+
<name>License Test :: filtered-modules - child 2</name>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>junit</groupId>
43+
<artifactId>junit</artifactId>
44+
<version>4.13.1</version>
45+
<scope>test</scope>
46+
</dependency>
47+
</dependencies>
48+
</project>
49+
50+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
#%L
4+
License Maven Plugin
5+
%%
6+
Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
7+
%%
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU Lesser General Public License as
10+
published by the Free Software Foundation, either version 3 of the
11+
License, or (at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Lesser Public License for more details.
17+
18+
You should have received a copy of the GNU General Lesser Public
19+
License along with this program. If not, see
20+
<http://www.gnu.org/licenses/lgpl-3.0.html>.
21+
#L%
22+
-->
23+
24+
<project xmlns="http://maven.apache.org/POM/4.0.0"
25+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
26+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
27+
28+
<modelVersion>4.0.0</modelVersion>
29+
30+
<parent>
31+
<groupId>org.codehaus.mojo.license.test</groupId>
32+
<artifactId>test-aggregate-add-third-party-filtered</artifactId>
33+
<version>@project.version@</version>
34+
</parent>
35+
36+
<artifactId>test-aggregate-add-third-party-filtered-child3</artifactId>
37+
38+
<name>License Test :: filtered-modules - child 3</name>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>org.springframework.security</groupId>
43+
<artifactId>spring-security-core</artifactId>
44+
<version>6.4.5</version>
45+
<exclusions>
46+
<!-- for test transitive dependencies are not required -->
47+
<exclusion>
48+
<groupId>*</groupId>
49+
<artifactId>*</artifactId>
50+
</exclusion>
51+
</exclusions>
52+
</dependency>
53+
</dependencies>
54+
</project>
55+
56+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
###
2+
# #%L
3+
# License Maven Plugin
4+
# %%
5+
# Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
6+
# %%
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Lesser General Public License as
9+
# published by the Free Software Foundation, either version 3 of the
10+
# License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Lesser Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Lesser Public
18+
# License along with this program. If not, see
19+
# <http://www.gnu.org/licenses/lgpl-3.0.html>.
20+
# #L%
21+
###
22+
invoker.goals=clean license:aggregate-add-third-party
23+
invoker.failureBehavior=fail-at-end
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
#%L
4+
License Maven Plugin
5+
%%
6+
Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
7+
%%
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU Lesser General Public License as
10+
published by the Free Software Foundation, either version 3 of the
11+
License, or (at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Lesser Public License for more details.
17+
18+
You should have received a copy of the GNU General Lesser Public
19+
License along with this program. If not, see
20+
<http://www.gnu.org/licenses/lgpl-3.0.html>.
21+
#L%
22+
-->
23+
24+
<project xmlns="http://maven.apache.org/POM/4.0.0"
25+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
26+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
27+
28+
<modelVersion>4.0.0</modelVersion>
29+
30+
<groupId>org.codehaus.mojo.license.test</groupId>
31+
<artifactId>test-aggregate-add-third-party-filtered</artifactId>
32+
<version>@project.version@</version>
33+
34+
<modules>
35+
<module>child1</module>
36+
<module>child2</module>
37+
<module>child3</module>
38+
</modules>
39+
40+
<name>License Test :: filtered-modules</name>
41+
42+
<packaging>pom</packaging>
43+
44+
<properties>
45+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
46+
<license.generateBundle>true</license.generateBundle>
47+
<license.verbose>true</license.verbose>
48+
</properties>
49+
50+
<build>
51+
<pluginManagement>
52+
<plugins>
53+
<plugin>
54+
<groupId>org.codehaus.mojo</groupId>
55+
<artifactId>license-maven-plugin</artifactId>
56+
<version>@project.version@</version>
57+
<configuration>
58+
<includedModules>
59+
<includedModule>test-aggregate-add-third-party-filtered-child1</includedModule>
60+
<includedModule>test-aggregate-add-third-party-filtered-child3</includedModule>
61+
</includedModules>
62+
<excludedModules>
63+
<excludedModule>test-aggregate-add-third-party-filtered-child1</excludedModule>
64+
</excludedModules>
65+
</configuration>
66+
</plugin>
67+
</plugins>
68+
</pluginManagement>
69+
</build>
70+
</project>
71+
72+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* #%L
3+
* License Maven Plugin
4+
* %%
5+
* Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 3 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
20+
* #L%
21+
*/
22+
23+
file = new File(basedir, 'target/generated-sources/license/THIRD-PARTY.txt');
24+
assert file.exists();
25+
content = file.text;
26+
assert !content.contains('The project has no dependencies.');
27+
assert !content.contains('commons-logging:commons-logging:1.1.1');
28+
assert !content.contains('junit:junit');
29+
assert content.contains('org.springframework.security:spring-security-core:6.4.5');
30+
31+
return true

src/main/java/org/codehaus/mojo/license/AggregateDownloadLicensesMojo.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.codehaus.mojo.license.api.ResolvedProjectDependencies;
3737
import org.codehaus.mojo.license.download.LicensedArtifact;
3838
import org.codehaus.mojo.license.download.LicensedArtifactResolver;
39+
import org.codehaus.mojo.license.utils.ModuleHelper;
3940
import org.codehaus.mojo.license.utils.MojoHelper;
4041

4142
/**
@@ -100,6 +101,22 @@ public class AggregateDownloadLicensesMojo extends AbstractDownloadLicensesMojo
100101
@Parameter(property = "reactorProjects", readonly = true, required = true)
101102
private List<MavenProject> reactorProjects;
102103

104+
/**
105+
* An array of modules to include in analysis.
106+
*
107+
* @since 2.6.0
108+
*/
109+
@Parameter(property = "license.includedModules")
110+
private String[] includedModules;
111+
112+
/**
113+
* An array of modules to exclude in analysis.
114+
*
115+
* @since 2.6.0
116+
*/
117+
@Parameter(property = "license.excludedModules")
118+
private String[] excludedModules;
119+
103120
/**
104121
* Extract and use non-maven data for license, copyright and vendor information,
105122
* including the plugins' archive file content.
@@ -134,7 +151,9 @@ protected boolean isSkip() {
134151
protected Map<String, LicensedArtifact> getDependencies() {
135152
final Map<String, LicensedArtifact> result = new TreeMap<>();
136153

137-
for (MavenProject p : reactorProjects) {
154+
List<MavenProject> modules = ModuleHelper.getFilteredModules(reactorProjects, includedModules, excludedModules);
155+
156+
for (MavenProject p : modules) {
138157
licensedArtifactResolver.loadProjectDependencies(
139158
new ResolvedProjectDependencies(p.getArtifacts(), MojoHelper.getDependencyArtifacts(p)),
140159
this,

src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.codehaus.mojo.license.api.DependenciesTool;
4747
import org.codehaus.mojo.license.api.ThirdPartyTool;
4848
import org.codehaus.mojo.license.model.LicenseMap;
49+
import org.codehaus.mojo.license.utils.ModuleHelper;
4950
import org.codehaus.mojo.license.utils.SortedProperties;
5051
import org.slf4j.Logger;
5152
import org.slf4j.LoggerFactory;
@@ -84,6 +85,22 @@ public class AggregatorAddThirdPartyMojo extends AbstractAddThirdPartyMojo {
8485
@Parameter(property = "reactorProjects", readonly = true, required = true)
8586
private List<MavenProject> reactorProjects;
8687

88+
/**
89+
* An array of modules to include in analysis.
90+
*
91+
* @since 2.6.0
92+
*/
93+
@Parameter(property = "license.includedModules")
94+
private String[] includedModules;
95+
96+
/**
97+
* An array of modules to exclude in analysis.
98+
*
99+
* @since 2.6.0
100+
*/
101+
@Parameter(property = "license.excludedModules")
102+
private String[] excludedModules;
103+
87104
/**
88105
* To skip execution of this mojo.
89106
*
@@ -173,8 +190,11 @@ protected void init() throws Exception {
173190
*/
174191
@Override
175192
protected void doAction() throws Exception {
193+
194+
List<MavenProject> modules = ModuleHelper.getFilteredModules(reactorProjects, includedModules, excludedModules);
195+
176196
if (isVerbose()) {
177-
LOG.info("After executing on {} project(s)", reactorProjects.size());
197+
LOG.info("After executing on {} project(s)", modules.size());
178198
}
179199

180200
licenseMap = new LicenseMap();
@@ -218,7 +238,7 @@ protected void doAction() throws Exception {
218238

219239
LOG.info("The default plugin hint is: " + addThirdPartyRoleHint);
220240

221-
for (MavenProject reactorProject : reactorProjects) {
241+
for (MavenProject reactorProject : modules) {
222242
if (getProject().equals(reactorProject) && !acceptPomPackaging) {
223243
// does not process this pom unless specified
224244
continue;

0 commit comments

Comments
 (0)