diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5659ProjectSettingsTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5659ProjectSettingsTest.java deleted file mode 100644 index 3bca7aab8..000000000 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5659ProjectSettingsTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.it; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.File; -import java.io.IOException; -import java.util.Properties; - -import org.apache.maven.shared.verifier.VerificationException; -import org.apache.maven.shared.verifier.Verifier; -import org.apache.maven.shared.verifier.util.ResourceExtractor; -import org.junit.jupiter.api.Test; - -public class MavenITmng5659ProjectSettingsTest extends AbstractMavenIntegrationTestCase { - - public MavenITmng5659ProjectSettingsTest() { - super("[4.0.0-alpha-6,)"); - } - - @Test - public void testProjectSettings() throws IOException, VerificationException { - File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-5659-project-settings"); - Verifier verifier = newVerifier(testDir.getAbsolutePath()); - - verifier.addCliArgument("validate"); - verifier.execute(); - verifier.verifyErrorFreeLog(); - - Properties props; - - verifier.verifyFilePresent("target/pom.properties"); - props = verifier.loadProperties("target/pom.properties"); - assertEquals( - "project.properties.activated", - Boolean.TRUE.toString(), - props.getProperty("project.properties.activated")); - } -} diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7344EffectivePomPluginTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7344EffectivePomPluginTest.java new file mode 100644 index 000000000..b3dc2421b --- /dev/null +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7344EffectivePomPluginTest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.it; + +import java.io.File; + +import org.apache.maven.shared.verifier.Verifier; +import org.apache.maven.shared.verifier.util.ResourceExtractor; +import org.junit.jupiter.api.Test; + +public class MavenITmng7344EffectivePomPluginTest extends AbstractMavenIntegrationTestCase { + public MavenITmng7344EffectivePomPluginTest() { + super("[4.0.0-alpha-13,)"); + } + + @Test + public void testIt() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-7344-effective-pom"); + + Verifier verifier = newVerifier(new File(testDir, "plugin").getAbsolutePath(), "remote"); + verifier.addCliArgument("install"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + for (String childFolder : new String[] {"dep-x", "bom-parent", "bom-intermediate"}) { + verifier = newVerifier(new File(testDir, childFolder).getAbsolutePath()); + verifier.addCliArgument("install"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + } + + verifier = newVerifier(new File(testDir, "consumer").getAbsolutePath()); + verifier.setForkJvm(true); + verifier.addCliArgument("compile"); + verifier.execute(); + + verifier.verifyTextInLog("[INFO] bom-intermediate-1.0-SNAPSHOT.pom @ 8:3"); + } +} diff --git a/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java b/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java index 27fe7d9d0..f8c50ad83 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java @@ -775,6 +775,7 @@ public TestSuiteOrdering() { suite.addTestSuite(MavenIT0010DependencyClosureResolutionTest.class); suite.addTestSuite(MavenIT0009GoalConfigurationTest.class); suite.addTestSuite(MavenIT0008SimplePluginTest.class); + suite.addTestSuite(MavenITmng7344EffectivePomPluginTest.class); /* * Add tests in reverse alpha order above. */ diff --git a/core-it-suite/src/test/resources/mng-7344-effective-pom/bom-intermediate/pom.xml b/core-it-suite/src/test/resources/mng-7344-effective-pom/bom-intermediate/pom.xml new file mode 100644 index 000000000..c45bfd4f3 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-7344-effective-pom/bom-intermediate/pom.xml @@ -0,0 +1,22 @@ + + + + 4.0.0 + + org.apache.maven.its.mng7344 + bom-intermediate + 1.0-SNAPSHOT + pom + + + + + org.apache.maven.its.mng7344 + bom-parent + 1.0-SNAPSHOT + pom + import + + + + diff --git a/core-it-suite/src/test/resources/mng-7344-effective-pom/bom-parent/pom.xml b/core-it-suite/src/test/resources/mng-7344-effective-pom/bom-parent/pom.xml new file mode 100644 index 000000000..88a09bbb8 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-7344-effective-pom/bom-parent/pom.xml @@ -0,0 +1,20 @@ + + + + 4.0.0 + + org.apache.maven.its.mng7344 + bom-parent + 1.0-SNAPSHOT + pom + + + + + org.apache.maven.its.mng7344 + dep-x + 2 + + + + diff --git a/core-it-suite/src/test/resources/mng-7344-effective-pom/consumer/pom.xml b/core-it-suite/src/test/resources/mng-7344-effective-pom/consumer/pom.xml new file mode 100644 index 000000000..fbe9cacba --- /dev/null +++ b/core-it-suite/src/test/resources/mng-7344-effective-pom/consumer/pom.xml @@ -0,0 +1,65 @@ + + + + 4.0.0 + + org.apache.maven.its.mng7344 + consumer + 1.0-SNAPSHOT + + + + + org.apache.maven.its.mng7344 + bom-intermediate + 1.0-SNAPSHOT + pom + import + + + + + + + org.apache.maven.its.mng7344 + dep-x + + + + + + + org.apache.maven.its.mng7344 + mng-7344-maven-plugin + 1.0-SNAPSHOT + + + effective-pom + + effective-pom + + compile + + + + + + + diff --git a/core-it-suite/src/test/resources/mng-7344-effective-pom/dep-x/pom.xml b/core-it-suite/src/test/resources/mng-7344-effective-pom/dep-x/pom.xml new file mode 100644 index 000000000..ffc681473 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-7344-effective-pom/dep-x/pom.xml @@ -0,0 +1,9 @@ + + + + 4.0.0 + + org.apache.maven.its.mng7344 + dep-x + 2 + diff --git a/core-it-suite/src/test/resources/mng-7344-effective-pom/plugin/pom.xml b/core-it-suite/src/test/resources/mng-7344-effective-pom/plugin/pom.xml new file mode 100644 index 000000000..5f3afc1dd --- /dev/null +++ b/core-it-suite/src/test/resources/mng-7344-effective-pom/plugin/pom.xml @@ -0,0 +1,76 @@ + + + + 4.0.0 + + org.apache.maven.its.mng7344 + mng-7344-maven-plugin + 1.0-SNAPSHOT + maven-plugin + + + ${mavenVersion} + + + + 8 + 3.6.3 + 3.9.0 + + + + + org.apache.maven + maven-plugin-api + ${mavenVersion} + provided + + + org.apache.maven + maven-core + ${mavenVersion} + provided + + + org.apache.maven + maven-model + ${mavenVersion} + provided + + + org.apache.maven.plugin-tools + maven-plugin-annotations + ${mavenPluginToolsVersion} + provided + + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + ${mavenPluginToolsVersion} + + + + + diff --git a/core-it-suite/src/test/resources/mng-7344-effective-pom/plugin/src/main/java/testmojo/EffectivePomMojo.java b/core-it-suite/src/test/resources/mng-7344-effective-pom/plugin/src/main/java/testmojo/EffectivePomMojo.java new file mode 100644 index 000000000..6bf90cc1f --- /dev/null +++ b/core-it-suite/src/test/resources/mng-7344-effective-pom/plugin/src/main/java/testmojo/EffectivePomMojo.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package testmojo; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.lang.reflect.Field; +import java.util.List; + +import org.apache.maven.model.Dependency; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; + +@Mojo(name = "effective-pom", aggregator = true) +public class EffectivePomMojo extends AbstractMojo { + + @Parameter(defaultValue = "${reactorProjects}", required = true, readonly = true) + private List projects; + + public void execute() throws MojoExecutionException, MojoFailureException { + projects.stream() + .map(MavenProject::getDependencyManagement) + .map(depMgt -> depMgt != null ? depMgt.getDependencies() : null) + .filter(dependencies -> dependencies != null) + .flatMap(List::stream) + .forEach(dependency -> { + getLog().info("" + dependency); + try { + getLog().info(getImportedFrom(dependency)); + } catch (Exception ex) { + getLog().error("Failed to get importedFrom"); + } + }); + } + + private String getImportedFrom(Dependency dependency) throws Exception { + Field delegateField = Class.forName("org.apache.maven.model.BaseObject").getDeclaredField("delegate"); + delegateField.setAccessible(true); + Object delegate = delegateField.get(dependency); + delegateField.setAccessible(false); + Object importedFrom = delegate.getClass().getMethod("getImportedFrom").invoke(delegate); + + return ("" + importedFrom).replaceAll("^.*[\\\\/]", ""); + } +}