Author: gnodet
Date: Wed Feb 11 19:35:15 2009
New Revision: 743462
URL: http://svn.apache.org/viewvc?rev=743462&view=rev
Log:
SMX4KNL-186: features/uninstall should select the right version if only one
version has been installed
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/internal/FeaturesServiceImpl.java
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/FeaturesServiceTest.java
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/internal/FeaturesServiceImpl.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/internal/FeaturesServiceImpl.java?rev=743462&r1=743461&r2=743462&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/internal/FeaturesServiceImpl.java
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/internal/FeaturesServiceImpl.java
Wed Feb 11 19:35:15 2009
@@ -231,7 +231,27 @@
}
public void uninstallFeature(String name) throws Exception {
- uninstallFeature(name, FeatureImpl.DEFAULT_VERSION);//uninstall
feature with default version
+ List<String> versions = new ArrayList<String>();
+ for (Feature f : installed.keySet()) {
+ if (name.equals(f.getName())) {
+ versions.add(f.getVersion());
+ }
+ }
+ if (versions.size() == 0) {
+ throw new Exception("Feature named '" + name + "' is not
installed");
+ } else if (versions.size() > 1) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Feature named '" + name + "' has multiple versions
installed (");
+ for (int i = 0; i < versions.size(); i++) {
+ if (i > 0) {
+ sb.append(", ");
+ }
+ sb.append(versions.get(i));
+ }
+ sb.append("). Please specify the version to uninstall.");
+ throw new Exception(sb.toString());
+ }
+ uninstallFeature(name, versions.get(0));
}
public void uninstallFeature(String name, String version) throws Exception
{
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/FeaturesServiceTest.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/FeaturesServiceTest.java?rev=743462&r1=743461&r2=743462&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/FeaturesServiceTest.java
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/FeaturesServiceTest.java
Wed Feb 11 19:35:15 2009
@@ -27,6 +27,7 @@
import org.apache.servicemix.kernel.gshell.features.internal.FeatureImpl;
import
org.apache.servicemix.kernel.gshell.features.internal.FeaturesServiceImpl;
import org.apache.servicemix.kernel.gshell.features.FeaturesRegistry;
+import
org.apache.servicemix.kernel.gshell.features.management.ManagedFeaturesRegistry;
import org.easymock.EasyMock;
import org.osgi.service.prefs.PreferencesService;
import org.osgi.service.prefs.Preferences;
@@ -122,4 +123,46 @@
svc.installFeature("f1");
}
+
+ public void testUninstallFeature() throws Exception {
+ File tmp = File.createTempFile("smx", ".feature");
+ PrintWriter pw = new PrintWriter(new FileWriter(tmp));
+ pw.println("<features>");
+ pw.println(" <feature name=\"f1\" version=\"0.1\">");
+ pw.println(" </feature>");
+ pw.println(" <feature name=\"f1\" version=\"0.2\">");
+ pw.println(" </feature>");
+ pw.println("</features>");
+ pw.close();
+
+ URI uri = tmp.toURI();
+
+ BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
+ Bundle installedBundle = EasyMock.createMock(Bundle.class);
+
+ FeaturesServiceImpl svc = new FeaturesServiceImpl();
+ svc.setBundleContext(bundleContext);
+ svc.setFeaturesServiceRegistry(new ManagedFeaturesRegistry());
+ svc.addRepository(uri);
+
+ try {
+ svc.uninstallFeature("f1");
+ fail("Uninstall should have failed as feature is not installed");
+ } catch (Exception e) {
+ // ok
+ }
+
+ svc.installFeature("f1", "0.1");
+ svc.installFeature("f1", "0.2");
+
+ try {
+ svc.uninstallFeature("f1");
+ fail("Uninstall should have failed as feature is installed in
multiple versions");
+ } catch (Exception e) {
+ // ok
+ }
+
+ svc.uninstallFeature("f1", "0.1");
+ svc.uninstallFeature("f1");
+ }
}