Author: pieber Date: Sat Feb 5 17:57:49 2011 New Revision: 1067472 URL: http://svn.apache.org/viewvc?rev=1067472&view=rev Log: [KARAF-422] features-maven-plugin supports automatic version of plugins now; thanks to Stephane Chomat
Signed-off-by: Andreas Pieber <anpie...@gmail.com> Modified: karaf/branches/karaf-2.1.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddFeaturesToRepoMojo.java Modified: karaf/branches/karaf-2.1.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddFeaturesToRepoMojo.java URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.1.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddFeaturesToRepoMojo.java?rev=1067472&r1=1067471&r2=1067472&view=diff ============================================================================== --- karaf/branches/karaf-2.1.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddFeaturesToRepoMojo.java (original) +++ karaf/branches/karaf-2.1.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddFeaturesToRepoMojo.java Sat Feb 5 17:57:49 2011 @@ -40,6 +40,7 @@ import javax.xml.parsers.ParserConfigura import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.w3c.dom.Document; @@ -61,6 +62,13 @@ import org.xml.sax.SAXException; public class AddFeaturesToRepoMojo extends MojoSupport { /** + * The artifact type of a feature + * + * @parameter default-value="xml" + */ + private String featureArtifactType = "xml"; + + /** * @parameter */ private List<String> descriptors; @@ -100,6 +108,17 @@ public class AddFeaturesToRepoMojo exten */ private boolean addTransitiveFeatures = true; + private Dependency findDependency(List<Dependency> dependencies, String artifactId, String groupId) { + for(Dependency dep : dependencies) { + if (artifactId.equals(dep.getArtifactId()) && groupId.equals(dep.getGroupId()) && + featureArtifactType.equals(dep.getType())) { + if (dep.getVersion() != null) + return dep; + } + } + return null; + } + public void execute() throws MojoExecutionException, MojoFailureException { try { Map<String, Feature> featuresMap = new HashMap<String, Feature>(); @@ -178,6 +197,18 @@ public class AddFeaturesToRepoMojo exten classifier = parts[4]; } } + } else { + Dependency dep = findDependency(project.getDependencies(), artifactId, groupId); + if (dep == null && project.getDependencyManagement() != null) { + dep = findDependency(project.getDependencyManagement().getDependencies(), artifactId, groupId); + } + if (dep != null) { + version = dep.getVersion(); + classifier = dep.getClassifier(); + } + } + if (version == null || version.isEmpty()) { + throw new MojoExecutionException("Cannot found version for: " + bundle); } String dir = groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/"; String name = artifactId + "-" + version + (classifier != null ? "-" + classifier : "") + "." + type;