Author: gnodet
Date: Tue May 20 11:52:28 2008
New Revision: 658391

URL: http://svn.apache.org/viewvc?rev=658391&view=rev
Log:
SMX4KNL-39: Make bundle locations for SMX configurable

Modified:
    
servicemix/smx4/kernel/trunk/main/src/main/java/org/apache/servicemix/kernel/main/Main.java
    servicemix/smx4/kernel/trunk/main/src/main/resources/config.properties

Modified: 
servicemix/smx4/kernel/trunk/main/src/main/java/org/apache/servicemix/kernel/main/Main.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/main/src/main/java/org/apache/servicemix/kernel/main/Main.java?rev=658391&r1=658390&r2=658391&view=diff
==============================================================================
--- 
servicemix/smx4/kernel/trunk/main/src/main/java/org/apache/servicemix/kernel/main/Main.java
 (original)
+++ 
servicemix/smx4/kernel/trunk/main/src/main/java/org/apache/servicemix/kernel/main/Main.java
 Tue May 20 11:52:28 2008
@@ -90,6 +90,11 @@
      */
     public static final String ENV_SERVICEMIX_BASE = "SERVICEMIX_BASE";
     
+    /**
+     * Config property which identifies directories which contain bundles to 
be loaded by SMX
+     *
+     */
+    public static final String BUNDLE_LOCATIONS = "bundle.locations";
 
     private File servicemixHome;
     private File servicemixBase;
@@ -706,6 +711,32 @@
         Properties configProps = loadPropertiesFile(configPropURL);
         Properties startupProps = loadPropertiesFile(startupPropURL);
         
+       String locations = configProps.getProperty(BUNDLE_LOCATIONS);
+       
+       if (locations != null) {
+           StringTokenizer st = new StringTokenizer(locations, "\" ",true);
+           if (st.countTokens() > 0)
+               {
+                   String location = null;
+                   do
+                       {
+                           location = nextLocation(st);
+                           if (location != null)
+                               {
+                                   File f = new File(location);
+                                   if(f.exists() && f.isDirectory()) {
+                                       bundleDirs.add(f);
+                                   } else {
+                                       System.err.println("Bundle location " + 
location 
+                                                          + " does not exist 
or is not a directory.");
+                                   }
+                               }
+                       }
+                   
+                   while (location != null);
+               }
+       }
+
         // Perform variable substitution for system properties.
         for (Enumeration e = configProps.propertyNames(); e.hasMoreElements(); 
)
         {
@@ -778,22 +809,23 @@
         }
         if( "all".equals( props.getProperty(PROPERTY_AUTO_START,"").trim()) ) {
             props.remove(PROPERTY_AUTO_START);
-            StringBuffer sb = new StringBuffer();
+           ArrayList<File> jars = new ArrayList<File>();
+
+           // We should start all the bundles in the system dir.
             for (File bundleDir : bundleDirs) {
-                // We should start all the bundles in the system dir.
-                File[] bundles = bundleDir.listFiles(new FileFilter() {
-                    public boolean accept(File pathname) {
-                        return pathname.toString().endsWith(".jar");
-                    }
-                });                
-                for (int i = 0; bundles!=null && i < bundles.length; i++) {
-                    try {
-                        
sb.append("\"").append(bundles[i].toURL().toString()).append("\" ");
-                    } catch (MalformedURLException e) {
-                        System.err.print( "Ignoring " + bundles[i].toString() 
+ " (" + e + ")" );
-                    }
-                }
-                       }
+               findJars(bundleDir, jars);
+           }
+           
+            StringBuffer sb = new StringBuffer();
+
+           for (File jar : jars) {
+               try {
+                   sb.append("\"").append(jar.toURL().toString()).append("\" 
");
+               } catch (MalformedURLException e) {
+                   System.err.print( "Ignoring " + jar.toString() + " (" + e + 
")" );
+               }
+           }
+
             props.setProperty(PROPERTY_AUTO_START, sb.toString());
                
         }
@@ -804,6 +836,7 @@
                for (Iterator iterator = startupProps.keySet().iterator(); 
iterator.hasNext();) {
                                String name = (String) iterator.next();
                                File file = findFile(bundleDirs, name);
+
                                if( file !=null ) {
                                        Integer level;
                                        try {
@@ -825,24 +858,53 @@
                                } else {
                                        System.err.println("Bundle listed in 
"+STARTUP_PROPERTIES_FILE_NAME+" configuration not found: " + name);
                                }
-                       }
-               for (Map.Entry<Integer, StringBuffer> entry : 
levels.entrySet()) {
-                props.setProperty(PROPERTY_AUTO_START+"."+entry.getKey(), 
entry.getValue().toString());
-                       }
+               }
+               
+               for (Map.Entry<Integer, StringBuffer> entry : 
levels.entrySet()) {
+                   props.setProperty(PROPERTY_AUTO_START+"."+entry.getKey(), 
entry.getValue().toString());
+               }
         }
 
     }
 
-       private static File findFile(ArrayList<File> bundleDirs, String name) {
-        for (File bundleDir : bundleDirs) {
-               File file = new File(bundleDir, name);
-               if( file.exists() && !file.isDirectory() ) {
-                       return file;
-               }
-        }
-        return null;
+    private static File findFile(ArrayList<File> bundleDirs, String name) {
+       for (File bundleDir : bundleDirs) {
+           File file = findFile(bundleDir, name);
+           if (file != null) {
+               return file;
+           }
        }
+       return null;
+    }
+
+    private static File findFile(File dir, String name) {
+       File theFile = new File(dir, name);
 
+       if( theFile.exists() && !theFile.isDirectory() ) {
+           return theFile;
+       } 
+
+       for (File file : dir.listFiles()) {
+           if (file.isDirectory()) {
+               return findFile(file, name);
+           }
+       }
+
+       return null;
+    }
+
+    private static void findJars (File dir, ArrayList<File> jars) {
+       for (File file : dir.listFiles()) {
+           if (file.isDirectory()) {
+               findJars(file, jars);
+           } else {
+               if(file.toString().endsWith(".jar")) {
+                   jars.add(file);
+               }
+           }
+       }
+    }
+    
     private static final String DELIM_START = "${";
     private static final String DELIM_STOP  = "}";
 

Modified: servicemix/smx4/kernel/trunk/main/src/main/resources/config.properties
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/main/src/main/resources/config.properties?rev=658391&r1=658390&r2=658391&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/main/src/main/resources/config.properties 
(original)
+++ servicemix/smx4/kernel/trunk/main/src/main/resources/config.properties Tue 
May 20 11:52:28 2008
@@ -43,6 +43,8 @@
 osgi.shell.telnet=on
 #obr.repository.url=http://bundles.osgi.org/obr/browse?_xml=1&cmd=repository
 
+#list of directories containing bundles to be loaded by SMX
+#bundle.locations=
 
 #
 # Java platform package export properties.


Reply via email to