[KARAF-3988] Add features repo name management
Project: http://git-wip-us.apache.org/repos/asf/karaf-cellar/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf-cellar/commit/6984f7d4 Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/6984f7d4 Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/6984f7d4 Branch: refs/heads/cellar-3.0.x Commit: 6984f7d4e7d0b8aade428f75ec70786dc211c81b Parents: 855f7d9 Author: Jean-Baptiste Onofré <[email protected]> Authored: Tue Sep 15 07:56:59 2015 +0200 Committer: Jean-Baptiste Onofré <[email protected]> Committed: Tue Sep 15 07:56:59 2015 +0200 ---------------------------------------------------------------------- .../karaf/cellar/features/FeatureFinder.java | 67 ++++++++++++++++++++ .../internal/CellarFeaturesMBeanImpl.java | 19 +++--- .../cellar/features/shell/RepoAddCommand.java | 20 ++++-- .../resources/OSGI-INF/blueprint/blueprint.xml | 5 ++ .../resources/OSGI-INF/blueprint/management.xml | 1 + .../OSGI-INF/blueprint/shell-features.xml | 1 + 6 files changed, 100 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/6984f7d4/features/src/main/java/org/apache/karaf/cellar/features/FeatureFinder.java ---------------------------------------------------------------------- diff --git a/features/src/main/java/org/apache/karaf/cellar/features/FeatureFinder.java b/features/src/main/java/org/apache/karaf/cellar/features/FeatureFinder.java new file mode 100644 index 0000000..a6117da --- /dev/null +++ b/features/src/main/java/org/apache/karaf/cellar/features/FeatureFinder.java @@ -0,0 +1,67 @@ +/* + * 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.cellar.features; + +import java.net.URI; +import java.util.Dictionary; + +import org.osgi.service.cm.Configuration; +import org.osgi.service.cm.ConfigurationAdmin; + +public class FeatureFinder { + + private ConfigurationAdmin configurationAdmin; + + public void setConfigurationAdmin(ConfigurationAdmin configurationAdmin) { + this.configurationAdmin = configurationAdmin; + } + + public URI getUriFor(String name, String version) throws Exception { + Configuration configuration = configurationAdmin.getConfiguration("org.apache.karaf.features.repos", null); + if (configuration == null) { + return null; + } + Dictionary properties = configuration.getProperties(); + if (properties == null) { + return null; + } + String url = (String) properties.get(name); + if (url == null) { + return null; + } + if (version != null) { + url = replaceVersion(url, version); + } + return URI.create(url); + } + + 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-cellar/blob/6984f7d4/features/src/main/java/org/apache/karaf/cellar/features/management/internal/CellarFeaturesMBeanImpl.java ---------------------------------------------------------------------- diff --git a/features/src/main/java/org/apache/karaf/cellar/features/management/internal/CellarFeaturesMBeanImpl.java b/features/src/main/java/org/apache/karaf/cellar/features/management/internal/CellarFeaturesMBeanImpl.java index 7af4e04..2bf77fe 100644 --- a/features/src/main/java/org/apache/karaf/cellar/features/management/internal/CellarFeaturesMBeanImpl.java +++ b/features/src/main/java/org/apache/karaf/cellar/features/management/internal/CellarFeaturesMBeanImpl.java @@ -13,19 +13,13 @@ */ package org.apache.karaf.cellar.features.management.internal; -// import org.apache.karaf.cellar.bundle.BundleState; - import org.apache.karaf.cellar.core.*; import org.apache.karaf.cellar.core.control.SwitchStatus; import org.apache.karaf.cellar.core.event.EventProducer; import org.apache.karaf.cellar.core.event.EventType; -import org.apache.karaf.cellar.features.ClusterFeaturesEvent; -import org.apache.karaf.cellar.features.Constants; -import org.apache.karaf.cellar.features.FeatureState; -import org.apache.karaf.cellar.features.ClusterRepositoryEvent; +import org.apache.karaf.cellar.features.*; import org.apache.karaf.cellar.features.management.CellarFeaturesMBean; import org.apache.karaf.features.*; -// import org.osgi.framework.BundleEvent; import org.osgi.service.cm.ConfigurationAdmin; import javax.management.NotCompliantMBeanException; @@ -48,6 +42,7 @@ public class CellarFeaturesMBeanImpl extends StandardMBean implements CellarFeat private GroupManager groupManager; private EventProducer eventProducer; private FeaturesService featuresService; + private FeatureFinder featureFinder; private ConfigurationAdmin configurationAdmin; public CellarFeaturesMBeanImpl() throws NotCompliantMBeanException { @@ -86,6 +81,14 @@ public class CellarFeaturesMBeanImpl extends StandardMBean implements CellarFeat this.featuresService = featuresService; } + public FeatureFinder getFeatureFinder() { + return featureFinder; + } + + public void setFeatureFinder(FeatureFinder featureFinder) { + this.featureFinder = featureFinder; + } + public ConfigurationAdmin getConfigurationAdmin() { return configurationAdmin; } @@ -424,7 +427,7 @@ public class CellarFeaturesMBeanImpl extends StandardMBean implements CellarFeat // get the features in the cluster group Map<String, FeatureState> clusterFeatures = clusterManager.getMap(Constants.FEATURES_MAP + Configurations.SEPARATOR + groupName); - URI uri = featuresService.getRepositoryUriFor(nameOrUrl, version); + URI uri = featureFinder.getUriFor(nameOrUrl, version); if (uri == null) { uri = new URI(nameOrUrl); } http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/6984f7d4/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoAddCommand.java ---------------------------------------------------------------------- diff --git a/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoAddCommand.java b/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoAddCommand.java index d705e86..e2cabea 100644 --- a/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoAddCommand.java +++ b/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoAddCommand.java @@ -19,6 +19,7 @@ import org.apache.karaf.cellar.core.control.SwitchStatus; import org.apache.karaf.cellar.core.event.EventProducer; import org.apache.karaf.cellar.core.shell.CellarCommandSupport; import org.apache.karaf.cellar.features.Constants; +import org.apache.karaf.cellar.features.FeatureFinder; import org.apache.karaf.cellar.features.FeatureState; import org.apache.karaf.cellar.features.ClusterRepositoryEvent; import org.apache.karaf.features.Feature; @@ -30,7 +31,6 @@ import org.apache.karaf.shell.commands.Command; import org.apache.karaf.shell.commands.Option; import java.net.URI; -import java.util.List; import java.util.Map; @Command(scope = "cluster", name = "feature-repo-add", description = "Add a features repository to a cluster group") @@ -50,6 +50,7 @@ public class RepoAddCommand extends CellarCommandSupport { private EventProducer eventProducer; private FeaturesService featuresService; + private FeatureFinder featureFinder; @Override protected Object doExecute() throws Exception { @@ -74,15 +75,15 @@ public class RepoAddCommand extends CellarCommandSupport { // get the features in the cluster group Map<String, FeatureState> clusterFeatures = clusterManager.getMap(Constants.FEATURES_MAP + Configurations.SEPARATOR + groupName); - URI uri = featuresService.getRepositoryUriFor(nameOrUrl, version); + URI uri = featureFinder.getUriFor(nameOrUrl, version); if (uri == null) { uri = new URI(nameOrUrl); } // check if the URL is already registered String name = null; - for (String repository : clusterRepositories.keySet()) { - if (repository.equals(uri)) { - name = clusterRepositories.get(uri); + for (String repositoryUri : clusterRepositories.keySet()) { + if (repositoryUri.equals(uri)) { + name = clusterRepositories.get(repositoryUri); break; } } @@ -162,4 +163,13 @@ public class RepoAddCommand extends CellarCommandSupport { public void setFeaturesService(FeaturesService featuresService) { this.featuresService = featuresService; } + + public FeatureFinder getFeatureFinder() { + return featureFinder; + } + + public void setFeatureFinder(FeatureFinder featureFinder) { + this.featureFinder = featureFinder; + } + } http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/6984f7d4/features/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/features/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/features/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 7e319ea..457b6fb 100644 --- a/features/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/features/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -67,6 +67,11 @@ </bean> <service ref="repositoryEventHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/> + <!-- Feature Finder --> + <bean id="featureFinder" class="org.apache.karaf.cellar.features.FeatureFinder"> + <property name="configurationAdmin" ref="configurationAdmin"/> + </bean> + <reference id="clusterManager" interface="org.apache.karaf.cellar.core.ClusterManager"/> <reference id="groupManager" interface="org.apache.karaf.cellar.core.GroupManager"/> <reference id="eventProducer" interface="org.apache.karaf.cellar.core.event.EventProducer"/> http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/6984f7d4/features/src/main/resources/OSGI-INF/blueprint/management.xml ---------------------------------------------------------------------- diff --git a/features/src/main/resources/OSGI-INF/blueprint/management.xml b/features/src/main/resources/OSGI-INF/blueprint/management.xml index 2795c9a..ef2569a 100644 --- a/features/src/main/resources/OSGI-INF/blueprint/management.xml +++ b/features/src/main/resources/OSGI-INF/blueprint/management.xml @@ -26,6 +26,7 @@ <property name="groupManager" ref="groupManager"/> <property name="configurationAdmin" ref="configurationAdmin"/> <property name="featuresService" ref="featuresService"/> + <property name="featureFinder" ref="featureFinder"/> </bean> <service ref="cellarFeaturesMBean" auto-export="interfaces"> <service-properties> http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/6984f7d4/features/src/main/resources/OSGI-INF/blueprint/shell-features.xml ---------------------------------------------------------------------- diff --git a/features/src/main/resources/OSGI-INF/blueprint/shell-features.xml b/features/src/main/resources/OSGI-INF/blueprint/shell-features.xml index dac31cf..f7e0a7c 100644 --- a/features/src/main/resources/OSGI-INF/blueprint/shell-features.xml +++ b/features/src/main/resources/OSGI-INF/blueprint/shell-features.xml @@ -68,6 +68,7 @@ <property name="groupManager" ref="groupManager"/> <property name="eventProducer" ref="eventProducer"/> <property name="featuresService" ref="featuresService"/> + <property name="featureFinder" ref="featureFinder"/> </action> <completers> <ref component-id="allGroupsCompleter"/>
