Repository: karaf
Updated Branches:
refs/heads/karaf-2.x d380c4d0c -> 0d39cad8a
[KARAF-3085] Refactoring of the FeatureFinder to leverage Pax URL and use
regular mvn URLs
Conflicts:
assemblies/apache-karaf/src/main/filtered-resources/etc/org.apache.karaf.features.repos.cfg
features/command/src/main/java/org/apache/karaf/features/command/Artifact.java
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/0d39cad8
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/0d39cad8
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/0d39cad8
Branch: refs/heads/karaf-2.x
Commit: 0d39cad8aa55be50c07feec12f3d7e67ef181527
Parents: d380c4d
Author: Jean-Baptiste Onofré <[email protected]>
Authored: Tue Jul 22 10:02:45 2014 +0200
Committer: Jean-Baptiste Onofré <[email protected]>
Committed: Tue Jul 22 10:18:29 2014 +0200
----------------------------------------------------------------------
.../etc/org.apache.karaf.features.repos.cfg | 21 ++++++-------
features/command/pom.xml | 3 ++
.../features/command/ChooseUrlCommand.java | 11 ++++---
.../karaf/features/command/FeatureFinder.java | 13 ++++----
.../java/org/apache/karaf/util/MvnUtils.java | 17 ++++++++++-
.../org/apache/karaf/util/MvnUtilsTest.java | 31 ++++++++++++++++++++
6 files changed, 75 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/0d39cad8/assemblies/apache-karaf/src/main/filtered-resources/etc/org.apache.karaf.features.repos.cfg
----------------------------------------------------------------------
diff --git
a/assemblies/apache-karaf/src/main/filtered-resources/etc/org.apache.karaf.features.repos.cfg
b/assemblies/apache-karaf/src/main/filtered-resources/etc/org.apache.karaf.features.repos.cfg
index 424b125..b92cfa2 100644
---
a/assemblies/apache-karaf/src/main/filtered-resources/etc/org.apache.karaf.features.repos.cfg
+++
b/assemblies/apache-karaf/src/main/filtered-resources/etc/org.apache.karaf.features.repos.cfg
@@ -20,13 +20,14 @@
#
# This file describes the features repository URL for some projects
#
-cellar = org.apache.karaf.cellar:apache-karaf-cellar:xml:features:(0,]
-camel = org.apache.camel.karaf:apache-camel:xml:features:(0,]
-camel-extras =
org.apache-extras.camel-extra.karaf:camel-extra:xml:features:(0,]
-cxf = org.apache.cxf.karaf:apache-cxf:xml:features:(0,]
-cxf-dosgi = org.apache.cxf.dosgi:cxf-dosgi:xml:features:(0,]
-activemq = org.apache.activemq:activemq-karaf:xml:features:(0,]
-jclouds = org.jclouds.karaf:jclouds-karaf:xml:features:(0,]
-openejb = org.apache.openejb:openejb-feature:xml:features:(0,]
-wicket = org.ops4j.pax.wicket:features:xml:features:(0,]
-hawtio = io.hawt:hawtio-karaf:xml:features:(0,]
+cellar=mvn:org.apache.karaf.cellar/apache-karaf-cellar/[2,3)/xml/features
+cave=mvn:org.apache.karaf.cave/apache-karaf-cave/[2,3)/xml/features
+camel=mvn:org.apache.camel.karaf/apache-camel/LATEST/xml/features
+camel-extras=mvn:org.apache-extras.camel-extra.karaf/camel-extra/LATEST/xml/features
+cxf=mvn:org.apache.cxf.karaf/apache-cxf/LATEST/xml/features
+cxf-dosgi=mvn:org.apache.cxf.dosgi/cxf-dosgi/LATEST/xml/features
+activemq=mvn:org.apache.activemq/activemq-karaf/LATEST/xml/features
+jclouds=mvn:org.jclouds.karaf/jclouds-karaf/LATEST/xml/features
+openejb=mvn:org.apache.openejb/openejb-feature/LATEST/xml/features
+wicket=mvn:org.ops4j.pax.wicket/features/LATEST/xml/features
+hawtio=mvn:io.hawt/hawtio-karaf/LATEST/xml/features
http://git-wip-us.apache.org/repos/asf/karaf/blob/0d39cad8/features/command/pom.xml
----------------------------------------------------------------------
diff --git a/features/command/pom.xml b/features/command/pom.xml
index e2ebff7..fedb6aa 100644
--- a/features/command/pom.xml
+++ b/features/command/pom.xml
@@ -118,6 +118,9 @@
org.apache.karaf.shell.console,
*
</Import-Package>
+ <Private-Package>
+ org.apache.karaf.util
+ </Private-Package>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/0d39cad8/features/command/src/main/java/org/apache/karaf/features/command/ChooseUrlCommand.java
----------------------------------------------------------------------
diff --git
a/features/command/src/main/java/org/apache/karaf/features/command/ChooseUrlCommand.java
b/features/command/src/main/java/org/apache/karaf/features/command/ChooseUrlCommand.java
index 43de93d..56cf648 100644
---
a/features/command/src/main/java/org/apache/karaf/features/command/ChooseUrlCommand.java
+++
b/features/command/src/main/java/org/apache/karaf/features/command/ChooseUrlCommand.java
@@ -47,12 +47,15 @@ public class ChooseUrlCommand extends AbstractAction {
}
protected Object doExecute() throws Exception {
- String effectiveVersion = (version == null) ? "LATEST" : version;
- URI uri = featureFinder.getUriFor(name, effectiveVersion);
+ URI uri = featureFinder.getUriFor(name, version);
if (uri == null) {
- throw new RuntimeException("No feature found for name " + name + "
and version " + version);
+ if (version != null) {
+ throw new RuntimeException("No feature found for name " + name
+ " and version " + version);
+ } else {
+ throw new RuntimeException("No feature found for name " +
name);
+ }
}
- System.out.println("adding feature url " + uri);
+ System.out.println("Adding feature url " + uri);
featuresService.addRepository(uri);
return null;
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/0d39cad8/features/command/src/main/java/org/apache/karaf/features/command/FeatureFinder.java
----------------------------------------------------------------------
diff --git
a/features/command/src/main/java/org/apache/karaf/features/command/FeatureFinder.java
b/features/command/src/main/java/org/apache/karaf/features/command/FeatureFinder.java
index 9cd3647..247cbcd 100644
---
a/features/command/src/main/java/org/apache/karaf/features/command/FeatureFinder.java
+++
b/features/command/src/main/java/org/apache/karaf/features/command/FeatureFinder.java
@@ -22,6 +22,7 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
+import org.apache.karaf.util.MvnUtils;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;
@@ -31,13 +32,13 @@ public class FeatureFinder implements ManagedService {
return nameToArtifactMap.keySet().toArray(new String[] {});
}
- public URI getUriFor(String name, String version) {
- String coords = nameToArtifactMap.get(name);
- if (coords == null) {
- return null;
+ public URI getUriFor(String name, String version) throws Exception {
+ String uri = nameToArtifactMap.get(name);
+ if (version != null) {
+ // replace the version in the URL with the provided one
+ uri = MvnUtils.replaceVersion(uri, version);
}
- Artifact artifact = new Artifact(coords);
- return artifact.getPaxUrlForArtifact(version);
+ return new URI(uri);
}
@SuppressWarnings("rawtypes")
http://git-wip-us.apache.org/repos/asf/karaf/blob/0d39cad8/util/src/main/java/org/apache/karaf/util/MvnUtils.java
----------------------------------------------------------------------
diff --git a/util/src/main/java/org/apache/karaf/util/MvnUtils.java
b/util/src/main/java/org/apache/karaf/util/MvnUtils.java
index 85610dd..e110faf 100644
--- a/util/src/main/java/org/apache/karaf/util/MvnUtils.java
+++ b/util/src/main/java/org/apache/karaf/util/MvnUtils.java
@@ -22,7 +22,6 @@ public class MvnUtils {
private MvnUtils() { }
-
/**
* Compute the path of url, expanding it if the url uses the mvn protocol.
*
@@ -50,4 +49,20 @@ public class MvnUtils {
}
return url.getPath();
}
+
+ public static String replaceVersion(String url, String version) {
+ if (url.startsWith("mvn:")) {
+ // mvn:groupId/artifactId/version...
+ int index = url.indexOf('/');
+ index = url.indexOf('/', index + 1);
+
+ String first = url.substring(0, index);
+ index = url.indexOf('/', index + 1);
+ String second = url.substring(index + 1);
+
+ return first + "/" + version + "/" + second;
+ }
+ return url;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/0d39cad8/util/src/test/java/org/apache/karaf/util/MvnUtilsTest.java
----------------------------------------------------------------------
diff --git a/util/src/test/java/org/apache/karaf/util/MvnUtilsTest.java
b/util/src/test/java/org/apache/karaf/util/MvnUtilsTest.java
new file mode 100644
index 0000000..c8545d8
--- /dev/null
+++ b/util/src/test/java/org/apache/karaf/util/MvnUtilsTest.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.util;
+
+import junit.framework.TestCase;
+
+public class MvnUtilsTest extends TestCase {
+
+ public void testVersionReplacement() {
+ String url =
"mvn:org.apache.karaf.cellar/apache-karaf-cellar/[2.3,3)/xml/features";
+
+ String result = MvnUtils.replaceVersion(url, "2.3.2");
+
+
assertEquals("mvn:org.apache.karaf.cellar/apache-karaf-cellar/2.3.2/xml/features",
result);
+ }
+
+}