felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r786625 - /felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java
Date Fri, 19 Jun 2009 18:53:10 GMT
Author: rickhall
Date: Fri Jun 19 18:53:10 2009
New Revision: 786625

URL: http://svn.apache.org/viewvc?rev=786625&view=rev
Log:
Applied patch (FELIX-1251) to handle when the watched directory is removed.

Modified:
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java

Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java?rev=786625&r1=786624&r2=786625&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java
(original)
+++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java
Fri Jun 19 18:53:10 2009
@@ -91,17 +91,7 @@
         }
         watchedDirectory = new File(dir);
         
-        if (!watchedDirectory.exists() && !watchedDirectory.mkdirs())
-        {
-            log("Cannot create folder " + watchedDirectory + ". Is the folder write-protected?",
null);
-            throw new RuntimeException("Cannot create folder " + watchedDirectory);
-        }
-
-        if (!this.watchedDirectory.isDirectory())
-        {
-            log("Cannot watch " + watchedDirectory + " because it's not a directory", null);
-            throw new RuntimeException("Cannot start FileInstall to watch something that
is not a directory");
-        }
+        prepareWatchedDir(watchedDirectory);
         
         Object value = properties.get(START_NEW_BUNDLES);
         if (value != null)
@@ -144,6 +134,34 @@
             }
         }
     }
+    
+    /**
+     * Create the watched directory, if not existing.
+     * Throws a runtime exception if the directory cannot be created,
+     * or if the provided File parameter does not refer to a directory.
+     * 
+     * @param watchedDirectory 
+     *            The directory File Install will monitor
+     */
+    private void prepareWatchedDir(File watchedDirectory)
+    {
+        if (!watchedDirectory.exists() && !watchedDirectory.mkdirs())
+        {
+            log("Cannot create folder "
+                + watchedDirectory
+                + ". Is the folder write-protected?", null);
+            throw new RuntimeException("Cannot create folder: " + watchedDirectory);
+        }
+
+        if (!watchedDirectory.isDirectory())
+        {
+            log("Cannot watch "
+                + watchedDirectory
+                + " because it's not a directory", null);
+            throw new RuntimeException(
+                "Cannot start FileInstall to watch something that is not a directory");
+        }
+    }
 
     /**
      * Handle the changes between the configurations already installed and the
@@ -163,7 +181,7 @@
             // with the inactive ones.
             Set inactive = new HashSet(current.keySet());
 
-            for (Iterator e = discovered.iterator(); e.hasNext();)
+            for (Iterator e = discovered.iterator(); e.hasNext(); )
             {
                 String path = (String) e.next();
                 File f = new File(path);
@@ -227,8 +245,7 @@
         {
             if (debug != 0 && !reported)
             {
-                log(
-                    "Can't find a Configuration Manager, configurations do not work",
+                log("Can't find a Configuration Manager, configurations do not work",
                     null);
                 reported = true;
             }
@@ -296,7 +313,8 @@
 	    Configuration oldConfiguration = findExistingConfiguration(pid, factoryPid);
         if (oldConfiguration != null)
         {
-            log("Updating configuration from " + pid + (factoryPid == null ? "" : "-" + factoryPid)
+ ".cfg", null);
+            log("Updating configuration from " + pid
+                + (factoryPid == null ? "" : "-" + factoryPid) + ".cfg", null);
             return oldConfiguration;
         }
         else
@@ -374,10 +392,9 @@
         start(new HashSet(startupFailures));
 
         if (startBundles
-                &&
-                (uninstalledBundles.size() > 0
-                        || updatedBundles.size() > 0
-                        || installedBundles.size() > 0))
+            && ((uninstalledBundles.size() > 0)
+                || (updatedBundles.size() > 0)
+                || (installedBundles.size() > 0)))
         {
             // Something has changed in the system, so
             // try to start all the bundles.
@@ -452,7 +469,12 @@
     void traverse(Map/* <String, Jar> */ jars, Set configs, File jardir)
     {
         String list[] = jardir.list();
-        for (int i = 0; i < list.length; i++)
+        if (list == null)
+        {
+            prepareWatchedDir(jardir);
+            list = jardir.list();
+        }
+        for (int i = 0; (list != null) && (i < list.length); i++)
         {
             File file = new File(jardir, list[i]);
             if (list[i].endsWith(".cfg"))
@@ -559,7 +581,7 @@
     {
         Bundle[] bundles = this.context.getBundles();
         String watchedDirPath = watchedDirectory.toURI().normalize().getPath();
-        for (int i = 0; i < bundles.length; ++i)
+        for (int i = 0; i < bundles.length; i++)
         {
             try
             {
@@ -630,7 +652,7 @@
 
     private void start(Collection bundles)
     {
-        for (Iterator b = bundles.iterator(); b.hasNext();)
+        for (Iterator b = bundles.iterator(); b.hasNext(); )
         {
             start((Bundle) b.next());
         }
@@ -648,7 +670,7 @@
     private Collection/* <Bundle> */ update(Collection jars)
     {
         List bundles = new ArrayList();
-        for (Iterator iter = jars.iterator(); iter.hasNext();)
+        for (Iterator iter = jars.iterator(); iter.hasNext(); )
         {
             Jar e = (Jar) iter.next();
             Jar c = (Jar) currentManagedBundles.get(e.getPath());
@@ -814,7 +836,7 @@
      */
     private void startAllBundles()
     {
-        for (Iterator jars = currentManagedBundles.values().iterator(); jars.hasNext();)
+        for (Iterator jars = currentManagedBundles.values().iterator(); jars.hasNext(); )
         {
             Jar jar = (Jar) jars.next();
             Bundle bundle = context.getBundle(jar.getBundleId());



Mime
View raw message