From 93ec09c8a548c92974673acf33a3fbb2f8cce81a Mon Sep 17 00:00:00 2001 From: Britton Isbell Date: Tue, 27 Jan 2009 21:48:22 +0000 Subject: [PATCH] MNG-4010: Remove duplicate dependency exclusions. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@738256 13f79535-47bb-0310-9956-ffa450edef68 --- .../ArtifactModelContainerFactory.java | 21 +++++--- .../maven/project/builder/PomTransformer.java | 50 ++++++++++++------- .../project/builder/rules/DependencyRule.java | 19 +++++++ .../project/builder/PomConstructionTest.java | 31 +++++++++++- .../dependencies-different-versions/pom.xml | 18 +++++++ .../dependency-scope/pom.xml | 36 +++++++++++++ .../dependency-scope/sub/pom.xml | 31 ++++++++++++ .../nexus-parent.xml | 34 +++++++++++++ .../duplicate-exclusions-dependency/pom.xml | 33 ++++++++++++ .../sub/pom.xml | 16 ++++++ 10 files changed, 264 insertions(+), 25 deletions(-) create mode 100644 maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DependencyRule.java create mode 100644 maven-project/src/test/resources-project-builder/dependencies-different-versions/pom.xml create mode 100644 maven-project/src/test/resources-project-builder/dependency-scope/pom.xml create mode 100644 maven-project/src/test/resources-project-builder/dependency-scope/sub/pom.xml create mode 100644 maven-project/src/test/resources-project-builder/duplicate-exclusions-dependency/nexus-parent.xml create mode 100644 maven-project/src/test/resources-project-builder/duplicate-exclusions-dependency/pom.xml create mode 100644 maven-project/src/test/resources-project-builder/duplicate-exclusions-dependency/sub/pom.xml diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java index f46a3e021c..04da05f823 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java @@ -35,20 +35,27 @@ public final class ArtifactModelContainerFactory { private static final Collection uris = Collections.unmodifiableList( Arrays.asList( - ProjectUri.DependencyManagement.Dependencies.Dependency.xUri, ProjectUri.Dependencies.Dependency.xUri, + ProjectUri.DependencyManagement.Dependencies.Dependency.xUri, + ProjectUri.Dependencies.Dependency.xUri, ProjectUri.Reporting.Plugins.Plugin.xUri, ProjectUri.Build.PluginManagement.Plugins.Plugin.xUri, - //ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.xUri, - - ProjectUri.Build.Plugins.Plugin.xUri, - //ProjectUri.Build.Plugins.Plugin.Dependencies.Dependency.xUri, - // ProjectUri.Build.Plugins.Plugin.Dependencies.Dependency.Exclusions.Exclusion.xUri, + ProjectUri.Build.Plugins.Plugin.xUri, ProjectUri.Build.Extensions.Extension.xUri ) ); + private final Collection u; + public Collection getUris() { - return uris; + return u; + } + + public ArtifactModelContainerFactory() { + u = uris; + } + + public ArtifactModelContainerFactory(String uri) { + u = Collections.unmodifiableList( Arrays.asList(uri) ); } public ModelContainer create( List modelProperties ) diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java index 092b3f9ba6..018613d4a0 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java @@ -26,6 +26,7 @@ import java.util.*; import org.apache.maven.shared.model.*; import org.apache.maven.shared.model.impl.DefaultModelDataSource; import org.apache.maven.project.builder.rules.ExecutionRule; +import org.apache.maven.project.builder.rules.DependencyRule; /** * Provides methods for transforming model properties into a domain model for the pom classic format and vice versa. @@ -60,6 +61,12 @@ public class PomTransformer null, goals_infos) ); + private static Collection dependency_exclusions = Arrays.asList( + ModelContainerInfo.Factory.createModelContainerInfo( + new IdModelContainerFactory(ProjectUri.DependencyManagement.Dependencies.Dependency.Exclusions.Exclusion.xUri), + new DependencyRule(), null) + ); + //Don't add subcontainers here, breaks MNG-3821 public static final Collection MODEL_CONTAINER_INFOS = Arrays.asList( ModelContainerInfo.Factory.createModelContainerInfo( @@ -68,8 +75,8 @@ public class PomTransformer new IdModelContainerFactory(ProjectUri.PluginRepositories.PluginRepository.xUri), null, null), ModelContainerInfo.Factory.createModelContainerInfo( new IdModelContainerFactory(ProjectUri.Repositories.Repository.xUri), null, null), - // ModelContainerInfo.Factory.createModelContainerInfo( - // new IdModelContainerFactory(ProjectUri.Reporting.Plugins.Plugin.ReportSets.ReportSet.xUri), null, null), + ModelContainerInfo.Factory.createModelContainerInfo( + new ArtifactModelContainerFactory(), null, dependency_exclusions), ModelContainerInfo.Factory.createModelContainerInfo( new IdModelContainerFactory(ProjectUri.Profiles.Profile.xUri), null, null) ); @@ -102,10 +109,10 @@ public class PomTransformer ProjectUri.Contributors.xUri, ProjectUri.Dependencies.xUri, - ProjectUri.Dependencies.Dependency.Exclusions.xUri, + // ProjectUri.Dependencies.Dependency.Exclusions.xUri, ProjectUri.DependencyManagement.Dependencies.xUri, - ProjectUri.DependencyManagement.Dependencies.Dependency.Exclusions.xUri, + // ProjectUri.DependencyManagement.Dependencies.Dependency.Exclusions.xUri, ProjectUri.Developers.xUri, ProjectUri.Developers.Developer.roles, @@ -121,9 +128,9 @@ public class PomTransformer ProjectUri.Profiles.Profile.Build.Resources.xUri, ProjectUri.Profiles.Profile.Build.TestResources.xUri, ProjectUri.Profiles.Profile.Dependencies.xUri, - ProjectUri.Profiles.Profile.Dependencies.Dependency.Exclusions.xUri, + // ProjectUri.Profiles.Profile.Dependencies.Dependency.Exclusions.xUri, ProjectUri.Profiles.Profile.DependencyManagement.Dependencies.xUri, - ProjectUri.Profiles.Profile.DependencyManagement.Dependencies.Dependency.Exclusions.xUri, + // ProjectUri.Profiles.Profile.DependencyManagement.Dependencies.Dependency.Exclusions.xUri, ProjectUri.Profiles.Profile.PluginRepositories.xUri, ProjectUri.Profiles.Profile.Reporting.Plugins.xUri, //ProjectUri.Profiles.Profile.Reporting.Plugins.Plugin.ReportSets.xUri, @@ -133,7 +140,7 @@ public class PomTransformer // ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.Plugin.Executions.xUri, // ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.xURI, ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.Plugin.Dependencies.xUri, - ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.Exclusions.xUri, + // ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.Exclusions.xUri, ProjectUri.Reporting.Plugins.xUri, //ProjectUri.Reporting.Plugins.Plugin.ReportSets.xUri, @@ -187,8 +194,25 @@ public class PomTransformer for ( ModelContainer managementContainer : source.queryFor( ProjectUri.DependencyManagement.Dependencies.Dependency.xUri ) ) { + //Join Duplicate Exclusions Rule (MNG-4010) + ModelDataSource exclusionSource = new DefaultModelDataSource(managementContainer.getProperties(), + Collections.unmodifiableList(Arrays.asList(new ArtifactModelContainerFactory(ProjectUri.DependencyManagement.Dependencies.Dependency.Exclusions.Exclusion.xUri)))); + List exclusionContainers = + exclusionSource.queryFor(ProjectUri.DependencyManagement.Dependencies.Dependency.Exclusions.Exclusion.xUri); + + for(ModelContainer mc : exclusionContainers) + { + for(ModelContainer mc1 : exclusionContainers) + { + if(!mc.equals(mc1) && mc.containerAction(mc1).equals(ModelContainerAction.JOIN)) + { + exclusionSource.joinWithOriginalOrder(mc, mc1); + } + } + } + managementContainer = new ArtifactModelContainerFactory().create( - transformDependencyManagement( managementContainer.getProperties() ) ); + transformDependencyManagement( exclusionSource.getModelProperties() ) ); ModelContainerAction action = dependencyContainer.containerAction( managementContainer ); if ( action.equals( ModelContainerAction.JOIN ) || action.equals( ModelContainerAction.DELETE ) ) { @@ -259,7 +283,7 @@ public class PomTransformer { managementPropertiesWithoutExecutions.removeAll(a.getProperties()); } - //THIS JOIN REVERSES ORDER + source.joinWithOriginalOrder( pluginContainer, new ArtifactModelContainerFactory().create(managementPropertiesWithoutExecutions) ); List pluginExecutionContainers = pluginDatasource.queryFor(ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri); @@ -289,14 +313,6 @@ public class PomTransformer { //MNG-3995 - property lost here joinedContainers.addAll(source.join(b, c).getProperties()); - // ExecutionRule rule = new ExecutionRule(); - // List x = rule.execute(d.getProperties()); - // List x = (!joinedContainer) ? rule.execute(es.getProperties()) : - // ModelTransformerContext.sort(rule.execute(es.getProperties()), - // ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri); - - // source.replace(d, d.createNewInstance(x)); - //REVERSE ORDER HERE joinedExecutionContainers.add(a); } } diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DependencyRule.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DependencyRule.java new file mode 100644 index 0000000000..ef74947e77 --- /dev/null +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DependencyRule.java @@ -0,0 +1,19 @@ +package org.apache.maven.project.builder.rules; + +import org.apache.maven.shared.model.ModelContainerRule; +import org.apache.maven.shared.model.ModelProperty; + +import java.util.List; +import java.util.ArrayList; + +public class DependencyRule implements ModelContainerRule { + public List execute(List modelProperties) { + System.out.println("EXECUTE------------------"); + List properties = new ArrayList(modelProperties); + List goalProperties = new ArrayList(); + List processedProperties = new ArrayList(); + + return processedProperties; + + } +} diff --git a/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java b/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java index ab48cd123d..1db1814ca9 100644 --- a/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java @@ -81,6 +81,34 @@ public class PomConstructionTest assertModelEquals( tester, "child-descriptor", "build/plugins[1]/executions[1]/goals[1]" ); } + /*MNG- + public void testDependencyScope() + throws Exception + { + PomTestWrapper pom = buildPom( "dependency-scope/sub" ); + System.out.println(pom.getDomainModel().asString()); + + } + */ + /*MNG- 4010*/ + public void testDuplicateExclusionsDependency() + throws Exception + { + PomTestWrapper pom = buildPom( "duplicate-exclusions-dependency/sub" ); + assertEquals( 1, ( (List) pom.getValue( "dependencies[1]/exclusions" ) ).size() ); + System.out.println(pom.getDomainModel().asString()); + + } + + /*MNG-4005 - not implemented + public void testDependenciesDifferentVersions() + throws Exception + { + PomTestWrapper pom = buildPom( "dependencies-different-versions" ); + + } + */ + public void testPluginOrder() throws Exception { @@ -150,13 +178,14 @@ public class PomConstructionTest assertEquals( 2, ( (List) pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/rules[1]/bannedDependencies" ) ).size() ); } - /** MNG- */ + /** MNG- public void testFoo() throws Exception { PomTestWrapper pom = buildPom( "foo/sub" ); //System.out.println(pom.getDomainModel().asString()); } + */ /** MNG-3985 */ public void testMultipleRepositories() diff --git a/maven-project/src/test/resources-project-builder/dependencies-different-versions/pom.xml b/maven-project/src/test/resources-project-builder/dependencies-different-versions/pom.xml new file mode 100644 index 0000000000..60ceaf728c --- /dev/null +++ b/maven-project/src/test/resources-project-builder/dependencies-different-versions/pom.xml @@ -0,0 +1,18 @@ + + 4.0.0 + org + org-artifact + 1.0 + + + test + test-artifact + 1.0 + + + test + test-artifact + 1.1 + + + \ No newline at end of file diff --git a/maven-project/src/test/resources-project-builder/dependency-scope/pom.xml b/maven-project/src/test/resources-project-builder/dependency-scope/pom.xml new file mode 100644 index 0000000000..6d34d40cfa --- /dev/null +++ b/maven-project/src/test/resources-project-builder/dependency-scope/pom.xml @@ -0,0 +1,36 @@ + + 4.0.0 + maven-t10 + p0 + pom + p0 + 1.0 + + + + + + maven-test + t10-a + 1.0 + test + + + + maven-test + t10-b + 1.0 + runtime + + + + maven-test + t10-c + 1.0 + test + + + + + + \ No newline at end of file diff --git a/maven-project/src/test/resources-project-builder/dependency-scope/sub/pom.xml b/maven-project/src/test/resources-project-builder/dependency-scope/sub/pom.xml new file mode 100644 index 0000000000..b5d6ef4f28 --- /dev/null +++ b/maven-project/src/test/resources-project-builder/dependency-scope/sub/pom.xml @@ -0,0 +1,31 @@ + + + p0 + maven-t10 + 1.0 + + 4.0.0 + maven-t10 + p1 + pom + p1 + 1.0 + + scm-url + + + + + + maven-test + t10-a + + + + maven-test + t10-c + runtime + + + + \ No newline at end of file diff --git a/maven-project/src/test/resources-project-builder/duplicate-exclusions-dependency/nexus-parent.xml b/maven-project/src/test/resources-project-builder/duplicate-exclusions-dependency/nexus-parent.xml new file mode 100644 index 0000000000..cf695cb38d --- /dev/null +++ b/maven-project/src/test/resources-project-builder/duplicate-exclusions-dependency/nexus-parent.xml @@ -0,0 +1,34 @@ + + 4.0.0 + + org.sonatype.nexus + nexus-parent + 8-SNAPSHOT + + + 1.0-beta-3.0.5-SNAPSHOT + + + + + + org.codehaus.plexus + plexus-container-default + ${plexus.version} + + + commons-logging + commons-logging-api + + + + + + + \ No newline at end of file diff --git a/maven-project/src/test/resources-project-builder/duplicate-exclusions-dependency/pom.xml b/maven-project/src/test/resources-project-builder/duplicate-exclusions-dependency/pom.xml new file mode 100644 index 0000000000..b12db4f084 --- /dev/null +++ b/maven-project/src/test/resources-project-builder/duplicate-exclusions-dependency/pom.xml @@ -0,0 +1,33 @@ + + 4.0.0 + + + org.sonatype.nexus + nexus-parent + 8-SNAPSHOT + nexus-parent.xml + + + org.sonatype.nexus + nexus + pom + Nexus Repository Manager + 1.3.0-SNAPSHOT + + + + + org.codehaus.plexus + plexus-container-default + provided + ${plexus.version} + + + commons-logging + commons-logging-api + + + + + + \ No newline at end of file diff --git a/maven-project/src/test/resources-project-builder/duplicate-exclusions-dependency/sub/pom.xml b/maven-project/src/test/resources-project-builder/duplicate-exclusions-dependency/sub/pom.xml new file mode 100644 index 0000000000..37b166d197 --- /dev/null +++ b/maven-project/src/test/resources-project-builder/duplicate-exclusions-dependency/sub/pom.xml @@ -0,0 +1,16 @@ + + + org.sonatype.nexus + nexus + 1.3.0-SNAPSHOT + + 4.0.0 + nexus-proxy + + + + org.codehaus.plexus + plexus-container-default + + + \ No newline at end of file