Skip to content

Commit 984fd88

Browse files
committed
[MNG-7344] Integration test for effective pom with imports
1 parent da642e9 commit 984fd88

File tree

8 files changed

+330
-0
lines changed

8 files changed

+330
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.it;
20+
21+
import java.io.File;
22+
23+
import org.apache.maven.shared.verifier.Verifier;
24+
import org.apache.maven.shared.verifier.util.ResourceExtractor;
25+
import org.junit.jupiter.api.Test;
26+
27+
public class MavenITmng7344EffectivePomPluginTest extends AbstractMavenIntegrationTestCase {
28+
public MavenITmng7344EffectivePomPluginTest() {
29+
super("[4.0.0-alpha-13,)");
30+
}
31+
32+
@Test
33+
public void testIt() throws Exception {
34+
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-7344-effective-pom");
35+
36+
Verifier verifier = newVerifier(new File(testDir, "plugin").getAbsolutePath(), "remote");
37+
verifier.addCliArgument("install");
38+
verifier.execute();
39+
verifier.verifyErrorFreeLog();
40+
41+
for (String childFolder : new String[] {"dep-x", "bom-parent", "bom-intermediate"}) {
42+
verifier = newVerifier(new File(testDir, childFolder).getAbsolutePath());
43+
verifier.addCliArgument("install");
44+
verifier.execute();
45+
verifier.verifyErrorFreeLog();
46+
}
47+
48+
verifier = newVerifier(new File(testDir, "consumer").getAbsolutePath());
49+
verifier.setForkJvm(true);
50+
verifier.addCliArgument("compile");
51+
verifier.execute();
52+
53+
verifier.verifyTextInLog("[INFO] bom-intermediate-1.0-SNAPSHOT.pom @ 8:3");
54+
}
55+
}

