You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gn...@apache.org on 2009/06/18 23:10:15 UTC

svn commit: r786282 - /felix/trunk/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/internal/FeaturesServiceImpl.java

Author: gnodet
Date: Thu Jun 18 21:10:14 2009
New Revision: 786282

URL: http://svn.apache.org/viewvc?rev=786282&view=rev
Log:
Fix the addRepository method and clean code a bit

Modified:
    felix/trunk/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/internal/FeaturesServiceImpl.java

Modified: felix/trunk/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/internal/FeaturesServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/internal/FeaturesServiceImpl.java?rev=786282&r1=786281&r2=786282&view=diff
==============================================================================
--- felix/trunk/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/internal/FeaturesServiceImpl.java (original)
+++ felix/trunk/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/internal/FeaturesServiceImpl.java Thu Jun 18 21:10:14 2009
@@ -110,8 +110,8 @@
     public void setUrls(String uris) throws URISyntaxException {
         String[] s = uris.split(",");
         this.uris = new HashSet<URI>();
-        for (int i = 0; i < s.length; i++) {
-            this.uris.add(new URI(s[i]));
+        for (String value : s) {
+            this.uris.add(new URI(value));
         }
     }
 
@@ -120,7 +120,7 @@
     }
 
     public void addRepository(URI uri) throws Exception {
-        if (!repositories.values().contains(uri)) {
+        if (!repositories.containsKey(uri)) {
             internalAddRepository(uri);
             saveState();
         }
@@ -208,7 +208,7 @@
     }
     protected Bundle installBundleIfNeeded(String bundleLocation) throws IOException, BundleException {
         LOGGER.debug("Checking " + bundleLocation);
-        InputStream is = null;
+        InputStream is;
         try {
             is = new BufferedInputStream(new URL(bundleLocation).openStream());
         } catch (RuntimeException e) {
@@ -256,7 +256,7 @@
             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 (");
+            sb.append("Feature named '").append(name).append("' has multiple versions installed (");
             for (int i = 0; i < versions.size(); i++) {
                 if (i > 0) {
                     sb.append(", ");
@@ -291,8 +291,7 @@
 
     public String[] listFeatures() throws Exception {
         Collection<String> features = new ArrayList<String>();
-        for (Map<String, Feature> featureWithDifferentVersion : getFeatures()
-				.values()) {
+        for (Map<String, Feature> featureWithDifferentVersion : getFeatures().values()) {
 			for (Feature f : featureWithDifferentVersion.values()) {
 				String installStatus = installed.containsKey(f) ? "installed  "
 						: "uninstalled";
@@ -358,7 +357,7 @@
                 boolean newRepo = false;
                 for (Repository repo : listRepositories()) {
                     for (URI uri : repo.getRepositories()) {
-                        if (!repositories.keySet().contains(uri)) {
+                        if (!repositories.containsKey(uri)) {
                             internalAddRepository(uri);
                             newRepo = true;
                         }
@@ -535,6 +534,11 @@
         return set;
     }
 
+    static Pattern fuzzyVersion  = Pattern.compile("(\\d+)(\\.(\\d+)(\\.(\\d+))?)?([^a-zA-Z0-9](.*))?",
+                                                   Pattern.DOTALL);
+    static Pattern fuzzyModifier = Pattern.compile("(\\d+[.-])*(.*)",
+                                                   Pattern.DOTALL);
+
     /**
      * Clean up version parameters. Other builders use more fuzzy definitions of
      * the version syntax. This method cleans up such a version to match an OSGi
@@ -543,11 +547,6 @@
      * @param version
      * @return
      */
-    static Pattern fuzzyVersion  = Pattern.compile("(\\d+)(\\.(\\d+)(\\.(\\d+))?)?([^a-zA-Z0-9](.*))?",
-                                                   Pattern.DOTALL);
-    static Pattern fuzzyModifier = Pattern.compile("(\\d+[.-])*(.*)",
-                                                   Pattern.DOTALL);
-
     static public String cleanupVersion(String version) {
         Matcher m = fuzzyVersion.matcher(version);
         if (m.matches()) {