From 552733c90772f5e1a698aa6c2bef3cff41dc11a5 Mon Sep 17 00:00:00 2001 From: Mikolaj Izdebski Date: Mon, 7 Oct 2013 16:31:54 +0200 Subject: [PATCH] Take stereotypes into account during dependency extraction --- .../dependency/impl/BuildDependencyVisitor.java | 16 ++++++---- .../dependency/impl/RuntimeDependencyVisitor.java | 10 +++--- .../fedoraproject/maven/utils/ArtifactUtils.java | 37 ++++++++++++++++++++++ 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/xmvn-core/src/main/java/org/fedoraproject/maven/dependency/impl/BuildDependencyVisitor.java b/xmvn-core/src/main/java/org/fedoraproject/maven/dependency/impl/BuildDependencyVisitor.java index 04dff90..0d47850 100644 --- a/xmvn-core/src/main/java/org/fedoraproject/maven/dependency/impl/BuildDependencyVisitor.java +++ b/xmvn-core/src/main/java/org/fedoraproject/maven/dependency/impl/BuildDependencyVisitor.java @@ -75,9 +75,11 @@ class BuildDependencyVisitor if ( !buildScopes.contains( dependency.getScope() ) ) return; - result.addDependencyArtifact( new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), - dependency.getClassifier(), dependency.getType(), - dependency.getVersion() ) ); + result.addDependencyArtifact( ArtifactUtils.createTypedArtifact( dependency.getGroupId(), + dependency.getArtifactId(), + dependency.getType(), + dependency.getClassifier(), + dependency.getVersion() ) ); } @Override @@ -111,8 +113,10 @@ class BuildDependencyVisitor if ( !runtimeScopes.contains( dependency.getScope() ) ) return; - result.addDependencyArtifact( new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), - dependency.getClassifier(), dependency.getType(), - dependency.getVersion() ) ); + result.addDependencyArtifact( ArtifactUtils.createTypedArtifact( dependency.getGroupId(), + dependency.getArtifactId(), + dependency.getType(), + dependency.getClassifier(), + dependency.getVersion() ) ); } } diff --git a/xmvn-core/src/main/java/org/fedoraproject/maven/dependency/impl/RuntimeDependencyVisitor.java b/xmvn-core/src/main/java/org/fedoraproject/maven/dependency/impl/RuntimeDependencyVisitor.java index 6ef22b9..4bcc8ad 100644 --- a/xmvn-core/src/main/java/org/fedoraproject/maven/dependency/impl/RuntimeDependencyVisitor.java +++ b/xmvn-core/src/main/java/org/fedoraproject/maven/dependency/impl/RuntimeDependencyVisitor.java @@ -19,8 +19,8 @@ import java.util.Arrays; import java.util.List; import org.apache.maven.model.Dependency; -import org.eclipse.aether.artifact.DefaultArtifact; import org.fedoraproject.maven.model.AbstractModelVisitor; +import org.fedoraproject.maven.utils.ArtifactUtils; /** * @author Mikolaj Izdebski @@ -43,8 +43,10 @@ class RuntimeDependencyVisitor if ( !scopes.contains( dependency.getScope() ) ) return; - result.addDependencyArtifact( new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), - dependency.getClassifier(), dependency.getType(), - dependency.getVersion() ) ); + result.addDependencyArtifact( ArtifactUtils.createTypedArtifact( dependency.getGroupId(), + dependency.getArtifactId(), + dependency.getType(), + dependency.getClassifier(), + dependency.getVersion() ) ); } } diff --git a/xmvn-core/src/main/java/org/fedoraproject/maven/utils/ArtifactUtils.java b/xmvn-core/src/main/java/org/fedoraproject/maven/utils/ArtifactUtils.java index b6ef806..b4a4062 100644 --- a/xmvn-core/src/main/java/org/fedoraproject/maven/utils/ArtifactUtils.java +++ b/xmvn-core/src/main/java/org/fedoraproject/maven/utils/ArtifactUtils.java @@ -23,10 +23,13 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.pull.XmlSerializer; import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.ArtifactType; import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.artifact.DefaultArtifactType; /** * @author Mikolaj Izdebski @@ -179,4 +182,38 @@ public class ArtifactUtils Xpp3Dom dom = toXpp3Dom( artifact, tag ); dom.writeToSerializer( namespace, serializer ); } + + private static final Map stereotypes = new HashMap<>(); + + private static void addStereotype( String type, String extension, String classifier ) + { + stereotypes.put( type, new DefaultArtifactType( type, extension, classifier, "java" ) ); + } + + // The list was taken from MavenRepositorySystemUtils in maven-aether-provider. + static + { + addStereotype( "maven-plugin", "jar", "" ); + addStereotype( "ejb", "jar", "" ); + addStereotype( "ejb-client", "jar", "client" ); + addStereotype( "test-jar", "jar", "tests" ); + addStereotype( "javadoc", "jar", "javadoc" ); + addStereotype( "java-source", "jar", "sources" ); + } + + public static Artifact createTypedArtifact( String groupId, String artifactId, String type, String classifier, + String version ) + { + String extension = type; + + ArtifactType artifactType = stereotypes.get( type ); + if ( artifactType != null ) + { + extension = artifactType.getExtension(); + if ( StringUtils.isEmpty( classifier ) ) + classifier = artifactType.getClassifier(); + } + + return new DefaultArtifact( groupId, artifactId, classifier, extension, version ); + } } -- 1.8.3.1