Repository: karaf Updated Branches: refs/heads/karaf-2.3.x 0a788d02d -> 0eb3f9929
[KARAF-3085] Refactoring of the FeatureFinder to leverage Pax URL and use regular mvn URLs Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/0eb3f992 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/0eb3f992 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/0eb3f992 Branch: refs/heads/karaf-2.3.x Commit: 0eb3f99291c6df094177580abbdfbe3f43116bfa Parents: 0a788d0 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:02:45 2014 +0200 ---------------------------------------------------------------------- .../etc/org.apache.karaf.features.repos.cfg | 21 ++++---- features/command/pom.xml | 3 ++ .../apache/karaf/features/command/Artifact.java | 56 -------------------- .../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 +++++++++++ 7 files changed, 75 insertions(+), 77 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/0eb3f992/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 5c9e4e0..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/0eb3f992/features/command/pom.xml ---------------------------------------------------------------------- diff --git a/features/command/pom.xml b/features/command/pom.xml index c8c61f9..8d08651 100644 --- a/features/command/pom.xml +++ b/features/command/pom.xml @@ -128,6 +128,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/0eb3f992/features/command/src/main/java/org/apache/karaf/features/command/Artifact.java ---------------------------------------------------------------------- diff --git a/features/command/src/main/java/org/apache/karaf/features/command/Artifact.java b/features/command/src/main/java/org/apache/karaf/features/command/Artifact.java deleted file mode 100644 index a718635..0000000 --- a/features/command/src/main/java/org/apache/karaf/features/command/Artifact.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.features.command; - -import java.net.URI; - -/** - * Simple abstraction of a maven artifact to avoid external deps - */ -public class Artifact { - String groupId; - String artifactId; - String version; - String extension; - String classifier; - - public Artifact(String coords) { - String[] coordsAr = coords.split(":"); - if (coordsAr.length != 5) { - throw new IllegalArgumentException("Maven URL " + coords + " is malformed or incomplete"); - } - this.groupId = coordsAr[0]; - this.artifactId = coordsAr[1]; - this.version = coordsAr[4]; - this.extension = coordsAr[2]; - this.classifier = coordsAr[3]; - } - - public Artifact(String coords, String version) { - this(coords); - this.version = version; - } - - public URI getPaxUrlForArtifact(String version) { - String uriSt = "mvn:" + this.groupId + "/" + this.artifactId + "/" + version + "/" + this.extension + "/" + this.classifier; - try { - return new URI(uriSt); - } catch (Exception e) { - return null; - } - } -} http://git-wip-us.apache.org/repos/asf/karaf/blob/0eb3f992/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/0eb3f992/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/0eb3f992/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/0eb3f992/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); + } + +}
