Repository: karaf Updated Branches: refs/heads/karaf-3.0.x ee4a6b4e1 -> 52fe48b25
[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/52fe48b2 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/52fe48b2 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/52fe48b2 Branch: refs/heads/karaf-3.0.x Commit: 52fe48b25f1b7f9e3a443edec9feb1793e172f7e Parents: ee4a6b4 Author: Jean-Baptiste Onofré <[email protected]> Authored: Tue Jul 22 10:49:08 2014 +0200 Committer: Jean-Baptiste Onofré <[email protected]> Committed: Tue Jul 22 10:49:08 2014 +0200 ---------------------------------------------------------------------- .../etc/org.apache.karaf.features.repos.cfg | 22 ++++---- .../apache/karaf/features/command/Artifact.java | 56 -------------------- .../karaf/features/command/FeatureFinder.java | 33 ++++++++---- .../karaf/features/command/RepoAddCommand.java | 3 +- 4 files changed, 36 insertions(+), 78 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/52fe48b2/assemblies/features/framework/src/main/resources/resources/etc/org.apache.karaf.features.repos.cfg ---------------------------------------------------------------------- diff --git a/assemblies/features/framework/src/main/resources/resources/etc/org.apache.karaf.features.repos.cfg b/assemblies/features/framework/src/main/resources/resources/etc/org.apache.karaf.features.repos.cfg index 00844e9..ea7e3d8 100644 --- a/assemblies/features/framework/src/main/resources/resources/etc/org.apache.karaf.features.repos.cfg +++ b/assemblies/features/framework/src/main/resources/resources/etc/org.apache.karaf.features.repos.cfg @@ -21,14 +21,14 @@ # This file describes the features repository URL # It could be directly installed using feature:repo-add command # - -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/LATEST/xml/features +cave=mvn:org.apache.karaf.cave/apache-karaf-cave/LATEST/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-features/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/52fe48b2/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 6d549f8..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 not complete"); - } - 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/52fe48b2/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 c9f042f..aa2aef9 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 @@ -30,16 +30,16 @@ public class FeatureFinder implements ManagedService { Map<String, String> nameToArtifactMap = new HashMap<String, String>(); public String[] getNames() { - return nameToArtifactMap.keySet().toArray(new String[] {}); + 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 = FeatureFinder.replaceVersion(uri, version); } - Artifact artifact = new Artifact(coords); - return artifact.getPaxUrlForArtifact(version); + return new URI(uri); } @SuppressWarnings("rawtypes") @@ -48,12 +48,27 @@ public class FeatureFinder implements ManagedService { nameToArtifactMap.clear(); Enumeration keys = properties.keys(); while (keys.hasMoreElements()) { - String key = (String)keys.nextElement(); + String key = (String) keys.nextElement(); if (!"felix.fileinstall.filename".equals(key) && !"service.pid".equals(key)) { - nameToArtifactMap.put(key, (String)properties.get(key)); + nameToArtifactMap.put(key, (String) properties.get(key)); } } } } + private 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/52fe48b2/features/command/src/main/java/org/apache/karaf/features/command/RepoAddCommand.java ---------------------------------------------------------------------- diff --git a/features/command/src/main/java/org/apache/karaf/features/command/RepoAddCommand.java b/features/command/src/main/java/org/apache/karaf/features/command/RepoAddCommand.java index ede1376..c6c1a1d 100644 --- a/features/command/src/main/java/org/apache/karaf/features/command/RepoAddCommand.java +++ b/features/command/src/main/java/org/apache/karaf/features/command/RepoAddCommand.java @@ -48,8 +48,7 @@ public class RepoAddCommand extends AbstractAction { } protected Object doExecute() throws Exception { - String effectiveVersion = (version == null) ? "LATEST" : version; - URI uri = featureFinder.getUriFor(nameOrUrl, effectiveVersion); + URI uri = featureFinder.getUriFor(nameOrUrl, version); if (uri == null) { uri = new URI(nameOrUrl); }
