felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1347608 - in /felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin: ./ spi/
Date Thu, 07 Jun 2012 13:32:36 GMT
Author: marrs
Date: Thu Jun  7 13:32:35 2012
New Revision: 1347608

URL: http://svn.apache.org/viewvc?rev=1347608&view=rev
Log:
Various smaller improvements and fixes.

Modified:
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractDeploymentPackage.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/Command.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/CommitResourceCommand.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropResourceCommand.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ProcessResourceCommand.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartBundleCommand.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartCustomizerCommand.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StopBundleCommand.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/UpdateCommand.java

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractDeploymentPackage.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractDeploymentPackage.java?rev=1347608&r1=1347607&r2=1347608&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractDeploymentPackage.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractDeploymentPackage.java
Thu Jun  7 13:32:35 2012
@@ -41,46 +41,72 @@ import org.osgi.service.deploymentadmin.
  * deployment package data is obtained, this should be handled by extending classes.
  */
 public abstract class AbstractDeploymentPackage implements DeploymentPackage {
-    private static final String[] STRINGS = new String[] {};
-    private static final ResourceInfoImpl[] RESOURCE_INFO_IMPLS = new ResourceInfoImpl[]
{};
-    private static final BundleInfoImpl[] BUNDLE_INFO_IMPLS = new BundleInfoImpl[] {};
-    private final BundleContext m_bundleContext;
-    private final DeploymentAdminImpl m_deploymentAdmin;
-    private final DeploymentPackageManifest m_manifest;
-    private final Map m_nameToBundleInfo = new HashMap();
-    private final Map m_pathToEntry = new HashMap();
-    private final BundleInfoImpl[] m_bundleInfos;
-    private final ResourceInfoImpl[] m_resourceInfos;
-    private final String[] m_resourcePaths;
-    private final boolean m_isFixPackage;
-    private boolean m_isStale;
-    protected static final AbstractDeploymentPackage EMPTY_PACKAGE = new AbstractDeploymentPackage()
{
+    /**
+     * Represents an empty deployment package.
+     */
+    private static final class EmptyDeploymentPackage extends AbstractDeploymentPackage {
+        private static final String[] STRINGS = new String[] {};
+        private static final ResourceInfoImpl[] RESOURCE_INFO_IMPLS = new ResourceInfoImpl[]
{};
+        private static final BundleInfoImpl[] BUNDLE_INFO_IMPLS = new BundleInfoImpl[] {};
+
         public String getHeader(String header) {
             if (Constants.DEPLOYMENTPACKAGE_SYMBOLICMAME.equals(header)) { return ""; }
             else if (Constants.DEPLOYMENTPACKAGE_VERSION.equals(header)) { return Version.emptyVersion.toString();
}
             else { return null; }
         }
+
         public Bundle getBundle(String symbolicName) { return null; }
+
         public BundleInfo[] getBundleInfos() { return BUNDLE_INFO_IMPLS; }
+
         public BundleInfoImpl[] getBundleInfoImpls() { return BUNDLE_INFO_IMPLS; }
+
         public ResourceInfoImpl[] getResourceInfos() { return RESOURCE_INFO_IMPLS; }
+
         public String getName() { return ""; }
+
         public String getResourceHeader(String resource, String header) { return null; }
+
         public ServiceReference getResourceProcessor(String resource) { return null; }
+
         public String[] getResources() { return STRINGS; }
+
         public Version getVersion() { return Version.emptyVersion; }
+
         public boolean isStale() { return true; }
+
         public void uninstall() throws DeploymentException { throw new IllegalStateException("Can
not uninstall stale DeploymentPackage"); }
+
         public boolean uninstallForced() throws DeploymentException { throw new IllegalStateException("Can
not uninstall stale DeploymentPackage"); }
+
         public InputStream getBundleStream(String symbolicName) throws IOException { return
null; }
+
         public BundleInfoImpl[] getOrderedBundleInfos() { return BUNDLE_INFO_IMPLS; }
+
         public ResourceInfoImpl[] getOrderedResourceInfos() { return RESOURCE_INFO_IMPLS;
}
+
         public InputStream getCurrentEntryStream() { throw new UnsupportedOperationException();
}
+
         public AbstractInfo getNextEntry() throws IOException { throw new UnsupportedOperationException();
}
+
         public String getDisplayName() { return ""; }
+
         public URL getIcon() { return null; }
-    };
+    }
+
+    protected static final AbstractDeploymentPackage EMPTY_PACKAGE = new EmptyDeploymentPackage();
 
+    private final BundleContext m_bundleContext;
+    private final DeploymentAdminImpl m_deploymentAdmin;
+    private final DeploymentPackageManifest m_manifest;
+    private final Map m_nameToBundleInfo = new HashMap();
+    private final Map m_pathToEntry = new HashMap();
+    private final BundleInfoImpl[] m_bundleInfos;
+    private final ResourceInfoImpl[] m_resourceInfos;
+    private final String[] m_resourcePaths;
+    private final boolean m_isFixPackage;
+    private boolean m_isStale;
+    
     /* Constructor only for use by the emptyPackage static variable */
     private AbstractDeploymentPackage() {
         m_bundleContext = null;
@@ -215,7 +241,6 @@ public abstract class AbstractDeployment
                     else {
                     	return null;
                     }
-                    
                 }
                 catch (InvalidSyntaxException e) {
                 	// TODO: log this

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java?rev=1347608&r1=1347607&r2=1347608&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java
Thu Jun  7 13:32:35 2012
@@ -68,7 +68,7 @@ public class DeploymentAdminImpl impleme
     private volatile PackageAdmin m_packageAdmin;   /* will be injected by dependencymanager
*/
     private volatile EventAdmin m_eventAdmin;       /* will be injected by dependencymanager
*/
     private volatile LogService m_log;              /* will be injected by dependencymanager
*/
-    private DeploymentSessionImpl m_session = null;
+    private volatile DeploymentSessionImpl m_session = null;
     private final Map m_packages = new HashMap();
     private final List m_commandChain = new ArrayList();
     private final Semaphore m_semaphore = new Semaphore();
@@ -121,8 +121,9 @@ public class DeploymentAdminImpl impleme
     }
 
     public boolean cancel() {
-        if (m_session != null) {
-            m_session.cancel();
+        DeploymentSessionImpl session = m_session;
+        if (session != null) {
+            session.cancel();
             return true;
         }
         return false;

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/Command.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/Command.java?rev=1347608&r1=1347607&r2=1347608&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/Command.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/Command.java
Thu Jun  7 13:32:35 2012
@@ -48,9 +48,11 @@ public abstract class Command {
      * Rolls back all actions that were added through the <code>addRollback(Runnable
r)</code> method (in reverse
      * adding order). It is not guaranteed that the state of everything related to the command
will be as if the
      * command was never executed, a best effort should be made though.
+     * 
+     * @param session the deployment session to rollback, should be used for logging purposes.
      */
-    public void rollback() {
-        for (ListIterator i = m_rollback.listIterator(m_commit.size()); i.hasPrevious();)
{
+    protected void rollback(DeploymentSessionImpl session) {
+        for (ListIterator i = m_rollback.listIterator(m_rollback.size()); i.hasPrevious();)
{
             Runnable runnable = (Runnable) i.previous();
             runnable.run();
         }
@@ -59,8 +61,10 @@ public abstract class Command {
 
     /**
      * Commits all changes the command may have defined when it was executed by calling the
<code>execute()</code> method.
+     * 
+     * @param session the deployment session to commit, should be used for logging purposes.
      */
-    protected void commit() {
+    protected void commit(DeploymentSessionImpl session) {
         for (ListIterator i = m_commit.listIterator(); i.hasNext();) {
             Runnable runnable = (Runnable) i.next();
             runnable.run();
@@ -110,5 +114,4 @@ public abstract class Command {
     public void cancel() {
         m_cancelled = true;
     }
-
 }

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/CommitResourceCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/CommitResourceCommand.java?rev=1347608&r1=1347607&r2=1347608&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/CommitResourceCommand.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/CommitResourceCommand.java
Thu Jun  7 13:32:35 2012
@@ -31,7 +31,7 @@ import org.osgi.service.log.LogService;
 /**
  * Command that commits all the resource processors that were added to the command.
  */
-public class CommitResourceCommand extends Command implements Runnable {
+public class CommitResourceCommand extends Command {
 
     private final List m_processors = new ArrayList();
 
@@ -52,23 +52,25 @@ public class CommitResourceCommand exten
                 processor.commit();
             }
             catch (Exception e) {
+                // We cannot throw an exception, see OSGi spec.
                 session.getLog().log(LogService.LOG_ERROR, "Committing resource processor
'" + processor + "' failed", e);
-                // TODO Throw exception?
             }
         }
         m_processors.clear();
     }
 
-    public void rollback() {
+    protected void rollback(DeploymentSessionImpl session) {
         for (ListIterator i = m_processors.listIterator(m_processors.size()); i.hasPrevious();)
{
             ResourceProcessor processor = (ResourceProcessor) i.previous();
             try {
                 processor.rollback();
             }
             catch (Exception e) {
-                // TODO Log this?
+                // We cannot throw an exception, see OSGi spec.
+                session.getLog().log(LogService.LOG_ERROR, "Rollback of resource processor
'" + processor + "' failed", e);
+            } finally {
+                i.remove();
             }
-            i.remove();
         }
     }
 
@@ -88,9 +90,4 @@ public class CommitResourceCommand exten
         m_processors.add(processor);
         return true;
     }
-
-    public void run() {
-        rollback();
-    }
-
 }

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java?rev=1347608&r1=1347607&r2=1347608&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java
Thu Jun  7 13:32:35 2012
@@ -79,7 +79,7 @@ public class DeploymentSessionImpl imple
             }
         }
         for (Iterator i = m_commands.iterator(); i.hasNext();) {
-            ((Command) i.next()).commit();
+            ((Command) i.next()).commit(this);
         }
         m_currentCommand = null;
     }
@@ -87,7 +87,7 @@ public class DeploymentSessionImpl imple
     private void rollback(List executedCommands) {
         for (ListIterator i = executedCommands.listIterator(executedCommands.size()); i.hasPrevious();)
{
             Command command = (Command) i.previous();
-            command.rollback();
+            command.rollback(this);
         }
     }
 
@@ -98,10 +98,13 @@ public class DeploymentSessionImpl imple
      */
     public boolean cancel() {
         m_cancelled = true;
-        if (m_currentCommand != null) {
-            m_currentCommand.cancel();
+
+        Command currentCommand = m_currentCommand;
+        if (currentCommand != null) {
+            currentCommand.cancel();
             return true;
         }
+
         return false;
     }
 

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropResourceCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropResourceCommand.java?rev=1347608&r1=1347607&r2=1347608&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropResourceCommand.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropResourceCommand.java
Thu Jun  7 13:32:35 2012
@@ -41,10 +41,12 @@ public class DropResourceCommand extends
      */
     public DropResourceCommand(CommitResourceCommand commitCommand) {
         m_commitCommand = commitCommand;
-        addRollback(m_commitCommand);
     }
 
     public void execute(DeploymentSessionImpl session) {
+        // Allow proper rollback in case the drop fails...
+        addRollback(new RollbackCommitAction(session));
+        
         AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
         AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
         BundleContext context = session.getBundleContext();
@@ -73,4 +75,16 @@ public class DropResourceCommand extends
             }
         }
     }
+    
+    private class RollbackCommitAction implements Runnable {
+        private final DeploymentSessionImpl m_session; 
+        
+        public RollbackCommitAction(DeploymentSessionImpl session) {
+            m_session = session;
+        }
+        
+        public void run() {
+            m_commitCommand.rollback(m_session);
+        }
+    }
 }

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ProcessResourceCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ProcessResourceCommand.java?rev=1347608&r1=1347607&r2=1347608&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ProcessResourceCommand.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ProcessResourceCommand.java
Thu Jun  7 13:32:35 2012
@@ -52,10 +52,12 @@ public class ProcessResourceCommand exte
      */
     public ProcessResourceCommand(CommitResourceCommand commitCommand) {
         m_commitCommand = commitCommand;
-        addRollback(m_commitCommand);
     }
 
     public void execute(DeploymentSessionImpl session) throws DeploymentException {
+        // Allow proper rollback in case the drop fails...
+        addRollback(new RollbackCommitAction(session));
+
         AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
         BundleContext context = session.getBundleContext();
 
@@ -69,6 +71,8 @@ public class ProcessResourceCommand exte
         }
 
         try {
+            String allowForeignCustomerizers = System.getProperty("org.apache.felix.deploymentadmin.allowforeigncustomizers",
"false");
+
         	while (!expectedResources.isEmpty()) {
             	AbstractInfo jarEntry = source.getNextEntry();
             	if (jarEntry == null) {
@@ -85,8 +89,7 @@ public class ProcessResourceCommand exte
                 ServiceReference ref = source.getResourceProcessor(name);
                 if (ref != null) {
                     String serviceOwnerSymName = ref.getBundle().getSymbolicName();
-                    String allowForeignCustomerizers = System.getProperty("org.apache.felix.deploymentadmin.allowforeigncustomizers",
"false");
-                    if (source.getBundleInfoByName(serviceOwnerSymName) != null || allowForeignCustomerizers.equals("true"))
{
+                    if (source.getBundleInfoByName(serviceOwnerSymName) != null || "true".equals(allowForeignCustomerizers))
{
                         ResourceProcessor resourceProcessor = (ResourceProcessor) context.getService(ref);
                         if (resourceProcessor != null) {
                             try {
@@ -121,5 +124,16 @@ public class ProcessResourceCommand exte
             throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Problem
while reading stream", e);
         }
     }
-
+    
+    private class RollbackCommitAction implements Runnable {
+        private final DeploymentSessionImpl m_session; 
+        
+        public RollbackCommitAction(DeploymentSessionImpl session) {
+            m_session = session;
+        }
+        
+        public void run() {
+            m_commitCommand.rollback(m_session);
+        }
+    }
 }

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java?rev=1347608&r1=1347607&r2=1347608&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
Thu Jun  7 13:32:35 2012
@@ -64,8 +64,8 @@ public class SnapshotCommand extends Com
                     try {
                         snapshot.createNewFile();
                         store(root, snapshot);
-                        addRollback(new RestoreSnapshotRunnable(snapshot, root));
-                        addCommit(new DeleteSnapshotRunnable(snapshot));
+                        addRollback(new RestoreSnapshotRunnable(session, snapshot, root));
+                        addCommit(new DeleteSnapshotRunnable(session, snapshot));
                     }
                     catch (IOException e) {
                         snapshot.delete();
@@ -77,18 +77,6 @@ public class SnapshotCommand extends Com
         }
     }
 
-    private void delete(File root, boolean deleteRoot) {
-        if (root.isDirectory()) {
-            File[] childs = root.listFiles();
-            for (int i = 0; i < childs.length; i++) {
-                delete(childs[i], true);
-            }
-        }
-        if (deleteRoot) {
-            root.delete();
-        }
-    }
-
     private void store(File source, File target) throws IOException {
         ZipOutputStream output = null;
         try {
@@ -142,68 +130,29 @@ public class SnapshotCommand extends Com
         }
     }
 
-    private void unpack(File source, File target) throws IOException {
-        ZipInputStream input = null;
-        try {
-            input = new ZipInputStream(new FileInputStream(source));
-            for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry())
{
-                if (entry.isDirectory()) {
-                    (new File(target, entry.getName())).mkdirs();
-                }
-                else {
-                    OutputStream output = null;
-                    try {
-                        output = new FileOutputStream(target);
-                        byte[] buffer = new byte[4096];
-                        for (int i = input.read(buffer); i > -1; i = input.read(buffer))
{
-                            output.write(buffer, 0, i);
-                        }
-                    }
-                    finally {
-                        if (output != null) {
-                            try {
-                                output.close();
-                            }
-                            catch (Exception ex) {
-                                // Not much we can do
-                            }
-                        }
-                    }
-                }
-                input.closeEntry();
-            }
-        }
-        finally {
-            if (input != null) {
-                try {
-                    input.close();
-                }
-                catch (Exception ex) {
-                    // Not much we can do
-                }
-            }
-        }
-    }
-
-    class DeleteSnapshotRunnable implements Runnable {
-
+    private static class DeleteSnapshotRunnable implements Runnable {
+        private final DeploymentSessionImpl m_session;
         private final File m_snapshot;
 
-        private DeleteSnapshotRunnable(File snapshot) {
+        private DeleteSnapshotRunnable(DeploymentSessionImpl session, File snapshot) {
+            m_session = session;
             m_snapshot = snapshot;
         }
 
         public void run() {
-            m_snapshot.delete();
+            if (!m_snapshot.delete()) {
+                m_session.getLog().log(LogService.LOG_WARNING, "Failed to delete snapshot
in " + m_snapshot + "!");
+            }
         }
     }
 
-    private class RestoreSnapshotRunnable implements Runnable {
-
+    private static class RestoreSnapshotRunnable implements Runnable {
+        private final DeploymentSessionImpl m_session;
         private final File m_snapshot;
         private final File m_root;
 
-        private RestoreSnapshotRunnable(File snapshot, File root) {
+        private RestoreSnapshotRunnable(DeploymentSessionImpl session, File snapshot, File
root) {
+            m_session = session;
             m_snapshot = snapshot;
             m_root = root;
         }
@@ -214,11 +163,66 @@ public class SnapshotCommand extends Com
                 unpack(m_snapshot, m_root);
             }
             catch (Exception ex) {
-                // TODO: log this
+                m_session.getLog().log(LogService.LOG_WARNING, "Failed to restore snapshot!",
ex);
             }
             finally {
                 m_snapshot.delete();
             }
         }
-    }
+
+        private void delete(File root, boolean deleteRoot) {
+            if (root.isDirectory()) {
+                File[] childs = root.listFiles();
+                for (int i = 0; i < childs.length; i++) {
+                    delete(childs[i], true);
+                }
+            }
+            if (deleteRoot) {
+                root.delete();
+            }
+        }
+
+        private void unpack(File source, File target) throws IOException {
+            ZipInputStream input = null;
+            try {
+                input = new ZipInputStream(new FileInputStream(source));
+                for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry())
{
+                    if (entry.isDirectory()) {
+                        (new File(target, entry.getName())).mkdirs();
+                    }
+                    else {
+                        OutputStream output = null;
+                        try {
+                            output = new FileOutputStream(target);
+                            byte[] buffer = new byte[4096];
+                            for (int i = input.read(buffer); i > -1; i = input.read(buffer))
{
+                                output.write(buffer, 0, i);
+                            }
+                        }
+                        finally {
+                            if (output != null) {
+                                try {
+                                    output.close();
+                                }
+                                catch (Exception ex) {
+                                    // Not much we can do
+                                }
+                            }
+                        }
+                    }
+                    input.closeEntry();
+                }
+            }
+            finally {
+                if (input != null) {
+                    try {
+                        input.close();
+                    }
+                    catch (Exception ex) {
+                        // Not much we can do
+                    }
+                }
+            }
+        }
+   }
 }
\ No newline at end of file

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartBundleCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartBundleCommand.java?rev=1347608&r1=1347607&r2=1347608&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartBundleCommand.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartBundleCommand.java
Thu Jun  7 13:32:35 2012
@@ -32,7 +32,6 @@ import org.osgi.service.packageadmin.Pac
  */
 public class StartBundleCommand extends Command {
     private final RefreshPackagesMonitor m_refreshMonitor = new RefreshPackagesMonitor();
-    private static final int REFRESH_TIMEOUT = 10000;
 
     public void execute(DeploymentSessionImpl session) {
         AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
@@ -81,8 +80,10 @@ public class StartBundleCommand extends 
     /**
      * Use this monitor when its desired to wait for the completion of the asynchronous PackageAdmin.refreshPackages()
call.
      */
-    private class RefreshPackagesMonitor {
-        private boolean m_alreadyNotified = false;
+    private static class RefreshPackagesMonitor {
+        private static final int REFRESH_TIMEOUT = 10000;
+
+        private volatile boolean m_alreadyNotified = false;
 
         /**
          * Waits for the completion of the PackageAdmin.refreshPackages() call. Because

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartCustomizerCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartCustomizerCommand.java?rev=1347608&r1=1347607&r2=1347608&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartCustomizerCommand.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartCustomizerCommand.java
Thu Jun  7 13:32:35 2012
@@ -27,6 +27,7 @@ import org.apache.felix.deploymentadmin.
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
 import org.osgi.service.deploymentadmin.DeploymentException;
+import org.osgi.service.log.LogService;
 
 /**
  * Command that starts all customizer bundles defined in the source deployment packages of
a deployment
@@ -38,11 +39,13 @@ public class StartCustomizerCommand exte
     public void execute(DeploymentSessionImpl session) throws DeploymentException {
         AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
         AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
+
         Set bundles = new HashSet();
         Set sourceBundlePaths = new HashSet();
+
         BundleInfoImpl[] targetInfos = target.getBundleInfoImpls();
         BundleInfoImpl[] sourceInfos = source.getBundleInfoImpls();
-        for(int i = 0; i < sourceInfos.length; i++) {
+        for (int i = 0; i < sourceInfos.length; i++) {
             if (sourceInfos[i].isCustomizer()) {
                 sourceBundlePaths.add(sourceInfos[i].getPath());
                 Bundle bundle = source.getBundle(sourceInfos[i].getSymbolicName());
@@ -51,7 +54,8 @@ public class StartCustomizerCommand exte
                 }
             }
         }
-        for(int i = 0; i < targetInfos.length; i++) {
+
+        for (int i = 0; i < targetInfos.length; i++) {
             if (targetInfos[i].isCustomizer() && !sourceBundlePaths.contains(targetInfos[i].getPath()))
{
                 Bundle bundle = target.getBundle(targetInfos[i].getSymbolicName());
                 if (bundle != null) {
@@ -59,7 +63,8 @@ public class StartCustomizerCommand exte
                 }
             }
         }
-        for(Iterator i = bundles.iterator(); i.hasNext(); ) {
+
+        for (Iterator i = bundles.iterator(); i.hasNext();) {
             Bundle bundle = (Bundle) i.next();
             try {
                 bundle.start();
@@ -67,15 +72,16 @@ public class StartCustomizerCommand exte
             catch (BundleException be) {
                 throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Could
not start customizer bundle '" + bundle.getSymbolicName() + "'", be);
             }
-            addRollback(new StopCustomizerRunnable(bundle));
+            addRollback(new StopCustomizerRunnable(session, bundle));
         }
     }
 
     private static class StopCustomizerRunnable implements Runnable {
-
+        private final DeploymentSessionImpl m_session;
         private final Bundle m_bundle;
 
-        public StopCustomizerRunnable(Bundle bundle) {
+        public StopCustomizerRunnable(DeploymentSessionImpl session, Bundle bundle) {
+            m_session = session;
             m_bundle = bundle;
         }
 
@@ -84,10 +90,8 @@ public class StartCustomizerCommand exte
                 m_bundle.stop();
             }
             catch (BundleException e) {
-                // TODO log this
-                e.printStackTrace();
+                m_session.getLog().log(LogService.LOG_WARNING, "Failed to stop bundle '"
+ m_bundle.getSymbolicName() + "'", e);
             }
         }
-
     }
 }

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StopBundleCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StopBundleCommand.java?rev=1347608&r1=1347607&r2=1347608&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StopBundleCommand.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StopBundleCommand.java
Thu Jun  7 13:32:35 2012
@@ -38,6 +38,8 @@ import org.osgi.service.log.LogService;
 public class StopBundleCommand extends Command {
 
     public void execute(DeploymentSessionImpl session) throws DeploymentException {
+        String stopUnaffectedBundle = System.getProperty("org.apache.felix.deploymentadmin.stopunaffectedbundle",
"true");
+        
         AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
         BundleInfo[] bundleInfos = target.getOrderedBundleInfos();
         for (int i = 0; i < bundleInfos.length; i++) {
@@ -47,11 +49,10 @@ public class StopBundleCommand extends C
             String symbolicName = bundleInfos[i].getSymbolicName();
 			Bundle bundle = target.getBundle(symbolicName);
             if (bundle != null) {
-            	String stopUnaffectedBundle = System.getProperty("org.apache.felix.deploymentadmin.stopunaffectedbundle",
"true");
-        		if (stopUnaffectedBundle.equalsIgnoreCase("false") && omitBundleStop(session,
symbolicName)) {
+        		if ("false".equalsIgnoreCase(stopUnaffectedBundle) && omitBundleStop(session,
symbolicName)) {
         			continue;
         		}
-                addRollback(new StartBundleRunnable(bundle));
+                addRollback(new StartBundleRunnable(session, bundle));
                 try {
                     bundle.stop();
                 }
@@ -87,11 +88,12 @@ public class StopBundleCommand extends C
 		return result;
 	}
 
-	private class StartBundleRunnable implements Runnable {
-
+	private static class StartBundleRunnable implements Runnable {
+        private final DeploymentSessionImpl m_session;
         private final Bundle m_bundle;
 
-        public StartBundleRunnable(Bundle bundle) {
+        public StartBundleRunnable(DeploymentSessionImpl session, Bundle bundle) {
+            m_session = session;
             m_bundle = bundle;
         }
 
@@ -100,11 +102,9 @@ public class StopBundleCommand extends C
                 m_bundle.start();
             }
             catch (BundleException e) {
-                // TODO: log this
-                e.printStackTrace();
+                m_session.getLog().log(LogService.LOG_WARNING, "Failed to start bundle '"
+ m_bundle.getSymbolicName() + "'", e);
             }
         }
-
     }
 }
 

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/UpdateCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/UpdateCommand.java?rev=1347608&r1=1347607&r2=1347608&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/UpdateCommand.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/UpdateCommand.java
Thu Jun  7 13:32:35 2012
@@ -51,7 +51,7 @@ public class UpdateCommand extends Comma
         AbstractInfo[] bundleInfos = (AbstractInfo[]) source.getBundleInfos();
         for (int i = 0; i < bundleInfos.length; i++) {
             AbstractInfo bundleInfo = bundleInfos[i];
-            if(!bundleInfo.isMissing()) {
+            if (!bundleInfo.isMissing()) {
                 expectedBundles.put(bundleInfo.getPath(), bundleInfo);
             }
         }
@@ -91,7 +91,7 @@ public class UpdateCommand extends Comma
                     }
                     throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Could
not install new bundle '" + name + "'", be);
                 }
-                if (!bundle.getSymbolicName().equals(bundleInfo.getSymbolicName()) || !Version.parseVersion((String)bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION)).equals(bundleInfo.getVersion()))
{
+                if (!bundle.getSymbolicName().equals(bundleInfo.getSymbolicName()) || !Version.parseVersion((String)
bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION)).equals(bundleInfo.getVersion()))
{
                     throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Installed/updated
bundle version and/or symbolicnames do not match what was installed/updated");
                 }
             }
@@ -102,7 +102,6 @@ public class UpdateCommand extends Comma
     }
 
     private static class UninstallBundleRunnable implements Runnable {
-
         private final Bundle m_bundle;
         private final LogService m_log;
 
@@ -122,7 +121,6 @@ public class UpdateCommand extends Comma
     }
 
     private static class UpdateBundleRunnable implements Runnable {
-
         private final AbstractDeploymentPackage m_targetPackage;
         private final Bundle m_bundle;
         private final LogService m_log;
@@ -137,15 +135,16 @@ public class UpdateCommand extends Comma
             InputStream is = null;
             try {
                 is = m_targetPackage.getBundleStream(m_bundle.getSymbolicName());
-                if(is != null){
-                    m_bundle.update(is);                    
+                if (is != null) {
+                    m_bundle.update(is);
                 }
                 throw new Exception("Unable to get Inputstream for bundle " + m_bundle.getSymbolicName());
             }
             catch (Exception e) {
                 m_log.log(LogService.LOG_WARNING, "Could not rollback update of bundle '"
+ m_bundle.getSymbolicName() + "'", e);
-            } finally {
-                if(is != null){
+            }
+            finally {
+                if (is != null) {
                     try {
                         is.close();
                     }
@@ -185,5 +184,4 @@ public class UpdateCommand extends Comma
             }
         }
     }
-
 }



Mime
View raw message