You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2011/12/09 14:05:27 UTC
svn commit: r1212387 - in
/karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src:
main/java/org/apache/karaf/tooling/features/
test/java/org/apache/karaf/tooling/features/
Author: jbonofre
Date: Fri Dec 9 13:05:27 2011
New Revision: 1212387
URL: http://svn.apache.org/viewvc?rev=1212387&view=rev
Log:
[KARAF-1041] feature:create-kar goal is not able to handle feature <configfile/> and package in the generated KAR
Modified:
karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddFeaturesToRepoMojo.java
karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CreateKarMojo.java
karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MojoSupport.java
karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java
Modified: karaf/branches/karaf-2.2.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.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddFeaturesToRepoMojo.java?rev=1212387&r1=1212386&r2=1212387&view=diff
==============================================================================
--- karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddFeaturesToRepoMojo.java (original)
+++ karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddFeaturesToRepoMojo.java Fri Dec 9 13:05:27 2011
@@ -125,7 +125,7 @@ public class AddFeaturesToRepoMojo exten
karafVersion = p.getImplementationVersion();
}
String karafCoreStandardFeatureUrl = String.format(KARAF_CORE_STANDARD_FEATURE_URL, karafVersion);
- Artifact standardFeatureDescriptor = bundleToArtifact(karafCoreStandardFeatureUrl, true);
+ Artifact standardFeatureDescriptor = resourceToArtifact(karafCoreStandardFeatureUrl, true);
if (standardFeatureDescriptor != null) {
try {
resolveBundle(standardFeatureDescriptor, remoteRepos);
@@ -136,7 +136,7 @@ public class AddFeaturesToRepoMojo exten
}
}
String karafCoreEnterpriseFeatureUrl = String.format(KARAF_CORE_ENTERPRISE_FEATURE_URL, karafVersion);
- Artifact enterpriseFeatureDescriptor = bundleToArtifact(karafCoreEnterpriseFeatureUrl, true);
+ Artifact enterpriseFeatureDescriptor = resourceToArtifact(karafCoreEnterpriseFeatureUrl, true);
if (enterpriseFeatureDescriptor != null) {
try {
resolveBundle(enterpriseFeatureDescriptor, remoteRepos);
@@ -181,7 +181,7 @@ public class AddFeaturesToRepoMojo exten
getLog().info("Base repo: " + localRepo.getUrl());
for (String bundle : bundles) {
- Artifact artifact = bundleToArtifact(bundle, skipNonMavenProtocols);
+ Artifact artifact = resourceToArtifact(bundle, skipNonMavenProtocols);
if (artifact == null) {
continue;
}
@@ -217,7 +217,7 @@ public class AddFeaturesToRepoMojo exten
private void retrieveDescriptorsRecursively(String uri, Set<String> bundles, Map<String, Feature> featuresMap)
throws Exception {
// let's ensure a mvn: based url is sitting in the local repo before we try reading it
- Artifact descriptor = bundleToArtifact(uri, true);
+ Artifact descriptor = resourceToArtifact(uri, true);
if (descriptor != null) {
resolveBundle(descriptor, remoteRepos);
}
Modified: karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CreateKarMojo.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CreateKarMojo.java?rev=1212387&r1=1212386&r2=1212387&view=diff
==============================================================================
--- karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CreateKarMojo.java (original)
+++ karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CreateKarMojo.java Fri Dec 9 13:05:27 2011
@@ -21,6 +21,7 @@ package org.apache.karaf.tooling.feature
import org.apache.karaf.deployer.kar.KarArtifactInstaller;
import org.apache.karaf.features.BundleInfo;
+import org.apache.karaf.features.ConfigFileInfo;
import org.apache.karaf.features.Feature;
import org.apache.karaf.features.internal.RepositoryImpl;
import org.apache.maven.archiver.MavenArchiveConfiguration;
@@ -104,9 +105,9 @@ public class CreateKarMojo extends MojoS
private String repositoryPath = "repository/";
public void execute() throws MojoExecutionException, MojoFailureException {
- List<Artifact> bundles = readBundles();
+ List<Artifact> resources = readResources();
// build the archive
- File archive = createArchive(bundles);
+ File archive = createArchive(resources);
// attach the generated archive to install/deploy
Artifact artifact = factory.createArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), null, "kar");
@@ -115,19 +116,28 @@ public class CreateKarMojo extends MojoS
project.addAttachedArtifact(artifact);
}
- private List<Artifact> readBundles() throws MojoExecutionException {
- List<Artifact> bundles = new ArrayList<Artifact>();
+ /**
+ * Read and load the bundles and configuration files contained in the features file.
+ *
+ * @return a list of resources artifact.
+ * @throws MojoExecutionException
+ */
+ private List<Artifact> readResources() throws MojoExecutionException {
+ List<Artifact> resources = new ArrayList<Artifact>();
try {
RepositoryImpl featuresRepo = new RepositoryImpl(featuresFile.toURI());
Feature[] features = featuresRepo.getFeatures();
for (Feature feature : features) {
for (BundleInfo bundle : feature.getBundles()) {
if (!bundle.isDependency()) {
- bundles.add(bundleToArtifact(bundle.getLocation(), false));
+ resources.add(resourceToArtifact(bundle.getLocation(), false));
}
}
+ for (ConfigFileInfo configFile : feature.getConfigurationFiles()) {
+ resources.add(resourceToArtifact(configFile.getLocation(), false));
+ }
}
- return bundles;
+ return resources;
} catch (MojoExecutionException e) {
throw e;
} catch (Exception e) {
Modified: karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MojoSupport.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MojoSupport.java?rev=1212387&r1=1212386&r2=1212387&view=diff
==============================================================================
--- karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MojoSupport.java (original)
+++ karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MojoSupport.java Fri Dec 9 13:05:27 2011
@@ -371,20 +371,20 @@ public abstract class MojoSupport extend
return null;
}
- protected Artifact bundleToArtifact(String bundle, boolean skipNonMavenProtocols) throws MojoExecutionException {
- bundle = bundle.replace("\r\n", "").replace("\n", "").replace(" ", "").replace("\t", "");
- final int index = bundle.indexOf("mvn:");
+ protected Artifact resourceToArtifact(String resourceLocation, boolean skipNonMavenProtocols) throws MojoExecutionException {
+ resourceLocation = resourceLocation.replace("\r\n", "").replace("\n", "").replace(" ", "").replace("\t", "");
+ final int index = resourceLocation.indexOf("mvn:");
if (index < 0) {
if (skipNonMavenProtocols) {
return null;
}
- throw new MojoExecutionException("Bundle url is not a maven url: " + bundle);
+ throw new MojoExecutionException("Resource URL is not a maven URL: " + resourceLocation);
} else {
- bundle = bundle.substring(index + "mvn:".length());
+ resourceLocation = resourceLocation.substring(index + "mvn:".length());
}
// Truncate the URL when a '#', a '?' or a '$' is encountered
- final int index1 = bundle.indexOf('?');
- final int index2 = bundle.indexOf('#');
+ final int index1 = resourceLocation.indexOf('?');
+ final int index2 = resourceLocation.indexOf('#');
int endIndex = -1;
if (index1 > 0) {
if (index2 > 0) {
@@ -396,27 +396,27 @@ public abstract class MojoSupport extend
endIndex = index2;
}
if (endIndex >= 0) {
- bundle = bundle.substring(0, endIndex);
+ resourceLocation = resourceLocation.substring(0, endIndex);
}
- final int index3 = bundle.indexOf('$');
+ final int index3 = resourceLocation.indexOf('$');
if (index3 > 0) {
- bundle = bundle.substring(0, index3);
+ resourceLocation = resourceLocation.substring(0, index3);
}
- //check if the bundle descriptor contains also remote repository information.
+ //check if the resourceLocation descriptor contains also remote repository information.
ArtifactRepository repo = null;
- if (bundle.startsWith("http://")) {
- final int repoDelimIntex = bundle.indexOf('!');
- String repoUrl = bundle.substring(0, repoDelimIntex);
+ if (resourceLocation.startsWith("http://")) {
+ final int repoDelimIntex = resourceLocation.indexOf('!');
+ String repoUrl = resourceLocation.substring(0, repoDelimIntex);
repo = new DefaultArtifactRepository(
repoUrl,
repoUrl,
new DefaultRepositoryLayout());
- bundle = bundle.substring(repoDelimIntex + 1);
+ resourceLocation = resourceLocation.substring(repoDelimIntex + 1);
}
- String[] parts = bundle.split("/");
+ String[] parts = resourceLocation.split("/");
String groupId = parts[0];
String artifactId = parts[1];
String version = null;
@@ -442,7 +442,7 @@ public abstract class MojoSupport extend
}
}
if (version == null || version.length() == 0) {
- throw new MojoExecutionException("Cannot find version for: " + bundle);
+ throw new MojoExecutionException("Cannot find version for: " + resourceLocation);
}
Artifact artifact = factory.createArtifactWithClassifier(groupId, artifactId, version, type, classifier);
artifact.setRepository(repo);
Modified: karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java?rev=1212387&r1=1212386&r2=1212387&view=diff
==============================================================================
--- karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java (original)
+++ karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java Fri Dec 9 13:05:27 2011
@@ -55,7 +55,7 @@ public class BundleToArtifactTest extend
@Test
public void testSimpleURL() throws Exception {
- Artifact artifact = bundleToArtifact("mvn:org.foo/bar/1.0/kar", false);
+ Artifact artifact = resourceToArtifact("mvn:org.foo/bar/1.0/kar", false);
assert artifact.getGroupId().equals("org.foo");
assert artifact.getArtifactId().equals("bar");
assert artifact.getBaseVersion().equals("1.0");
@@ -66,7 +66,7 @@ public class BundleToArtifactTest extend
@Test
public void testURLWithClassifier() throws Exception {
- Artifact artifact = bundleToArtifact("mvn:org.foo/bar/1.0/kar/type", false);
+ Artifact artifact = resourceToArtifact("mvn:org.foo/bar/1.0/kar/type", false);
assert artifact.getGroupId().equals("org.foo");
assert artifact.getArtifactId().equals("bar");
assert artifact.getBaseVersion().equals("1.0");
@@ -77,7 +77,7 @@ public class BundleToArtifactTest extend
@Test
public void testRemoteRepoURL() throws Exception {
- Artifact artifact = bundleToArtifact("mvn:http://baz.com!org.foo/bar/1.0/kar", false);
+ Artifact artifact = resourceToArtifact("mvn:http://baz.com!org.foo/bar/1.0/kar", false);
assert artifact.getGroupId().equals("org.foo");
assert artifact.getArtifactId().equals("bar");
assert artifact.getBaseVersion().equals("1.0");