-
Notifications
You must be signed in to change notification settings - Fork 94
Fix for #408, ensure nested dependency exclusions aren't overrided #485
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
treilhes
wants to merge
16
commits into
mojohaus:master
Choose a base branch
from
treilhes:master
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 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5588879
Fix for #408 ensure nested exclusion aren't overrided
treilhes 0cd0ddf
Add mistakenly removed header
treilhes d4c9ff4
appeasing spotless with static imports a the bottom
treilhes 412751d
restored providing project dependencies to collect request
treilhes d3b0527
ensure conflict are resolved successfully by discarding looser deps
treilhes 90643f1
fix spotless issue
treilhes 5b9a7e2
test dependencies musn't override application dependencies
treilhes bb202f6
re-add again this facetious header that keep disapearing
treilhes 11337cf
Ensure compatibility with maven 3.6.3
treilhes 4fae9e1
Update src/test/java/org/codehaus/mojo/flatten/FlattenMojoNestedExclu…
treilhes 7b768d7
Update src/test/java/org/codehaus/mojo/flatten/FlattenMojoConflictWin…
treilhes 6fe45a6
Update src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
treilhes 6e914f0
Update src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
treilhes ce21acc
Update src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
treilhes 4a90434
Update src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
treilhes 111a5d4
removed loop on projectDependencies as it does not contains profile deps
treilhes 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
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
150 changes: 150 additions & 0 deletions
150
src/test/java/org/codehaus/mojo/flatten/FlattenMojoConflictWinnerTest.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,150 @@ | ||
| package org.codehaus.mojo.flatten; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import org.apache.maven.execution.DefaultMavenExecutionRequest; | ||
| import org.apache.maven.execution.DefaultMavenExecutionResult; | ||
| import org.apache.maven.execution.MavenExecutionRequest; | ||
| import org.apache.maven.execution.MavenExecutionResult; | ||
| import org.apache.maven.execution.MavenSession; | ||
| import org.apache.maven.model.Dependency; | ||
| import org.apache.maven.plugin.testing.MojoRule; | ||
| import org.apache.maven.project.MavenProject; | ||
| import org.apache.maven.project.ProjectBuilder; | ||
| import org.apache.maven.project.ProjectBuildingException; | ||
| import org.apache.maven.project.ProjectBuildingRequest; | ||
| import org.apache.maven.project.ProjectBuildingResult; | ||
| import org.apache.maven.repository.internal.MavenRepositorySystemUtils; | ||
| import org.codehaus.plexus.component.repository.exception.ComponentLookupException; | ||
| import org.eclipse.aether.DefaultRepositorySystemSession; | ||
| import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; | ||
| import org.eclipse.aether.repository.LocalRepository; | ||
| import org.eclipse.aether.repository.LocalRepositoryManager; | ||
| import org.eclipse.aether.repository.NoLocalRepositoryManagerException; | ||
| import org.junit.After; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| /** | ||
| * Test-Case for {@link FlattenMojo}. | ||
| */ | ||
| public class FlattenMojoConflictWinnerTest { | ||
|
|
||
| private static final String PATH = "src/test/resources/conflict-winner/"; | ||
| private static final String POM = PATH + "pom.xml"; | ||
| private static final String FLATTENED_POM = PATH + ".flattened-pom.xml"; | ||
|
|
||
| private static final String REPO_PATH = "src/test/resources/conflict-winner/repository/"; | ||
|
|
||
| @Rule | ||
| public MojoRule rule = new MojoRule(); | ||
|
|
||
| /** | ||
| * Test method to check that version conflict are correctly honored. Two levels | ||
treilhes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * of dependencies are defined for this test: | ||
| * <ul> | ||
| * <li>A depends on B 0.0.1</li> | ||
| * <li>B 0.0.2</li> | ||
| * </ul> | ||
| * | ||
| * The tested pom depends on A and B. It is then expected that B use version | ||
| * 0.0.2 in the flattened pom because B 0.0.2 is closer to the root. | ||
| * | ||
| * 1.7.3 of the plugin was handling this case correctly but since solving #408 | ||
| * it is not the case anymore. By removing resolved transitive dependencies from | ||
| * the collect request parameters, the conflict resolution is not applied anymore | ||
| * as resolved transitive dependencies does not appear first anymore. This test ensure | ||
| * that the conflicting dependencies are correctly filtered from collect | ||
| * results and the winner version is kept. | ||
| * | ||
| * @see <a href= | ||
| * "https://github.com/mojohaus/flatten-maven-plugin/issues/408">Issue | ||
| * #408</a> | ||
| * | ||
| * @since 1.7.3+ | ||
| * @throws Exception if something goes wrong. | ||
| */ | ||
| @Test | ||
| public void testConflictResolutionIsEnforced() throws Exception { | ||
|
|
||
| MavenSession session = newMavenSession(REPO_PATH); | ||
| MavenProject project = loadResolvedProject(session, new File(POM)); | ||
| FlattenMojo flattenMojo = (FlattenMojo) rule.lookupConfiguredMojo(project, "flatten"); | ||
| rule.setVariableValueToObject(flattenMojo, "session", session); | ||
|
|
||
| flattenMojo.execute(); | ||
|
|
||
| MavenProject flattenedProject = loadResolvedProject(session, new File(FLATTENED_POM)); | ||
|
|
||
| List<Dependency> bDependencies = flattenedProject.getDependencies().stream() | ||
| .filter(dep -> dep.getArtifactId().equals("b")) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| assertThat(bDependencies) | ||
| .hasSize(1) | ||
| .withFailMessage("There must be only one B dependency in flattened POM.") | ||
| .allMatch( | ||
| dep -> dep.getVersion().equals("0.0.2"), | ||
| "B dependency version 0.0.2 must win the conflicting version match in flattened POM."); | ||
| } | ||
|
|
||
| /** | ||
| * Load a maven project with resolved dependencies (same as standard maven execution). | ||
| * By default dependencies are not resolved by MojoRule and project.getArtifacts is empty | ||
| * @param session the Maven session to use for building the project | ||
| * @param pomFile the POM file to load and resolve dependencies for | ||
| * @return the resolved MavenProject instance with dependencies | ||
| * @throws ComponentLookupException if the ProjectBuilder component cannot be found | ||
| * @throws ProjectBuildingException if an error occurs while building the project | ||
| */ | ||
| private MavenProject loadResolvedProject(MavenSession session, File pomFile) | ||
| throws ComponentLookupException, ProjectBuildingException { | ||
| ProjectBuilder projectBuilder = rule.lookup(ProjectBuilder.class); | ||
|
|
||
| ProjectBuildingRequest buildingRequest = session.getProjectBuildingRequest(); | ||
| buildingRequest.setResolveDependencies(true); | ||
|
|
||
| ProjectBuildingResult result = projectBuilder.build(pomFile, buildingRequest); | ||
| return result.getProject(); | ||
| } | ||
|
|
||
| /** | ||
| * Create a new maven session with a local repository at the given path. | ||
| * @param repoPath the path to the local repository to use for the session | ||
| * @return a new MavenSession instance configured with the specified local repository | ||
| * @throws NoLocalRepositoryManagerException if the local repository manager cannot be created | ||
| */ | ||
| protected MavenSession newMavenSession(String repoPath) throws NoLocalRepositoryManagerException { | ||
| MavenExecutionRequest request = new DefaultMavenExecutionRequest(); | ||
| MavenExecutionResult result = new DefaultMavenExecutionResult(); | ||
|
|
||
| MavenSession session = | ||
| new MavenSession(rule.getContainer(), MavenRepositorySystemUtils.newSession(), request, result); | ||
| LocalRepository testRepo = new LocalRepository(repoPath); | ||
| LocalRepositoryManager lrm = | ||
| new SimpleLocalRepositoryManagerFactory().newInstance(session.getRepositorySession(), testRepo); | ||
|
|
||
| ((DefaultRepositorySystemSession) session.getRepositorySession()).setLocalRepositoryManager(lrm); | ||
| return session; | ||
| } | ||
|
|
||
| /** | ||
| * After test method. Removes flattened-pom.xml file which is created during test. | ||
| * | ||
| * @throws IOException if can't remove file. | ||
| */ | ||
| @After | ||
| public void removeFlattenedPom() throws IOException { | ||
| File flattenedPom = new File(FLATTENED_POM); | ||
| if (flattenedPom.exists()) { | ||
| if (!flattenedPom.delete()) { | ||
| throw new IOException("Can't delete " + flattenedPom); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.