You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/10/10 17:43:03 UTC

svn commit: r703503 - in /servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features: Repository.java internal/FeaturesServiceImpl.java internal/RepositoryImpl.java

Author: gnodet
Date: Fri Oct 10 08:43:03 2008
New Revision: 703503

URL: http://svn.apache.org/viewvc?rev=703503&view=rev
Log:
SMX4KNL-116: Allow repository descriptors to reference other repository descriptors

Modified:
    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/FeaturesServiceImpl.java
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/gshell/features/internal/RepositoryImpl.java

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=703503&r1=703502&r2=703503&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 Fri Oct 10 08:43:03 2008
@@ -27,6 +27,8 @@
 
     URI getURI();
 
+    URI[] getRepositories() throws Exception;
+
     Feature[] getFeatures() throws Exception;
 
 }

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=703503&r1=703502&r2=703503&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 Fri Oct 10 08:43:03 2008
@@ -31,6 +31,8 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.jar.JarInputStream;
 import java.util.jar.Manifest;
 
@@ -112,8 +114,10 @@
     }
 
     public void addRepository(URI uri) throws Exception {
-        internalAddRepository(uri);
-        saveState();
+        if (!repositories.values().contains(uri)) {
+            internalAddRepository(uri);
+            saveState();
+        }
     }
 
     protected void internalAddRepository(URI uri) throws Exception {
@@ -123,8 +127,10 @@
     }
 
     public void removeRepository(URI uri) {
-        internalRemoveRepository(uri);
-        saveState();
+        if (repositories.values().contains(uri)) {
+            internalRemoveRepository(uri);
+            saveState();
+        }
     }
 
     public void internalRemoveRepository(URI uri) {
@@ -219,21 +225,19 @@
 
     public String[] listFeatures() throws Exception {
         Collection<String> features = new ArrayList<String>();
-        for (Repository repo : repositories.values()) {
-            for (Feature f : repo.getFeatures()) {
-            	String installStatus = installed.containsKey(f.getName()) ? "installed  " : "uninstalled";
-            	String version = f.getVersion();
-            	switch (version.length()) {
-            	case 1: version = "       " + version;
-            	case 2: version = "      " + version;
-            	case 3: version = "     " + version;
-            	case 4: version = "    " + version;
-            	case 5: version = "   " + version;
-            	case 6: version = "  " + version;
-            	case 7: version = " " + version;
-            	}
-                features.add("[" + installStatus + "] " + " [" + version + "] " + f.getName());
+        for (Feature f : getFeatures().values()) {
+            String installStatus = installed.containsKey(f.getName()) ? "installed  " : "uninstalled";
+            String version = f.getVersion();
+            switch (version.length()) {
+            case 1: version = "       " + version;
+            case 2: version = "      " + version;
+            case 3: version = "     " + version;
+            case 4: version = "    " + version;
+            case 5: version = "   " + version;
+            case 6: version = "  " + version;
+            case 7: version = " " + version;
             }
+            features.add("[" + installStatus + "] " + " [" + version + "] " + f.getName());
         }
         return features.toArray(new String[features.size()]);
     }
@@ -249,6 +253,23 @@
     protected Map<String, Feature> getFeatures() throws Exception {
         if (features == null) {
             Map<String, Feature> map = new HashMap<String, Feature>();
+            // Two phase load:
+            // * first load dependent repositories
+            for (;;) {
+                boolean newRepo = false;
+                for (Repository repo : listRepositories()) {
+                    for (URI uri : repo.getRepositories()) {
+                        if (!repositories.keySet().contains(uri)) {
+                            internalAddRepository(uri);
+                            newRepo = true;
+                        }
+                    }
+                }
+                if (!newRepo) {
+                    break;
+                }
+            }
+            // * then load all features
             for (Repository repo : repositories.values()) {
                 for (Feature f : repo.getFeatures()) {
                     map.put(f.getName(), f);

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=703503&r1=703502&r2=703503&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 Fri Oct 10 08:43:03 2008
@@ -19,6 +19,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.List;
@@ -44,6 +45,7 @@
 
     private URI uri;
     private List<Feature> features;
+    private List<URI> repositories;
 
     public RepositoryImpl(URI uri) {
         this.uri = uri;
@@ -53,6 +55,13 @@
         return uri;
     }
 
+    public URI[] getRepositories() throws Exception {
+        if (repositories == null) {
+            load();
+        }
+        return repositories.toArray(new URI[repositories.size()]);
+    }
+
     public Feature[] getFeatures() throws Exception {
         if (features == null) {
             load();
@@ -62,53 +71,61 @@
 
     public void load() throws IOException {
         try {
+            repositories = new ArrayList<URI>();
             features = new ArrayList<Feature>();
             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
             Document doc = factory.newDocumentBuilder().parse(uri.toURL().openStream());
             NodeList nodes = doc.getDocumentElement().getChildNodes();
             for (int i = 0; i < nodes.getLength(); i++) {
                 Node node = nodes.item(i);
-                if (!(node instanceof Element) || !"feature".equals(node.getNodeName())) {
+                if (!(node instanceof Element)) {
                     continue;
                 }
-                Element e = (Element) nodes.item(i);
-                String name = e.getAttribute("name");
-                FeatureImpl f = new FeatureImpl(name);
-                String version = e.getAttribute("version");
-                if (version != null && version.length() > 0) {
-                	f.setVersion(version);
-                }
-                
-                NodeList featureNodes = e.getElementsByTagName("feature");
-                for (int j = 0; j < featureNodes.getLength(); j++) {
-                    Element b = (Element) featureNodes.item(j);
-                    f.addDependency(b.getTextContent());
-                }
-                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));
+                if ("repository".equals(node.getNodeName())) {
+                    Element e = (Element) nodes.item(i);
+                    repositories.add(new URI(e.getTextContent()));
+                } else if ("feature".equals(node.getNodeName())) {
+                    Element e = (Element) nodes.item(i);
+                    String name = e.getAttribute("name");
+                    FeatureImpl f = new FeatureImpl(name);
+                    String version = e.getAttribute("version");
+                    if (version != null && version.length() > 0) {
+                        f.setVersion(version);
                     }
-                    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());
+
+                    NodeList featureNodes = e.getElementsByTagName("feature");
+                    for (int j = 0; j < featureNodes.getLength(); j++) {
+                        Element b = (Element) featureNodes.item(j);
+                        f.addDependency(b.getTextContent());
+                    }
+                    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);
+        } catch (URISyntaxException e) {
+            throw (IOException) new IOException().initCause(e);
         }
     }