incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1060274 - in /sling/trunk/installer: core/src/main/java/org/apache/sling/installer/core/impl/ factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/
Date Tue, 18 Jan 2011 09:50:02 GMT
Author: cziegeler
Date: Tue Jan 18 09:50:01 2011
New Revision: 1060274

URL: http://svn.apache.org/viewvc?rev=1060274&view=rev
Log:
Fix NPEs and make service execution more robust.

Modified:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
    sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeploymentPackageInstaller.java

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java?rev=1060274&r1=1060273&r2=1060274&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java
Tue Jan 18 09:50:01 2011
@@ -167,29 +167,30 @@ public class DefaultTransformer
     private Manifest getManifest(final InputStream ins) throws IOException {
         Manifest result = null;
 
-        JarInputStream jis = null;
-        try {
-            jis = new JarInputStream(ins);
-            result= jis.getManifest();
-
-        } finally {
-
-            // close the jar stream or the inputstream, if the jar
-            // stream is set, we don't need to close the input stream
-            // since closing the jar stream closes the input stream
-            if (jis != null) {
-                try {
-                    jis.close();
-                } catch (IOException ignore) {
-                }
-            } else {
-                try {
-                    ins.close();
-                } catch (IOException ignore) {
+        if ( ins != null ) {
+            JarInputStream jis = null;
+            try {
+                jis = new JarInputStream(ins);
+                result= jis.getManifest();
+
+            } finally {
+
+                // close the jar stream or the inputstream, if the jar
+                // stream is set, we don't need to close the input stream
+                // since closing the jar stream closes the input stream
+                if (jis != null) {
+                    try {
+                        jis.close();
+                    } catch (IOException ignore) {
+                    }
+                } else {
+                    try {
+                        ins.close();
+                    } catch (IOException ignore) {
+                    }
                 }
             }
         }
-
         return result;
     }
 

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java?rev=1060274&r1=1060273&r2=1060274&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
Tue Jan 18 09:50:01 2011
@@ -164,7 +164,6 @@ public class OsgiInstallerImpl
         while (active) {
             logger.debug("Starting new cycle");
 
-            boolean sleep = true;
             this.mergeNewlyRegisteredResources();
 
             // invoke transformers
@@ -192,15 +191,12 @@ public class OsgiInstallerImpl
                         logger.debug("Notified of new resources, back to work");
                     }
                 }
-                sleep = false;
-            }
-            if ( sleep ) {
-                // Some integration tests depend on this delay, make sure to
-                // rerun/adapt them if changing this value
-                try {
-                    Thread.sleep(250);
-                } catch (final InterruptedException ignore) {}
             }
+            // Some integration tests depend on this delay, make sure to
+            // rerun/adapt them if changing this value
+            try {
+                Thread.sleep(250);
+            } catch (final InterruptedException ignore) {}
         }
     }
 
@@ -517,13 +513,17 @@ public class OsgiInstallerImpl
                 }
             };
             while (this.active && !tasks.isEmpty()) {
-                InstallTask t = null;
+                InstallTask task = null;
                 synchronized (tasks) {
-                    t = tasks.first();
-                    tasks.remove(t);
+                    task = tasks.first();
+                    tasks.remove(task);
+                }
+                logger.debug("Executing task: {}", task);
+                try {
+                    task.execute(ctx);
+                } catch (final Throwable t) {
+                    logger.error("Uncaught exception during task execution!", t);
                 }
-                logger.debug("Executing task: {}", t);
-                t.execute(ctx);
             }
             persistentList.save();
         }
@@ -558,12 +558,16 @@ public class OsgiInstallerImpl
                     if ( services[i] instanceof ResourceTransformer ) {
                         final ResourceTransformer transformer = (ResourceTransformer)services[i];
 
-                        final TransformationResult[] result = transformer.transform(resource);
-                        if ( result != null && result.length > 0 ) {
-                            this.persistentList.transform(resource, result);
-                            changed = true;
-                            index--;
-                            break;
+                        try {
+                            final TransformationResult[] result = transformer.transform(resource);
+                            if ( result != null && result.length > 0 ) {
+                                this.persistentList.transform(resource, result);
+                                changed = true;
+                                index--;
+                                break;
+                            }
+                        } catch (final Throwable t) {
+                            logger.error("Uncaught exception during resource transformation!",
t);
                         }
                     }
                 }

Modified: sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeploymentPackageInstaller.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeploymentPackageInstaller.java?rev=1060274&r1=1060273&r2=1060274&view=diff
==============================================================================
--- sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeploymentPackageInstaller.java
(original)
+++ sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeploymentPackageInstaller.java
Tue Jan 18 09:50:01 2011
@@ -91,29 +91,30 @@ public class DeploymentPackageInstaller
     private Manifest getManifest(final InputStream ins) throws IOException {
         Manifest result = null;
 
-        JarInputStream jis = null;
-        try {
-            jis = new JarInputStream(ins);
-            result= jis.getManifest();
+        if ( ins != null ) {
+            JarInputStream jis = null;
+            try {
+                jis = new JarInputStream(ins);
+                result= jis.getManifest();
 
-        } finally {
+            } finally {
 
-            // close the jar stream or the inputstream, if the jar
-            // stream is set, we don't need to close the input stream
-            // since closing the jar stream closes the input stream
-            if (jis != null) {
-                try {
-                    jis.close();
-                } catch (IOException ignore) {
-                }
-            } else {
-                try {
-                    ins.close();
-                } catch (IOException ignore) {
+                // close the jar stream or the inputstream, if the jar
+                // stream is set, we don't need to close the input stream
+                // since closing the jar stream closes the input stream
+                if (jis != null) {
+                    try {
+                        jis.close();
+                    } catch (IOException ignore) {
+                    }
+                } else {
+                    try {
+                        ins.close();
+                    } catch (IOException ignore) {
+                    }
                 }
             }
         }
-
         return result;
     }
 



Mime
View raw message