Author: cschneider Date: Wed Jan 4 12:22:38 2012 New Revision: 1227132 URL: http://svn.apache.org/viewvc?rev=1227132&view=rev Log: KARAF-1132 Adding feature:chooseurl command for karaf 3
Added: karaf/trunk/assemblies/apache-karaf/src/main/filtered-resources/etc/org.apache.karaf.features.repos.cfg karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/Artifact.java karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ChooseUrlCommand.java karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/FeatureFinder.java karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/completers/FeatureRepoNameCompleter.java Modified: karaf/trunk/features/command/pom.xml karaf/trunk/features/command/src/main/resources/OSGI-INF/blueprint/features-command.xml Added: karaf/trunk/assemblies/apache-karaf/src/main/filtered-resources/etc/org.apache.karaf.features.repos.cfg URL: http://svn.apache.org/viewvc/karaf/trunk/assemblies/apache-karaf/src/main/filtered-resources/etc/org.apache.karaf.features.repos.cfg?rev=1227132&view=auto ============================================================================== --- karaf/trunk/assemblies/apache-karaf/src/main/filtered-resources/etc/org.apache.karaf.features.repos.cfg (added) +++ karaf/trunk/assemblies/apache-karaf/src/main/filtered-resources/etc/org.apache.karaf.features.repos.cfg Wed Jan 4 12:22:38 2012 @@ -0,0 +1,5 @@ +camel=org.apache.camel.karaf:apache-camel:xml:features:(0,] +cxf=org.apache.cxf.karaf:apache-cxf:xml:features:(0,] +activemq=org.apache.activemq:activemq-karaf:xml:features:(0,] +jclouds=org.jclouds.karaf:feature:xml:features:(0,] +openejb=org.apache.openejb:openejb-feature:xml:features:(0,] Modified: karaf/trunk/features/command/pom.xml URL: http://svn.apache.org/viewvc/karaf/trunk/features/command/pom.xml?rev=1227132&r1=1227131&r2=1227132&view=diff ============================================================================== --- karaf/trunk/features/command/pom.xml (original) +++ karaf/trunk/features/command/pom.xml Wed Jan 4 12:22:38 2012 @@ -44,6 +44,11 @@ <scope>provided</scope> </dependency> <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + <scope>provided</scope> + </dependency> + <dependency> <groupId>org.apache.karaf.features</groupId> <artifactId>org.apache.karaf.features.core</artifactId> </dependency> Added: karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/Artifact.java URL: http://svn.apache.org/viewvc/karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/Artifact.java?rev=1227132&view=auto ============================================================================== --- karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/Artifact.java (added) +++ karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/Artifact.java Wed Jan 4 12:22:38 2012 @@ -0,0 +1,53 @@ +/* + * 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(":"); + 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; + } + } +} Added: karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ChooseUrlCommand.java URL: http://svn.apache.org/viewvc/karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ChooseUrlCommand.java?rev=1227132&view=auto ============================================================================== --- karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ChooseUrlCommand.java (added) +++ karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ChooseUrlCommand.java Wed Jan 4 12:22:38 2012 @@ -0,0 +1,63 @@ +package org.apache.karaf.features.command; +/* + * 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. + */ + + +import java.net.URI; + +import org.apache.karaf.features.FeaturesService; +import org.apache.karaf.shell.commands.Argument; +import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.console.AbstractAction; + +/** + * Concatenate and print files and/or URLs. + * + * @version $Rev: 593392 $ $Date: 2007-11-09 03:14:15 +0100 (Fri, 09 Nov 2007) $ + */ +@Command(scope = "feature", name = "chooseurl", description = "Add a repository url for well known features") +public class ChooseUrlCommand extends AbstractAction { + + @Argument(index = 0, name = "", description = "", required = true, multiValued = false) + private String name; + + @Argument(index = 1, name = "", description = "", required = false, multiValued = false) + private String version; + + private FeatureFinder featureFinder; + private FeaturesService featuresService; + + public void setFeatureFinder(FeatureFinder featureFinder) { + this.featureFinder = featureFinder; + } + + public void setFeaturesService(FeaturesService featuresService) { + this.featuresService = featuresService; + } + + protected Object doExecute() throws Exception { + String effectiveVersion = (version == null) ? "LATEST" : version; + URI uri = featureFinder.getUriFor(name, effectiveVersion); + if (uri == null) { + throw new RuntimeException("No feature found for name " + name + " and version " + version); + } + System.out.println("adding feature url " + uri); + featuresService.addRepository(uri); + return null; + } + +} Added: karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/FeatureFinder.java URL: http://svn.apache.org/viewvc/karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/FeatureFinder.java?rev=1227132&view=auto ============================================================================== --- karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/FeatureFinder.java (added) +++ karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/FeatureFinder.java Wed Jan 4 12:22:38 2012 @@ -0,0 +1,55 @@ +/* + * 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; +import java.util.Dictionary; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; + +import org.osgi.service.cm.ConfigurationException; +import org.osgi.service.cm.ManagedService; + +public class FeatureFinder implements ManagedService { + Map<String, String> nameToArtifactMap = new HashMap<String, String>(); + public String[] getNames() { + return nameToArtifactMap.keySet().toArray(new String[] {}); + } + + public URI getUriFor(String name, String version) { + String coords = nameToArtifactMap.get(name); + if (coords == null) { + return null; + } + Artifact artifact = new Artifact(coords); + return artifact.getPaxUrlForArtifact(version); + } + + @SuppressWarnings("rawtypes") + public void updated(Dictionary properties) throws ConfigurationException { + nameToArtifactMap.clear(); + Enumeration keys = properties.keys(); + while (keys.hasMoreElements()) { + String key = (String)keys.nextElement(); + if (!"felix.fileinstall.filename".equals(key) && !"service.pid".equals(key)) { + nameToArtifactMap.put(key, (String)properties.get(key)); + } + } + } + +} Added: karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/completers/FeatureRepoNameCompleter.java URL: http://svn.apache.org/viewvc/karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/completers/FeatureRepoNameCompleter.java?rev=1227132&view=auto ============================================================================== --- karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/completers/FeatureRepoNameCompleter.java (added) +++ karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/completers/FeatureRepoNameCompleter.java Wed Jan 4 12:22:38 2012 @@ -0,0 +1,23 @@ +package org.apache.karaf.features.command.completers; + +import java.util.Arrays; +import java.util.List; + +import org.apache.karaf.features.command.FeatureFinder; +import org.apache.karaf.shell.console.Completer; +import org.apache.karaf.shell.console.completer.StringsCompleter; + +public class FeatureRepoNameCompleter implements Completer { + + FeatureFinder featureFinder; + + public void setFeatureFinder(FeatureFinder featureFinder) { + this.featureFinder = featureFinder; + } + + public int complete(final String buffer, final int cursor, final List candidates) { + StringsCompleter delegate = new StringsCompleter(Arrays.asList(featureFinder.getNames())); + return delegate.complete(buffer, cursor, candidates); + } + +} Modified: karaf/trunk/features/command/src/main/resources/OSGI-INF/blueprint/features-command.xml URL: http://svn.apache.org/viewvc/karaf/trunk/features/command/src/main/resources/OSGI-INF/blueprint/features-command.xml?rev=1227132&r1=1227131&r2=1227132&view=diff ============================================================================== --- karaf/trunk/features/command/src/main/resources/OSGI-INF/blueprint/features-command.xml (original) +++ karaf/trunk/features/command/src/main/resources/OSGI-INF/blueprint/features-command.xml Wed Jan 4 12:22:38 2012 @@ -74,8 +74,31 @@ <ref component-id="allFeatureCompleter" /> </completers> </command> + <command> + <action class="org.apache.karaf.features.command.ChooseUrlCommand"> + <property name="featureFinder" ref="featureFinder" /> + <property name="featuresService" ref="featuresService" /> + </action> + <completers> + <ref component-id="featureRepoCompleter" /> + <null/> + </completers> + </command> </command-bundle> + <bean id="featureRepoCompleter" class="org.apache.karaf.features.command.completers.FeatureRepoNameCompleter"> + <property name="featureFinder" ref="featureFinder" /> + </bean> + + <bean id="featureFinder" class="org.apache.karaf.features.command.FeatureFinder"> + </bean> + + <service ref="featureFinder" interface="org.osgi.service.cm.ManagedService" > + <service-properties> + <entry key="service.pid" value="org.apache.karaf.features.repos" /> + </service-properties> + </service> + <reference id="featuresService" interface="org.apache.karaf.features.FeaturesService" /> <bean id="uninstalledFeatureCompleter" class="org.apache.karaf.features.command.completers.AvailableFeatureCompleter">