-
Notifications
You must be signed in to change notification settings - Fork 70
[MNG-7344] Integration test for effective pom with imports #333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
juulhobert
wants to merge
5
commits into
apache:master
Choose a base branch
from
infosupport:MPH-183_dependency-management-hierarchy-inputsource
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6c28e17
[MNG-7344] Integration test for effective pom with imports
juulhobert 50263d6
Removed line ref, added prefix for matching the right log part
juulhobert debf660
Moved test to the top in the test suite ordering
juulhobert 7be71e6
Updated version range to start from beta-4 for mng7334 test
juulhobert 1b16b7a
Merge branch 'master' of github.com:apache/maven-integration-testing …
juulhobert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7344EffectivePomPluginTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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("[IMPORTED FROM] bom-intermediate-1.0-SNAPSHOT.pom"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
core-it-suite/src/test/resources/mng-7344-effective-pom/bom-intermediate/pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
|
||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>org.apache.maven.its.mng7344</groupId> | ||
| <artifactId>bom-intermediate</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| <packaging>pom</packaging> | ||
|
|
||
| <dependencyManagement> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.maven.its.mng7344</groupId> | ||
| <artifactId>bom-parent</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| <type>pom</type> | ||
| <scope>import</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </dependencyManagement> | ||
| </project> |
20 changes: 20 additions & 0 deletions
20
core-it-suite/src/test/resources/mng-7344-effective-pom/bom-parent/pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
|
||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>org.apache.maven.its.mng7344</groupId> | ||
| <artifactId>bom-parent</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| <packaging>pom</packaging> | ||
|
|
||
| <dependencyManagement> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.maven.its.mng7344</groupId> | ||
| <artifactId>dep-x</artifactId> | ||
| <version>2</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </dependencyManagement> | ||
| </project> |
65 changes: 65 additions & 0 deletions
65
core-it-suite/src/test/resources/mng-7344-effective-pom/consumer/pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| 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. | ||
| --> | ||
| <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.apache.maven.its.mng7344</groupId> | ||
| <artifactId>consumer</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
|
|
||
| <dependencyManagement> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.maven.its.mng7344</groupId> | ||
| <artifactId>bom-intermediate</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| <type>pom</type> | ||
| <scope>import</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </dependencyManagement> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.maven.its.mng7344</groupId> | ||
| <artifactId>dep-x</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.its.mng7344</groupId> | ||
| <artifactId>mng-7344-maven-plugin</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| <executions> | ||
| <execution> | ||
| <id>effective-pom</id> | ||
| <goals> | ||
| <goal>effective-pom</goal> | ||
| </goals> | ||
| <phase>compile</phase> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| </project> |
9 changes: 9 additions & 0 deletions
9
core-it-suite/src/test/resources/mng-7344-effective-pom/dep-x/pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
|
||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>org.apache.maven.its.mng7344</groupId> | ||
| <artifactId>dep-x</artifactId> | ||
| <version>2</version> | ||
| </project> |
76 changes: 76 additions & 0 deletions
76
core-it-suite/src/test/resources/mng-7344-effective-pom/plugin/pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| 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. | ||
| --> | ||
| <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.apache.maven.its.mng7344</groupId> | ||
| <artifactId>mng-7344-maven-plugin</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| <packaging>maven-plugin</packaging> | ||
|
|
||
| <prerequisites> | ||
| <maven>${mavenVersion}</maven> | ||
| </prerequisites> | ||
|
|
||
| <properties> | ||
| <javaVersion>8</javaVersion> | ||
| <mavenVersion>3.6.3</mavenVersion> | ||
| <mavenPluginToolsVersion>3.9.0</mavenPluginToolsVersion> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.maven</groupId> | ||
| <artifactId>maven-plugin-api</artifactId> | ||
| <version>${mavenVersion}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.maven</groupId> | ||
| <artifactId>maven-core</artifactId> | ||
| <version>${mavenVersion}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.maven</groupId> | ||
| <artifactId>maven-model</artifactId> | ||
| <version>${mavenVersion}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.maven.plugin-tools</groupId> | ||
| <artifactId>maven-plugin-annotations</artifactId> | ||
| <version>${mavenPluginToolsVersion}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <pluginManagement> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-plugin-plugin</artifactId> | ||
| <version>${mavenPluginToolsVersion}</version> | ||
| </plugin> | ||
| </plugins> | ||
| </pluginManagement> | ||
| </build> | ||
| </project> |
82 changes: 82 additions & 0 deletions
82
...test/resources/mng-7344-effective-pom/plugin/src/main/java/testmojo/EffectivePomMojo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<MavenProject> 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("[IMPORTED FROM] " + 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("^.*[\\\\/]", ""); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.