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 e187c83b9a..248cf9f3ec 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 @@ -73,6 +73,8 @@ public final class ArtifactModelContainerFactory private String scope; + private String classifier; + private List properties; private static String findBaseUriFrom( List modelProperties ) @@ -112,6 +114,10 @@ public final class ArtifactModelContainerFactory { this.scope = mp.getResolvedValue(); } + else if ( classifier == null && mp.getUri().equals( uri + "/classifier" ) ) + { + this.classifier = mp.getResolvedValue(); + } else if ( type == null && mp.getUri().equals( ProjectUri.Dependencies.Dependency.type ) || mp.getUri().equals(ProjectUri.DependencyManagement.Dependencies.Dependency.type) || mp.getUri().equals(ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.type) @@ -159,6 +165,11 @@ public final class ArtifactModelContainerFactory type = "jar"; } + if ( classifier == null ) + { + classifier = ""; + } + if ( scope == null || scope.equals("provided")) { scope = "compile"; @@ -178,7 +189,8 @@ public final class ArtifactModelContainerFactory } ArtifactModelContainer c = (ArtifactModelContainer) modelContainer; - if ( c.groupId.equals( groupId ) && c.artifactId.equals( artifactId ) && c.type.equals( type ) ) + if ( c.groupId.equals( groupId ) && c.artifactId.equals( artifactId ) && c.type.equals( type ) + && c.classifier.equals( classifier )) { if ( c.version.equals( version ) ) { diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/EnforcerPomTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/EnforcerPomTest.java index 6709fb60a5..dc32a7c449 100644 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/EnforcerPomTest.java +++ b/maven-project-builder/src/test/java/org/apache/maven/project/builder/EnforcerPomTest.java @@ -53,8 +53,15 @@ public class EnforcerPomTest DefaultModelDataSource source = new DefaultModelDataSource(); source.init(domainModel.getModelProperties(), Arrays.asList(new ArtifactModelContainerFactory(), new IdModelContainerFactory())); List containers = source.queryFor(ProjectUri.Dependencies.Dependency.xUri); - assertTrue(containers.size() == 1 ); - assertTrue(contains(ProjectUri.Dependencies.Dependency.version, "v1", containers.get(0))); + assertTrue(containers.size() == 2 ); + + ModelContainer mc0 = containers.get(0); + assertTrue(contains(ProjectUri.Dependencies.Dependency.version, "v1", mc0)); + assertFalse(contains(ProjectUri.Dependencies.Dependency.classifier, "tests", mc0)); + + ModelContainer mc1 = containers.get(1); + assertTrue(contains(ProjectUri.Dependencies.Dependency.version, "v1", mc1)); + assertTrue(contains(ProjectUri.Dependencies.Dependency.classifier, "tests", mc1)); } private boolean contains(String name, String value, ModelContainer modelContainer) {