Index: tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CreateKarMojo.java =================================================================== --- tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CreateKarMojo.java (revision 1294725) +++ tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CreateKarMojo.java (working copy) @@ -40,6 +40,8 @@ import org.apache.maven.artifact.repository.metadata.SnapshotVersion; import org.apache.maven.artifact.repository.metadata.Versioning; import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.codehaus.plexus.archiver.jar.JarArchiver; @@ -47,7 +49,7 @@ /** * assembles a kar archive * - * @version $Revision: 1.1 $ + * @version $Revision$ * @goal features-create-kar * @phase package * @requiresDependencyResolution runtime @@ -104,7 +106,7 @@ * * @parameter default-value="${project.build.directory}/feature/feature.xml" */ - private File featuresFile; + private String featuresFile; /** @@ -113,16 +115,44 @@ * @parameter default-value="${repositoryPath}" */ private String repositoryPath = "repository/"; - - + // // Mojo // public void execute() throws MojoExecutionException, MojoFailureException { - List resources = readResources(); + File featuresFileResolved = new File(featuresFile); + String groupId = project.getGroupId(); + String artifactId = project.getArtifactId(); + String version = project.getVersion(); + + if (isMavenUrl(featuresFile)) { + featuresFileResolved = new File(translateFromMaven(featuresFile).replace("file:///", "")); + + Artifact artifactTemp = resourceToArtifact(featuresFile, false); + + if (!featuresFileResolved.exists()) { + try { + resolver.resolve(artifactTemp, remoteRepos, localRepo); + featuresFileResolved = artifactTemp.getFile(); + } catch (ArtifactResolutionException e) { + getLog().error("Artifact was not resolved", e); + } catch (ArtifactNotFoundException e) { + getLog().error("Artifact was not found", e); + } + } + + if (artifactTemp.getGroupId() != null) + groupId = artifactTemp.getGroupId(); + if (artifactTemp.getArtifactId() != null) + artifactId = artifactTemp.getArtifactId(); + if (artifactTemp.getVersion() != null) + version = artifactTemp.getVersion(); + } + + List resources = readResources(featuresFileResolved); // Build the archive - File archive = createArchive(resources); + File archive = createArchive(resources, featuresFileResolved, groupId, artifactId, version); // Attach the generated archive for install/deploy Artifact artifact = factory.createArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), null, "kar"); @@ -137,14 +167,14 @@ * @return * @throws MojoExecutionException */ - private List readResources() throws MojoExecutionException { + private List readResources(File featuresFile) throws MojoExecutionException { List resources = new ArrayList(); try { InputStream in = new FileInputStream(featuresFile); try { Features features = JaxbUtil.unmarshal(in, false); for (Feature feature : features.getFeature()) { - for (BundleInfo bundle : feature.getBundles()) { + for (BundleInfo bundle : feature.getBundles()) { if (!bundle.isDependency()) { resources.add(resourceToArtifact(bundle.getLocation(), false)); } @@ -169,7 +199,7 @@ * * @param bundles */ - private File createArchive(List bundles) throws MojoExecutionException { + private File createArchive(List bundles, File featuresFile, String groupId, String artifactId, String version) throws MojoExecutionException { ArtifactRepositoryLayout layout = new DefaultRepositoryLayout(); File archiveFile = getArchiveFile(outputDirectory, finalName, null); @@ -196,7 +226,7 @@ // archive.addManifestEntry(Constants.BUNDLE_SYMBOLICNAME, project.getArtifactId()); //include the feature.xml - Artifact featureArtifact = factory.createArtifactWithClassifier(project.getGroupId(), project.getArtifactId(), project.getVersion(), "xml", KarArtifactInstaller.FEATURE_CLASSIFIER); + Artifact featureArtifact = factory.createArtifactWithClassifier(groupId, artifactId, version, "xml", KarArtifactInstaller.FEATURE_CLASSIFIER); jarArchiver.addFile(featuresFile, repositoryPath + layout.pathOf(featureArtifact)); if (featureArtifact.isSnapshot()) { @@ -276,6 +306,16 @@ throw new MojoExecutionException("Failed to create archive", e); } } + + protected static Boolean isMavenUrl(String uri) { + Boolean result = false; + + if (uri.startsWith("mvn:")) { + result = true; + } + + return result; + } protected static File getArchiveFile(final File basedir, final String finalName, String classifier) { if (classifier == null) {