core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ public TestSuiteOrdering() {
775775
suite.addTestSuite(MavenIT0010DependencyClosureResolutionTest.class);
776776
suite.addTestSuite(MavenIT0009GoalConfigurationTest.class);
777777
suite.addTestSuite(MavenIT0008SimplePluginTest.class);
778+
suite.addTestSuite(MavenITmng7344EffectivePomPluginTest.class);
778779
/*
779780
* Add tests in reverse alpha order above.
780781
*/
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.apache.maven.its.mng7344</groupId>
7+
<artifactId>bom-intermediate</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
<packaging>pom</packaging>
10+
11+
<dependencyManagement>
12+
<dependencies>
13+
<dependency>
14+
<groupId>org.apache.maven.its.mng7344</groupId>
15+
<artifactId>bom-parent</artifactId>
16+
<version>1.0-SNAPSHOT</version>
17+
<type>pom</type>
18+
<scope>import</scope>
19+
</dependency>
20+
</dependencies>
21+
</dependencyManagement>
22+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.apache.maven.its.mng7344</groupId>
7+
<artifactId>bom-parent</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
<packaging>pom</packaging>
10+
11+
<dependencyManagement>
12+
<dependencies>
13+
<dependency>
14+
<groupId>org.apache.maven.its.mng7344</groupId>
15+
<artifactId>dep-x</artifactId>
16+
<version>2</version>
17+
</dependency>
18+
</dependencies>
19+
</dependencyManagement>
20+
</project>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<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">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>org.apache.maven.its.mng7344</groupId>
24+
<artifactId>consumer</artifactId>
25+
<version>1.0-SNAPSHOT</version>
26+
27+
<dependencyManagement>
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.apache.maven.its.mng7344</groupId>
31+
<artifactId>bom-intermediate</artifactId>
32+
<version>1.0-SNAPSHOT</version>
33+
<type>pom</type>
34+
<scope>import</scope>
35+
</dependency>
36+
</dependencies>
37+
</dependencyManagement>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>org.apache.maven.its.mng7344</groupId>
42+
<artifactId>dep-x</artifactId>
43+
</dependency>
44+
</dependencies>
45+
46+
<build>
47+
<plugins>
48+
<plugin>
49+
<groupId>org.apache.maven.its.mng7344</groupId>
50+
<artifactId>mng-7344-maven-plugin</artifactId>
51+
<version>1.0-SNAPSHOT</version>
52+
<executions>
53+
<execution>
54+
<id>effective-pom</id>
55+
<goals>
56+
<goal>effective-pom</goal>
57+
</goals>
58+
<phase>compile</phase>
59+
</execution>
60+
</executions>
61+
</plugin>
62+
</plugins>
63+
</build>
64+
65+
</project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.apache.maven.its.mng7344</groupId>
7+
<artifactId>dep-x</artifactId>
8+
<version>2</version>
9+
</project>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<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">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>org.apache.maven.its.mng7344</groupId>
24+
<artifactId>mng-7344-maven-plugin</artifactId>
25+
<version>1.0-SNAPSHOT</version>
26+
<packaging>maven-plugin</packaging>
27+
28+
<prerequisites>
29+
<maven>${mavenVersion}</maven>
30+
</prerequisites>
31+
32+
<properties>
33+
<javaVersion>8</javaVersion>
34+
<mavenVersion>3.6.3</mavenVersion>
35+
<mavenPluginToolsVersion>3.9.0</mavenPluginToolsVersion>
36+
</properties>
37+
38+
<dependencies>
39+
<dependency>
40+
<groupId>org.apache.maven</groupId>
41+
<artifactId>maven-plugin-api</artifactId>
42+
<version>${mavenVersion}</version>
43+
<scope>provided</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.apache.maven</groupId>
47+
<artifactId>maven-core</artifactId>
48+
<version>${mavenVersion}</version>
49+
<scope>provided</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.apache.maven</groupId>
53+
<artifactId>maven-model</artifactId>
54+
<version>${mavenVersion}</version>
55+
<scope>provided</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.apache.maven.plugin-tools</groupId>
59+
<artifactId>maven-plugin-annotations</artifactId>
60+
<version>${mavenPluginToolsVersion}</version>
61+
<scope>provided</scope>
62+
</dependency>
63+
</dependencies>
64+
65+
<build>
66+
<pluginManagement>
67+
<plugins>
68+
<plugin>
69+
<groupId>org.apache.maven.plugins</groupId>
70+
<artifactId>maven-plugin-plugin</artifactId>
71+
<version>${mavenPluginToolsVersion}</version>
72+
</plugin>
73+
</plugins>
74+
</pluginManagement>
75+
</build>
76+
</project>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package testmojo;
20+
21+
/*
22+
* Licensed to the Apache Software Foundation (ASF) under one
23+
* or more contributor license agreements. See the NOTICE file
24+
* distributed with this work for additional information
25+
* regarding copyright ownership. The ASF licenses this file
26+
* to you under the Apache License, Version 2.0 (the
27+
* "License"); you may not use this file except in compliance
28+
* with the License. You may obtain a copy of the License at
29+
*
30+
* http://www.apache.org/licenses/LICENSE-2.0
31+
*
32+
* Unless required by applicable law or agreed to in writing,
33+
* software distributed under the License is distributed on an
34+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
35+
* KIND, either express or implied. See the License for the
36+
* specific language governing permissions and limitations
37+
* under the License.
38+
*/
39+
40+
import java.lang.reflect.Field;
41+
import java.util.List;
42+
43+
import org.apache.maven.model.Dependency;
44+
import org.apache.maven.plugin.AbstractMojo;
45+
import org.apache.maven.plugin.MojoExecutionException;
46+
import org.apache.maven.plugin.MojoFailureException;
47+
import org.apache.maven.plugins.annotations.Mojo;
48+
import org.apache.maven.plugins.annotations.Parameter;
49+
import org.apache.maven.project.MavenProject;
50+
51+
@Mojo(name = "effective-pom", aggregator = true)
52+
public class EffectivePomMojo extends AbstractMojo {
53+
54+
@Parameter(defaultValue = "${reactorProjects}", required = true, readonly = true)
55+
private List<MavenProject> projects;
56+
57+
public void execute() throws MojoExecutionException, MojoFailureException {
58+
projects.stream()
59+
.map(MavenProject::getDependencyManagement)
60+
.map(depMgt -> depMgt != null ? depMgt.getDependencies() : null)
61+
.filter(dependencies -> dependencies != null)
62+
.flatMap(List::stream)
63+
.forEach(dependency -> {
64+
getLog().info("" + dependency);
65+
try {
66+
getLog().info(getImportedFrom(dependency));
67+
} catch (Exception ex) {
68+
getLog().error("Failed to get importedFrom");
69+
}
70+
});
71+
}
72+
73+
private String getImportedFrom(Dependency dependency) throws Exception {
74+
Field delegateField = Class.forName("org.apache.maven.model.BaseObject").getDeclaredField("delegate");
75+
delegateField.setAccessible(true);
76+
Object delegate = delegateField.get(dependency);
77+
delegateField.setAccessible(false);
78+
Object importedFrom = delegate.getClass().getMethod("getImportedFrom").invoke(delegate);
79+
80+
return ("" + importedFrom).replaceAll("^.*[\\\\/]", "");
81+
}
82+
}

0 commit comments

Comments
 (0)