FELIX-1869 - Need better UI feedback when features commands fail


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@880637 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/deployer/features/src/main/java/org/apache/felix/karaf/deployer/features/FeatureDeploymentListener.java b/karaf/deployer/features/src/main/java/org/apache/felix/karaf/deployer/features/FeatureDeploymentListener.java
index 23a1ba3..6a7f256 100644
--- a/karaf/deployer/features/src/main/java/org/apache/felix/karaf/deployer/features/FeatureDeploymentListener.java
+++ b/karaf/deployer/features/src/main/java/org/apache/felix/karaf/deployer/features/FeatureDeploymentListener.java
@@ -17,6 +17,7 @@
 package org.apache.felix.karaf.deployer.features;
 
 import java.io.File;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Arrays;
 import java.util.EnumSet;
@@ -115,22 +116,21 @@
     }
 
     public void bundleChanged(BundleEvent bundleEvent) {
-        try {
             Bundle bundle = bundleEvent.getBundle();
             if (bundleEvent.getType() == BundleEvent.RESOLVED) {
                 Enumeration featuresUrlEnumeration = bundle.findEntries("/META-INF/" + FEATURE_PATH + "/", "*.xml", false);
                 while (featuresUrlEnumeration != null && featuresUrlEnumeration.hasMoreElements()) {
                     URL url = (URL) featuresUrlEnumeration.nextElement();
-                    featuresService.addRepository(url.toURI());
-                    for (Repository repo : featuresService.listRepositories()) {
-                        if (repo.getURI().equals(url.toURI())) {
-                            Set<Feature> features = new HashSet<Feature>(Arrays.asList(repo.getFeatures()));
-                            try {
-                                featuresService.installFeatures(features, EnumSet.noneOf(FeaturesService.Option.class));
-                            } catch (Exception e) {
-                                LOGGER.error("Unable to install features", e);
+                    try {
+                        featuresService.addRepository(url.toURI());
+                        for (Repository repo : featuresService.listRepositories()) {
+                            if (repo.getURI().equals(url.toURI())) {
+                                Set<Feature> features = new HashSet<Feature>(Arrays.asList(repo.getFeatures()));
+                                    featuresService.installFeatures(features, EnumSet.noneOf(FeaturesService.Option.class));
                             }
                         }
+                    } catch (Exception e) {
+                        LOGGER.error("Unable to install features", e);
                     }
                 }
             } else if (bundleEvent.getType() == BundleEvent.UNINSTALLED) {
@@ -138,22 +138,27 @@
                 while (featuresUrlEnumeration != null && featuresUrlEnumeration.hasMoreElements()) {
                     URL url = (URL) featuresUrlEnumeration.nextElement();
                     for (Repository repo : featuresService.listRepositories()) {
-                        if (repo.getURI().equals(url.toURI())) {
-                            for (Feature f : repo.getFeatures()) {
-                                try {
-                                    featuresService.uninstallFeature(f.getName(), f.getVersion());
-                                } catch (Exception e) {
-                                    LOGGER.error("Unable to uninstall feature: " + f.getName(), e);
+                        try {
+                            if (repo.getURI().equals(url.toURI())) {
+                                for (Feature f : repo.getFeatures()) {
+                                    try {
+                                        featuresService.uninstallFeature(f.getName(), f.getVersion());
+                                    } catch (Exception e) {
+                                        LOGGER.error("Unable to uninstall feature: " + f.getName(), e);
+                                    }
                                 }
                             }
+                        } catch (Exception e) {
+                            LOGGER.error("Unable to uninstall features: " + url, e);
                         }
                     }
-                    featuresService.removeRepository(url.toURI());
+                    try {
+                        featuresService.removeRepository(url.toURI());
+                    } catch (URISyntaxException e) {
+                        LOGGER.error("Unable to remove repository: " + url, e);
+                    }
                 }
             }
-        } catch (Exception e) {
-            LOGGER.error("Unable to install / uninstall feature", e);
-        }
     }
 
     protected Document parse(File artifact) throws Exception {
diff --git a/karaf/features/command/src/main/java/org/apache/felix/karaf/features/command/AddUrlCommand.java b/karaf/features/command/src/main/java/org/apache/felix/karaf/features/command/AddUrlCommand.java
index 2a3141a..237ac50 100644
--- a/karaf/features/command/src/main/java/org/apache/felix/karaf/features/command/AddUrlCommand.java
+++ b/karaf/features/command/src/main/java/org/apache/felix/karaf/features/command/AddUrlCommand.java
@@ -31,7 +31,11 @@
 
     protected void doExecute(FeaturesService admin) throws Exception {
         for (String url : urls) {
-            admin.addRepository(new URI(url));
+            try {
+                admin.addRepository(new URI(url));
+            } catch (Exception e) {
+                System.out.println("Could not add Feature Repository:\n" + e );  
+            }
         }
     }
 }
diff --git a/karaf/features/command/src/main/java/org/apache/felix/karaf/features/command/RefreshUrlCommand.java b/karaf/features/command/src/main/java/org/apache/felix/karaf/features/command/RefreshUrlCommand.java
index de088b2..de67840 100644
--- a/karaf/features/command/src/main/java/org/apache/felix/karaf/features/command/RefreshUrlCommand.java
+++ b/karaf/features/command/src/main/java/org/apache/felix/karaf/features/command/RefreshUrlCommand.java
@@ -39,9 +39,13 @@
             }
         }
         for (String strUri : urls) {
-            URI uri = new URI(strUri);
-            admin.removeRepository(uri);
-            admin.addRepository(uri);
+            try {
+                URI uri = new URI(strUri);
+                admin.removeRepository(uri);
+                admin.addRepository(uri);
+            } catch (Exception e) {
+                System.out.println("Could not refresh Feature Repository:\n" + e.getMessage() );
+            }
         }
     }
 }
diff --git a/karaf/features/core/src/main/java/org/apache/felix/karaf/features/internal/FeaturesServiceImpl.java b/karaf/features/core/src/main/java/org/apache/felix/karaf/features/internal/FeaturesServiceImpl.java
index 5a4da58..07e9199 100644
--- a/karaf/features/core/src/main/java/org/apache/felix/karaf/features/internal/FeaturesServiceImpl.java
+++ b/karaf/features/core/src/main/java/org/apache/felix/karaf/features/internal/FeaturesServiceImpl.java
@@ -163,16 +163,11 @@
 
     protected RepositoryImpl internalAddRepository(URI uri) throws Exception {
     	RepositoryImpl repo = null;
-        try {
-            repo = new RepositoryImpl(uri);
-            repo.load();
-            repositories.put(uri, repo);
-            callListeners(new RepositoryEvent(repo, RepositoryEvent.EventType.RepositoryAdded, false));
-            features = null;
-            
-        } catch (Exception e) {
-            LOGGER.warn(e.getMessage());
-        }
+        repo = new RepositoryImpl(uri);
+        repo.load();
+        repositories.put(uri, repo);
+        callListeners(new RepositoryEvent(repo, RepositoryEvent.EventType.RepositoryAdded, false));
+        features = null;
         return repo;
         
     }
diff --git a/karaf/features/core/src/main/java/org/apache/felix/karaf/features/internal/RepositoryImpl.java b/karaf/features/core/src/main/java/org/apache/felix/karaf/features/internal/RepositoryImpl.java
index 88f4c6e..374f3cf 100644
--- a/karaf/features/core/src/main/java/org/apache/felix/karaf/features/internal/RepositoryImpl.java
+++ b/karaf/features/core/src/main/java/org/apache/felix/karaf/features/internal/RepositoryImpl.java
@@ -21,6 +21,7 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URLConnection;
+import java.rmi.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.Hashtable;
@@ -33,6 +34,8 @@
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -47,6 +50,7 @@
  */
 public class RepositoryImpl implements Repository {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(RepositoryImpl.class);
     private int unnamedRepoId = 0;
     private String name;
     private URI uri;
@@ -106,7 +110,12 @@
                 }
                 if ("repository".equals(node.getNodeName())) {
                     Element e = (Element) nodes.item(i);
-                    repositories.add(new URI(e.getTextContent()));
+                    try {
+                        URI newrepo = new URI(e.getTextContent());
+                        repositories.add(newrepo);
+                    } catch (URISyntaxException ex) {
+                        LOGGER.error("Could not load feature repository: " + ex.getMessage() + " in feature repository " + uri);
+                    }
                 } else if ("feature".equals(node.getNodeName())) {
                     Element e = (Element) nodes.item(i);
                     String name = e.getAttribute("name");
@@ -155,10 +164,10 @@
             throw (IOException) new IOException().initCause(e);
         } catch (ParserConfigurationException e) {
             throw (IOException) new IOException().initCause(e);
-        } catch (URISyntaxException e) {
-            throw (IOException) new IOException(e.getMessage() + " : " + uri).initCause(e);
         } catch (IllegalArgumentException e) {
             throw (IOException) new IOException(e.getMessage() + " : " + uri).initCause(e);
+        } catch (Exception e) {
+            throw (IOException) new IOException(e.getMessage() + " : " + uri).initCause(e);
         }
     }