Author: gnodet
Date: Thu Mar 27 09:58:25 2008
New Revision: 641892
URL: http://svn.apache.org/viewvc?rev=641892&view=rev
Log:
SMX4KL-20, SMX4KNL-25: feature command enhancements (work in progress)
Added:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/InstallFeatureCommand.java
- copied, changed from r635461,
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/AddUrlCommand.java
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/ListFeaturesCommand.java
- copied, changed from r635461,
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/ListUrlCommand.java
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/RefreshUrlCommand.java
(contents, props changed)
- copied, changed from r635461,
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/AddUrlCommand.java
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/UninstallFeatureCommand.java
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-features/pom.xml
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/Feature.java
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/FeaturesService.java
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/Repository.java
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/CommandProxy.java
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/FeatureImpl.java
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/FeaturesServiceImpl.java
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/RepositoryImpl.java
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/resources/META-INF/spring/gshell-features.xml
Modified: servicemix/smx4/kernel/trunk/gshell/gshell-features/pom.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/pom.xml?rev=641892&r1=641891&r2=641892&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-features/pom.xml (original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-features/pom.xml Thu Mar 27
09:58:25 2008
@@ -46,6 +46,23 @@
</dependency>
<dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>${felix.compendium.version}</version>
+ <scope>provided</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.foundation</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>javax.servlet</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.bundlerepository</artifactId>
<version>${felix.bundlerepository.version}</version>
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/Feature.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/Feature.java?rev=641892&r1=641891&r2=641892&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/Feature.java
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/Feature.java
Thu Mar 27 09:58:25 2008
@@ -16,6 +16,9 @@
*/
package org.apache.servicemix.gshell.features;
+import java.util.List;
+import java.util.Map;
+
/**
* A feature is a list of bundles associated identified by its name.
*/
@@ -23,6 +26,8 @@
String getName();
- String[] getBundles();
+ List<String> getBundles();
+
+ Map<String, Map<String, String>> getConfigurations();
}
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/FeaturesService.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/FeaturesService.java?rev=641892&r1=641891&r2=641892&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/FeaturesService.java
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/FeaturesService.java
Thu Mar 27 09:58:25 2008
@@ -28,4 +28,13 @@
void removeRepository(URL url);
Repository[] listRepositories();
+
+ void installFeature(String name) throws Exception;
+
+ void uninstallFeature(String name) throws Exception;
+
+ String[] listFeatures();
+
+ String[] listInstalledFeatures();
+
}
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/Repository.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/Repository.java?rev=641892&r1=641891&r2=641892&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/Repository.java
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/Repository.java
Thu Mar 27 09:58:25 2008
@@ -16,6 +16,7 @@
*/
package org.apache.servicemix.gshell.features;
+import java.io.IOException;
import java.net.URL;
/**
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/CommandProxy.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/CommandProxy.java?rev=641892&r1=641891&r2=641892&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/CommandProxy.java
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/CommandProxy.java
Thu Mar 27 09:58:25 2008
@@ -75,7 +75,7 @@
}
protected void deploy(RepositoryAdmin admin) throws Exception {
- List<String> bundles = Arrays.asList(feature.getBundles());
+ List<String> bundles = feature.getBundles();
int idx0 = -1;
while (++idx0 < bundles.size()) {
if (bundles.get(idx0).startsWith("obr:")) {
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/FeatureImpl.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/FeatureImpl.java?rev=641892&r1=641891&r2=641892&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/FeatureImpl.java
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/FeatureImpl.java
Thu Mar 27 09:58:25 2008
@@ -17,7 +17,9 @@
package org.apache.servicemix.gshell.features.internal;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.servicemix.gshell.features.Feature;
@@ -28,6 +30,7 @@
private String name;
private List<String> bundles = new ArrayList<String>();
+ private Map<String, Map<String,String>> configs = new HashMap<String,
Map<String,String>>();
public FeatureImpl(String name) {
this.name = name;
@@ -37,11 +40,19 @@
return name;
}
- public String[] getBundles() {
- return bundles.toArray(new String[bundles.size()]);
+ public List<String> getBundles() {
+ return bundles;
+ }
+
+ public Map<String, Map<String, String>> getConfigurations() {
+ return configs;
}
public void addBundle(String bundle) {
bundles.add(bundle);
+ }
+
+ public void addConfig(String name, Map<String,String> properties) {
+ configs.put(name, properties);
}
}
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/FeaturesServiceImpl.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/FeaturesServiceImpl.java?rev=641892&r1=641891&r2=641892&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/FeaturesServiceImpl.java
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/FeaturesServiceImpl.java
Thu Mar 27 09:58:25 2008
@@ -16,19 +16,27 @@
*/
package org.apache.servicemix.gshell.features.internal;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
import org.apache.servicemix.gshell.features.Feature;
import org.apache.servicemix.gshell.features.FeaturesService;
import org.apache.servicemix.gshell.features.Repository;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.service.obr.RepositoryAdmin;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.prefs.PreferencesService;
import org.springframework.osgi.context.BundleContextAware;
/**
@@ -40,10 +48,14 @@
*/
public class FeaturesServiceImpl implements FeaturesService,
BundleContextAware {
+ private static final String ALIAS_KEY = "_alias_factory_pid";
+
private BundleContext bundleContext;
- private RepositoryAdmin admin;
+ private ConfigurationAdmin configAdmin;
+ private PreferencesService preferences;
private Set<URL> urls;
private Map<URL, RepositoryImpl> repositories = new HashMap<URL,
RepositoryImpl>();
+ private Map<String, Feature> features;
public BundleContext getBundleContext() {
return bundleContext;
@@ -53,12 +65,20 @@
this.bundleContext = bundleContext;
}
- public RepositoryAdmin getAdmin() {
- return admin;
+ public ConfigurationAdmin getConfigAdmin() {
+ return configAdmin;
+ }
+
+ public void setConfigAdmin(ConfigurationAdmin configAdmin) {
+ this.configAdmin = configAdmin;
+ }
+
+ public PreferencesService getPreferences() {
+ return preferences;
}
- public void setAdmin(RepositoryAdmin admin) {
- this.admin = admin;
+ public void setPreferences(PreferencesService preferences) {
+ this.preferences = preferences;
}
public void setUrls(String urls) throws MalformedURLException {
@@ -71,17 +91,18 @@
public void addRepository(URL url) throws Exception {
RepositoryImpl repo = new RepositoryImpl(url);
+ repositories.put(url, repo);
+ features = null;
repo.load();
Feature[] features = repo.getFeatures();
for (int i = 0; i < features.length; i++) {
CommandProxy cmd = new CommandProxy(features[i], bundleContext);
}
- repositories.put(url, repo);
}
public void removeRepository(URL url) {
Repository repo = repositories.remove(url);
- // TODO: ...
+ features = null;
}
public Repository[] listRepositories() {
@@ -89,6 +110,64 @@
return repos.toArray(new Repository[repos.size()]);
}
+ public void installFeature(String name) throws Exception {
+ Feature f = getFeature(name);
+ if (f == null) {
+ throw new Exception("No feature named '" + name + "' available");
+ }
+ for (String config : f.getConfigurations().keySet()) {
+ Dictionary<String,String> props = new Hashtable<String,
String>(f.getConfigurations().get(config));
+ String[] pid = parsePid(config);
+ if (pid[1] != null) {
+ props.put(ALIAS_KEY, pid[1]);
+ }
+ Configuration cfg = getConfiguration(configAdmin, pid[0], pid[1]);
+ if (cfg.getBundleLocation() != null) {
+ cfg.setBundleLocation(null);
+ }
+ cfg.update(props);
+ }
+ for (String bundle : f.getBundles()) {
+ Bundle b = getBundleContext().installBundle(bundle, null);
+ b.start();
+ }
+ }
+
+ public void uninstallFeature(String name) throws Exception {
+ //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public String[] listFeatures() {
+ Collection<String> features = new ArrayList<String>();
+ for (Repository repo : repositories.values()) {
+ for (Feature f : repo.getFeatures()) {
+ features.add(f.getName());
+ }
+ }
+ return features.toArray(new String[features.size()]);
+ }
+
+ public String[] listInstalledFeatures() {
+ return new String[0]; //To change body of implemented methods use
File | Settings | File Templates.
+ }
+
+ protected Feature getFeature(String name) {
+ return getFeatures().get(name);
+ }
+
+ protected Map<String, Feature> getFeatures() {
+ if (features == null) {
+ Map<String, Feature> map = new HashMap<String, Feature>();
+ for (Repository repo : repositories.values()) {
+ for (Feature f : repo.getFeatures()) {
+ map.put(f.getName(), f);
+ }
+ }
+ features = map;
+ }
+ return features;
+ }
+
public void start() throws Exception {
if (urls != null) {
for (URL url : urls) {
@@ -103,4 +182,30 @@
removeRepository(repositories.keySet().iterator().next());
}
}
+
+ protected String[] parsePid(String pid) {
+ int n = pid.indexOf('-');
+ if (n > 0) {
+ String factoryPid = pid.substring(n + 1);
+ pid = pid.substring(0, n);
+ return new String[]{pid, factoryPid};
+ } else {
+ return new String[]{pid, null};
+ }
+ }
+
+ protected Configuration getConfiguration(ConfigurationAdmin
configurationAdmin,
+ String pid, String factoryPid)
throws IOException, InvalidSyntaxException {
+ if (factoryPid != null) {
+ Configuration[] configs =
configurationAdmin.listConfigurations("(|(" + ALIAS_KEY + "=" + pid +
")(.alias_factory_pid=" + factoryPid + "))");
+ if (configs == null || configs.length == 0) {
+ return configurationAdmin.createFactoryConfiguration(pid,
null);
+ } else {
+ return configs[0];
+ }
+ } else {
+ return configurationAdmin.getConfiguration(pid, null);
+ }
+ }
+
}
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/RepositoryImpl.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/RepositoryImpl.java?rev=641892&r1=641891&r2=641892&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/RepositoryImpl.java
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/RepositoryImpl.java
Thu Mar 27 09:58:25 2008
@@ -16,11 +16,17 @@
*/
package org.apache.servicemix.gshell.features.internal;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Hashtable;
import java.util.List;
+import java.util.Map;
+import java.util.Properties;
import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -28,6 +34,7 @@
import org.apache.servicemix.gshell.features.Feature;
import org.apache.servicemix.gshell.features.Repository;
+import org.xml.sax.SAXException;
/**
* The repository implementation.
@@ -49,22 +56,42 @@
return features.toArray(new Feature[features.size()]);
}
- public void load() throws Exception {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- Document doc = factory.newDocumentBuilder().parse(url.openStream());
- NodeList nodes =
doc.getDocumentElement().getElementsByTagName("feature");
- for (int i = 0; i < nodes.getLength(); i++) {
- Element e = (Element) nodes.item(i);
- String name = e.getAttribute("name");
- FeatureImpl f = new FeatureImpl(name);
- NodeList bundleNodes = e.getElementsByTagName("bundle");
- for (int j = 0; j < bundleNodes.getLength(); j++) {
- Element b = (Element) bundleNodes.item(j);
- f.addBundle(b.getTextContent());
+ public void load() throws IOException {
+ try {
+ features = new ArrayList<Feature>();
+ DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
+ Document doc =
factory.newDocumentBuilder().parse(url.openStream());
+ NodeList nodes =
doc.getDocumentElement().getElementsByTagName("feature");
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Element e = (Element) nodes.item(i);
+ String name = e.getAttribute("name");
+ FeatureImpl f = new FeatureImpl(name);
+ NodeList configNodes = e.getElementsByTagName("config");
+ for (int j = 0; j < configNodes.getLength(); j++) {
+ Element c = (Element) configNodes.item(j);
+ String cfgName = c.getAttribute("name");
+ String data = c.getTextContent();
+ Properties properties = new Properties();
+ properties.load(new ByteArrayInputStream(data.getBytes()));
+ Map<String, String> hashtable = new Hashtable<String,
String>();
+ for (Object key : properties.keySet()) {
+ String n = key.toString();
+ hashtable.put(n, properties.getProperty(n));
+ }
+ f.addConfig(cfgName, hashtable);
+ }
+ NodeList bundleNodes = e.getElementsByTagName("bundle");
+ for (int j = 0; j < bundleNodes.getLength(); j++) {
+ Element b = (Element) bundleNodes.item(j);
+ f.addBundle(b.getTextContent());
+ }
+ features.add(f);
}
- features.add(f);
+ } catch (SAXException e) {
+ throw (IOException) new IOException().initCause(e);
+ } catch (ParserConfigurationException e) {
+ throw (IOException) new IOException().initCause(e);
}
-
}
}
Copied:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/InstallFeatureCommand.java
(from r635461,
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/AddUrlCommand.java)
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/InstallFeatureCommand.java?p2=servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/InstallFeatureCommand.java&p1=servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/AddUrlCommand.java&r1=635461&r2=641892&rev=641892&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/AddUrlCommand.java
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/InstallFeatureCommand.java
Thu Mar 27 09:58:25 2008
@@ -23,15 +23,13 @@
import org.apache.geronimo.gshell.command.annotation.CommandComponent;
import org.apache.servicemix.gshell.features.FeaturesService;
[EMAIL PROTECTED](id="features:addUrl", description="Add a list of repository
URLs to the features service")
-public class AddUrlCommand extends FeaturesCommandSupport {
[EMAIL PROTECTED](id="features:install", description="Install a feature")
+public class InstallFeatureCommand extends FeaturesCommandSupport {
- @Argument(required = true, multiValued = true, description = "Repository
URLs")
- List<String> urls;
+ @Argument(required = true, description = "The name of the feature")
+ String name;
protected void doExecute(FeaturesService admin) throws Exception {
- for (String url : urls) {
- admin.addRepository(new URL(url));
- }
+ admin.installFeature(name);
}
-}
+}
\ No newline at end of file
Copied:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/ListFeaturesCommand.java
(from r635461,
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/ListUrlCommand.java)
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/ListFeaturesCommand.java?p2=servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/ListFeaturesCommand.java&p1=servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/ListUrlCommand.java&r1=635461&r2=641892&rev=641892&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/ListUrlCommand.java
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/ListFeaturesCommand.java
Thu Mar 27 09:58:25 2008
@@ -19,18 +19,31 @@
import org.apache.servicemix.gshell.features.FeaturesService;
import org.apache.servicemix.gshell.features.Repository;
import org.apache.geronimo.gshell.command.annotation.CommandComponent;
+import org.apache.geronimo.gshell.clp.Option;
[EMAIL PROTECTED](id="features:listUrl", description="Display the repository
URLs currently associated with the features service.")
-public class ListUrlCommand extends FeaturesCommandSupport {
[EMAIL PROTECTED](id="features:list", description="List existing features.")
+public class ListFeaturesCommand extends FeaturesCommandSupport {
+
+ @Option(name = "-i", aliases={"--installed"}, description="Display the
list of installed features")
+ boolean installed;
protected void doExecute(FeaturesService admin) throws Exception {
- Repository[] repos = admin.listRepositories();
- if ((repos != null) && (repos.length > 0)) {
- for (int i = 0; i < repos.length; i++) {
- io.out.println(repos[i].getURL());
+ String[] features;
+ if (installed) {
+ features = admin.listInstalledFeatures();
+ } else {
+ features = admin.listFeatures();
+ }
+ if ((features != null) && (features.length > 0)) {
+ for (int i = 0; i < features.length; i++) {
+ io.out.println(features[i]);
}
} else {
- io.out.println("No repository URLs are set.");
+ if (installed) {
+ io.out.println("No features installed.");
+ } else {
+ io.out.println("No features available.");
+ }
}
}
-}
+}
\ No newline at end of file
Copied:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/RefreshUrlCommand.java
(from r635461,
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/AddUrlCommand.java)
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/RefreshUrlCommand.java?p2=servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/RefreshUrlCommand.java&p1=servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/AddUrlCommand.java&r1=635461&r2=641892&rev=641892&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/AddUrlCommand.java
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/RefreshUrlCommand.java
Thu Mar 27 09:58:25 2008
@@ -23,15 +23,17 @@
import org.apache.geronimo.gshell.command.annotation.CommandComponent;
import org.apache.servicemix.gshell.features.FeaturesService;
[EMAIL PROTECTED](id="features:addUrl", description="Add a list of repository
URLs to the features service")
-public class AddUrlCommand extends FeaturesCommandSupport {
[EMAIL PROTECTED](id="features:refreshUrl", description="Reload the
repositories to obtain a fresh list of features")
+public class RefreshUrlCommand extends FeaturesCommandSupport {
@Argument(required = true, multiValued = true, description = "Repository
URLs")
List<String> urls;
protected void doExecute(FeaturesService admin) throws Exception {
- for (String url : urls) {
- admin.addRepository(new URL(url));
+ for (String strUrl : urls) {
+ URL url = new URL(strUrl);
+ admin.removeRepository(url);
+ admin.addRepository(url);
}
}
-}
+}
\ No newline at end of file
Propchange:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/RefreshUrlCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/UninstallFeatureCommand.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/UninstallFeatureCommand.java?rev=641892&view=auto
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/UninstallFeatureCommand.java
(added)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/commands/UninstallFeatureCommand.java
Thu Mar 27 09:58:25 2008
@@ -0,0 +1,35 @@
+/*
+ * 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.servicemix.gshell.features.internal.commands;
+
+import java.util.List;
+import java.net.URL;
+
+import org.apache.geronimo.gshell.clp.Argument;
+import org.apache.geronimo.gshell.command.annotation.CommandComponent;
+import org.apache.servicemix.gshell.features.FeaturesService;
+
[EMAIL PROTECTED](id="features:uninstall", description="Uninstall a feature")
+public class UninstallFeatureCommand extends FeaturesCommandSupport {
+
+ @Argument(required = true, description = "The name of the feature")
+ String name;
+
+ protected void doExecute(FeaturesService admin) throws Exception {
+ admin.uninstallFeature(name);
+ }
+}
\ No newline at end of file
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/resources/META-INF/spring/gshell-features.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/resources/META-INF/spring/gshell-features.xml?rev=641892&r1=641891&r2=641892&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/resources/META-INF/spring/gshell-features.xml
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/resources/META-INF/spring/gshell-features.xml
Thu Mar 27 09:58:25 2008
@@ -38,10 +38,24 @@
<bean id="removeUrl"
class="org.apache.servicemix.gshell.features.internal.commands.RemoveUrlCommand"
/>
+ <bean id="refreshUrl"
class="org.apache.servicemix.gshell.features.internal.commands.RefreshUrlCommand"
/>
+
+ <bean id="installFeature"
class="org.apache.servicemix.gshell.features.internal.commands.InstallFeatureCommand"
/>
+
+ <bean id="uninstallFeature"
class="org.apache.servicemix.gshell.features.internal.commands.UninstallFeatureCommand"
/>
+
+ <bean id="listFeatures"
class="org.apache.servicemix.gshell.features.internal.commands.ListFeaturesCommand"
/>
+
<bean id="featuresService"
class="org.apache.servicemix.gshell.features.internal.FeaturesServiceImpl"
init-method="start" destroy-method="stop">
<property name="urls" value="${featuresRepositories}" />
+ <property name="configAdmin" ref="configAdmin" />
+ <property name="preferences" ref="preferences" />
</bean>
+ <osgi:reference id="configAdmin"
interface="org.osgi.service.cm.ConfigurationAdmin" />
+
+ <osgi:reference id="preferences"
interface="org.osgi.service.prefs.PreferencesService" cardinality="0..1" />
+
<osgi:service ref="addUrl"
interface="org.apache.geronimo.gshell.command.Command">
<osgi:service-properties>
<entry key="shell" value="features"/>
@@ -60,6 +74,34 @@
<osgi:service-properties>
<entry key="shell" value="features"/>
<entry key="alias" value="removeUrl"/>
+ </osgi:service-properties>
+ </osgi:service>
+
+ <osgi:service ref="refreshUrl"
interface="org.apache.geronimo.gshell.command.Command">
+ <osgi:service-properties>
+ <entry key="shell" value="features"/>
+ <entry key="alias" value="refreshUrl"/>
+ </osgi:service-properties>
+ </osgi:service>
+
+ <osgi:service ref="installFeature"
interface="org.apache.geronimo.gshell.command.Command">
+ <osgi:service-properties>
+ <entry key="shell" value="features"/>
+ <entry key="alias" value="installFeature"/>
+ </osgi:service-properties>
+ </osgi:service>
+
+ <osgi:service ref="uninstallFeature"
interface="org.apache.geronimo.gshell.command.Command">
+ <osgi:service-properties>
+ <entry key="shell" value="features"/>
+ <entry key="alias" value="uninstallFeature"/>
+ </osgi:service-properties>
+ </osgi:service>
+
+ <osgi:service ref="listFeatures"
interface="org.apache.geronimo.gshell.command.Command">
+ <osgi:service-properties>
+ <entry key="shell" value="features"/>
+ <entry key="alias" value="listFeatures"/>
</osgi:service-properties>
</osgi:service>