geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1409392 - in /geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core: DeploymentUtils.java FilteredClassResourceDelta.java GeronimoServerBehaviourDelegate.java
Date Wed, 14 Nov 2012 20:58:04 GMT
Author: gawor
Date: Wed Nov 14 20:58:04 2012
New Revision: 1409392

URL: http://svn.apache.org/viewvc?rev=1409392&view=rev
Log:
GERONIMODEVTOOLS-807: Handle updates to static and class files at the same time for OSGi applications

Added:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/FilteredClassResourceDelta.java
  (with props)
Modified:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DeploymentUtils.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DeploymentUtils.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DeploymentUtils.java?rev=1409392&r1=1409391&r2=1409392&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DeploymentUtils.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DeploymentUtils.java
Wed Nov 14 20:58:04 2012
@@ -573,6 +573,29 @@ public class DeploymentUtils {
         return true;
     }
     
+    
+    /**
+     * Returns true only if the delta contains at least one CHANGED class resource. 
+     */
+    public static boolean containsChangedClassResources(IModuleResourceDelta[] deltaArray)
{
+        for (IModuleResourceDelta delta : deltaArray) {
+            int kind = delta.getKind();                    
+            IModuleResource resource = delta.getModuleResource();
+            if (resource instanceof IModuleFile) {
+                String name = resource.getName();
+                if (name.endsWith(".class") && kind == IModuleResourceDelta.CHANGED)
{
+                    return true;
+                }
+            } else if (resource instanceof IModuleFolder) {
+                IModuleResourceDelta[] childDeltaArray = delta.getAffectedChildren();
+                if (containsChangedClassResources(childDeltaArray)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
     public static File createChangeSetFile(IModuleResource[] resources) {
         Trace.tracePoint("Entry", Activator.traceCore, "DeploymentUtils.createChangeSetFile",
resources);
         

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/FilteredClassResourceDelta.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/FilteredClassResourceDelta.java?rev=1409392&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/FilteredClassResourceDelta.java
(added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/FilteredClassResourceDelta.java
Wed Nov 14 20:58:04 2012
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.st.v30.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.wst.server.core.model.IModuleFile;
+import org.eclipse.wst.server.core.model.IModuleResource;
+import org.eclipse.wst.server.core.model.IModuleResourceDelta;
+
+public class FilteredClassResourceDelta implements IModuleResourceDelta {
+    
+    private final IModuleResourceDelta delta;
+    private final boolean includeModifiedClasses;
+    private IModuleResourceDelta[] children;
+
+    public FilteredClassResourceDelta(IModuleResourceDelta delta, boolean includeModifiedClasses)
{
+        this.delta = delta;
+        this.includeModifiedClasses = includeModifiedClasses;
+    }
+
+    @Override
+    public IModuleResourceDelta[] getAffectedChildren() {
+        if (children == null) {
+            if (includeModifiedClasses) {
+                children = filterIn(delta.getAffectedChildren());
+            } else {
+                children = filterOut(delta.getAffectedChildren());
+            }
+        }
+        return children;
+    }
+
+    private static IModuleResourceDelta[] filterOut(IModuleResourceDelta[] deltaArray) {
+        if (deltaArray == null) {
+            return null;
+        }
+        List<IModuleResourceDelta> deltaList = new ArrayList<IModuleResourceDelta>();
+        for (IModuleResourceDelta delta : deltaArray) {
+            IModuleResource resource = delta.getModuleResource();
+            int kind = delta.getKind();
+            if (resource instanceof IModuleFile) {
+                // file
+                if (kind == IModuleResourceDelta.CHANGED && resource.getName().endsWith(".class"))
{
+                    // filter out changed .class file
+                } else {
+                    deltaList.add(delta);
+                }
+            } else {
+                // directory
+                deltaList.add(new FilteredClassResourceDelta(delta, false));
+            }
+        }
+        return deltaList.toArray(new IModuleResourceDelta[deltaList.size()]);
+    }
+
+    
+    private static IModuleResourceDelta[] filterIn(IModuleResourceDelta[] deltaArray) {
+        if (deltaArray == null) {
+            return null;
+        }
+        List<IModuleResourceDelta> deltaList = new ArrayList<IModuleResourceDelta>();
+        for (IModuleResourceDelta delta : deltaArray) {
+            IModuleResource resource = delta.getModuleResource();
+            int kind = delta.getKind();
+            if (resource instanceof IModuleFile) {
+                // file
+                if (kind == IModuleResourceDelta.CHANGED && resource.getName().endsWith(".class"))
{
+                    // filter in changed .class file only
+                    deltaList.add(delta);
+                }
+            } else {
+                // directory
+                if (kind == IModuleResourceDelta.NO_CHANGE || kind == IModuleResourceDelta.CHANGED)
{
+                    // filter in changed or non-changed directories
+                    deltaList.add(new FilteredClassResourceDelta(delta, true));
+                }
+            }
+        }
+        return deltaList.toArray(new IModuleResourceDelta[deltaList.size()]);
+    }
+
+    @Override
+    public int getKind() {
+        return delta.getKind();
+    }
+
+    @Override
+    public IPath getModuleRelativePath() {
+        return delta.getModuleRelativePath();
+    }
+
+    @Override
+    public IModuleResource getModuleResource() {
+        return delta.getModuleResource();
+    }    
+    
+    public static IModuleResourceDelta[] getChangedClassIncludeDelta(IModuleResourceDelta[]
deltaArray) {
+        return filterIn(deltaArray);
+    }
+    
+    public static IModuleResourceDelta[] getChangedClassExcludeDelta(IModuleResourceDelta[]
deltaArray) {
+        return filterOut(deltaArray);
+    }
+    
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/FilteredClassResourceDelta.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/FilteredClassResourceDelta.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/FilteredClassResourceDelta.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java?rev=1409392&r1=1409391&r2=1409392&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java
Wed Nov 14 20:58:04 2012
@@ -17,7 +17,6 @@
 package org.apache.geronimo.st.v30.core;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -382,7 +381,7 @@ public class GeronimoServerBehaviourDele
      * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#publishModules(int,
java.util.List, java.util.List, org.eclipse.core.runtime.MultiStatus, org.eclipse.core.runtime.IProgressMonitor)
      */
     protected void publishModules(int kind, List modules, List deltaKind, MultiStatus multi,
IProgressMonitor monitor) {
-        Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.publishModules",
publishKindToString(kind), Arrays.asList(modules), Arrays.asList(deltaKind), multi, monitor);
+        Trace.traceEntry(Activator.traceCore, "GeronimoServerBehaviourDelegate.publishModules",
publishKindToString(kind), Arrays.asList(modules), Arrays.asList(deltaKind), multi, monitor);
 
         // 
         // WTP publishes modules in reverse alphabetical order which does not account for
possible 
@@ -447,119 +446,206 @@ public class GeronimoServerBehaviourDele
             resetSourceLookupList();
         }
         
-        if(status.isOK()) {
-            if (modules == null)
+        if (status.isOK()) {
+            if (modules == null || modules.isEmpty()) {
                 return;
+            }
             
-            int size = modules.size();
-            if (size == 0)
+            if (monitor.isCanceled()) {
                 return;
+            }
             
-            if (monitor.isCanceled())
-                return;
+            for (ModuleDeltaList moduleList : publishMap.values()) {  
+                IModule[] rootModule = moduleList.getRootModule();
+                if (GeronimoUtils.isEBAModule(rootModule[0])) {
+                    publishEBAModule(kind, multi, monitor, moduleList);      
+                } else if (GeronimoUtils.isEarModule(rootModule[0])) {
+                    publishEARModule(kind, multi, monitor, moduleList);   
+                } else if (GeronimoUtils.isWebModule(rootModule[0]) || GeronimoUtils.isBundleModule(rootModule[0]))
{
+                    publishSingleModule(kind, multi, monitor, moduleList);
+                } else {
+                    publishEntireModule(kind, multi, monitor, moduleList);
+                }
+            }
             
-            // phase 1: see if the modified contents can copied/replaced 
-            if (getServerDelegate().isNoRedeploy() && !isRemote()) {
-                Iterator<ModuleDeltaList> iterator = publishMap.values().iterator();
-                while (iterator.hasNext()) {
-                    ModuleDeltaList moduleList = iterator.next();
-                    IModule[] rootModule = moduleList.getRootModule();
-                    if (GeronimoUtils.isEBAModule(rootModule[0]) || GeronimoUtils.isEarModule(rootModule[0]))
{
-                        if (moduleList.hasChangedChildModulesOnly(true)) {
-                            boolean replacementPossible = true;
-                            Map<IModule[], IStatus> statusMap = new HashMap<IModule[],
IStatus>();   
-                            
-                            for (ModuleDelta moduleDelta : moduleList.getChildModules())
{
-                                IModule bundleModule = moduleDelta.module[1];
-                                if (moduleDelta.delta == CHANGED && (GeronimoUtils.isWebModule(bundleModule)
|| GeronimoUtils.isBundleModule(bundleModule))) {
-                                    // try to do replacement
-                                    status = tryFileReplace(moduleDelta.module);
-                                    if (status == null) {
-                                        // replacement was not possible
-                                        replacementPossible = false;
-                                        break;
-                                    } else {
-                                        statusMap.put(moduleDelta.module, status);
-                                    }
-                                } else {
-                                    statusMap.put(moduleDelta.module, Status.OK_STATUS);
-                                }
-                            }
-                            
-                            if (replacementPossible) {
-                                // replacement was possible for all changed child modules
- remove it from publish list
-                                iterator.remove();
-                                
-                                statusMap.put(rootModule, Status.OK_STATUS);
-                                for (Map.Entry<IModule[], IStatus> entry : statusMap.entrySet())
{
-                                    setStatus(entry.getKey(), entry.getValue(), multi);
-                                }
-                            } else {
-                                // replacement was not possible for at least one child module
- redeploy the module
-                            }                            
-                        }
-                    } else if (GeronimoUtils.isWebModule(rootModule[0]) || GeronimoUtils.isBundleModule(rootModule[0]))
{
-                        if (moduleList.getEffectiveRootDelta() == CHANGED) {
-                            // contents changed - try to do replacement
-                            status = tryFileReplace(rootModule);
-                            if (status != null) {
-                                // replacement was possible - remove it from publish list
-                                iterator.remove();
+        } else {
+            multi.add(status);
+        }
 
-                                setStatus(rootModule, status, multi);
+        Trace.traceExit(Activator.traceCore, "GeronimoServerBehaviourDelegate.publishModules");
+    }
+
+    private void publishEBAModule(int kind, MultiStatus multi, IProgressMonitor monitor,
ModuleDeltaList moduleList) {
+        Trace.traceEntry(Activator.traceCore, "GeronimoServerBehaviourDelegate.publishEBAModule",
Arrays.toString(moduleList.getRootModule()));
+        
+        Map<IModule[], IStatus> statusMap = new HashMap<IModule[], IStatus>();
+        
+        if (getServerDelegate().isNoRedeploy() && !isRemote()) {            
+            if (moduleList.hasChangedChildModulesOnly(true)) {    
+                List<ModuleInfo> childModules = moduleList.getChildModules();
+                for (ModuleInfo module : childModules) {
+                    if (module.delta == CHANGED) {
+                        // changed module - try to do replacement
+                        IModuleResourceDelta[] delta = getPublishedResourceDelta(module.module);
+                        IModuleResourceDelta[] nonClassDelta = FilteredClassResourceDelta.getChangedClassExcludeDelta(delta);
+                        if (Activator.getDefault().isDebugging()) {
+                            Trace.trace(Trace.INFO, "Non-modified class delta for " + module,
Activator.traceCore);
+                            traceModuleResourceDelta(nonClassDelta, "  ");
+                        }
+                        IStatus status = tryFileReplace(module.module, nonClassDelta);
+                        if (status == null) {
+                            // replace not performed - must redeploy bundle or entire application
+                        } else if (status.isOK()) {
+                            boolean containsModifiedClasses = DeploymentUtils.containsChangedClassResources(delta);
+                            if (containsModifiedClasses) {
+                                // replace performed but we have modified classes to deploy
+                                // set remaining resource delta to process
+                                IModuleResourceDelta[] classDelta = FilteredClassResourceDelta.getChangedClassIncludeDelta(delta);
+                                if (Activator.getDefault().isDebugging()) {
+                                    Trace.trace(Trace.INFO, "Modified class delta for " +
module, Activator.traceCore);
+                                    traceModuleResourceDelta(classDelta, "  ");
+                                }
+                                module.resourceDelta = classDelta;
                             } else {
-                                // replacement was not possible - redeploy the module
+                                // replace performed and was successful                 
  
+                                statusMap.put(module.module, status);
                             }
+                        } else {        
+                            // replace performed but failed
+                            statusMap.put(module.module, status);
                         }
-                    }                                          
+                    } else {
+                        // non-changed module
+                        statusMap.put(module.module, Status.OK_STATUS);
+                    }
                 }
-            }   
-                    
-            // phase 2: re-deploy the modules
-            boolean refreshOSGiBundle = getServerDelegate().isRefreshOSGiBundle();
-            for (ModuleDeltaList moduleList : publishMap.values()) {  
-                IModule[] rootModule = moduleList.getRootModule();
-                AbstractName ebaName = null;
-                if (refreshOSGiBundle &&
-                    GeronimoUtils.isEBAModule(rootModule[0]) &&  
-                    moduleList.hasChangedChildModulesOnly(false) && 
-                    (ebaName = getApplicationGBeanName(rootModule[0])) != null) {
-                    List<IModule[]> changedModules = new ArrayList<IModule[]>();
-                    List<IModule[]> unChangedModules = new ArrayList<IModule[]>();
-                    for (ModuleDelta moduleDelta : moduleList.getChildModules()) {
-                        if (moduleDelta.delta == CHANGED) {
-                            changedModules.add(moduleDelta.module);
+                
+                if (statusMap.size() == childModules.size()) {
+                    // replacement was possible for all changed child modules - we're done
+                    for (Map.Entry<IModule[], IStatus> entry : statusMap.entrySet())
{
+                        setStatus(entry.getKey(), entry.getValue(), multi);
+                    }
+                    setStatus(moduleList.getRootModule(), Status.OK_STATUS, multi);
+                    Trace.traceExit(Activator.traceCore, "GeronimoServerBehaviourDelegate.publishEBAModule",
"File replace");
+                    return;                        
+                } 
+                
+                // fall-through: replacement was not possible for at least one child module
or more work to do              
+            }
+        }
+        
+        boolean refreshOSGiBundle = getServerDelegate().isRefreshOSGiBundle();
+        if (refreshOSGiBundle && moduleList.hasChangedChildModulesOnly(false)) {
+            AbstractName ebaName = getApplicationGBeanName(moduleList.getRootModule()[0]);
+            if (ebaName != null) {
+                for (ModuleInfo module : moduleList.getChildModules()) {
+                    IStatus status = statusMap.get(module.module);
+                    if (status == null) {
+                        if (module.delta == CHANGED) {
+                            status = refreshBundle(ebaName, module);
                         } else {
-                            unChangedModules.add(moduleDelta.module);
+                            status = Status.OK_STATUS;
                         }
+                    }                           
+                    setStatus(module.module, status, multi);
+                }
+                setStatus(moduleList.getRootModule(), Status.OK_STATUS, multi);
+                Trace.traceExit(Activator.traceCore, "GeronimoServerBehaviourDelegate.publishEBAModule",
"Bundle update");
+                return;
+            }
+        }
+        
+        // deploy the entire module
+        publishEntireModule(kind, multi, monitor, moduleList);
+        
+        Trace.traceExit(Activator.traceCore, "GeronimoServerBehaviourDelegate.publishEBAModule");
+    }
+    
+    private void publishEARModule(int kind, MultiStatus multi, IProgressMonitor monitor,
ModuleDeltaList moduleList) {
+        Trace.traceEntry(Activator.traceCore, "GeronimoServerBehaviourDelegate.publishEARModule",
Arrays.toString(moduleList.getRootModule()));
+
+        if (getServerDelegate().isNoRedeploy() && !isRemote()) {            
+            if (moduleList.hasChangedChildModulesOnly(true)) {
+                List<ModuleInfo> childModules = moduleList.getChildModules();
+                Map<IModule[], IStatus> statusMap = new HashMap<IModule[], IStatus>();
+                
+                for (ModuleInfo module : childModules) {
+                    if (module.delta == CHANGED) {
+                        // changed module - try to do replacement
+                        IModuleResourceDelta[] delta = getPublishedResourceDelta(module.module);
+                        IStatus status = tryFileReplace(module.module, delta);
+                        if (status == null) {
+                            // replacement was not possible - must redeploy the whole ear
+                            break;                           
+                        } else {
+                            statusMap.put(module.module, status);
+                        }                       
+                    } else {        
+                        // non-changed module
+                        statusMap.put(module.module, Status.OK_STATUS);
                     }
-                    status = refreshBundles(rootModule[0], ebaName, changedModules, ProgressUtil.getSubMonitorFor(monitor,
3000));
-                    if (status != null && !status.isOK()) {
-                        multi.add(status);
-                    }
-                    unChangedModules.add(rootModule);
-                    for (IModule[] module : unChangedModules) {                   
-                        setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
-                        setModuleStatus(module, null);
-                    }
-                } else {
-                    status = publishModule(kind, rootModule, moduleList.getEffectiveRootDelta(),
ProgressUtil.getSubMonitorFor(monitor, 3000));
-                    if (status != null && !status.isOK()) {
-                        multi.add(status);
-                    } else {
-                        for (ModuleDelta moduleDelta : moduleList.getChildModules()) {
-                            setModulePublishState(moduleDelta.module, IServer.PUBLISH_STATE_NONE);
-                            setModuleStatus(moduleDelta.module, null);
-                        }
+                }
+                        
+                if (statusMap.size() == childModules.size()) {
+                    // replacement was possible for all changed child modules - we're done
                  
+                    for (Map.Entry<IModule[], IStatus> entry : statusMap.entrySet())
{
+                        setStatus(entry.getKey(), entry.getValue(), multi);
                     }
+                    setStatus(moduleList.getRootModule(), Status.OK_STATUS, multi);
+                    Trace.traceExit(Activator.traceCore, "GeronimoServerBehaviourDelegate.publishEARModule",
"File replace");
+                    return;                        
                 }
+                
+                // fall-through: replacement was not possible for at least one child module
- deploy the entire module                         
             }
+        }    
+   
+        // deploy the entire module
+        publishEntireModule(kind, multi, monitor, moduleList);
+        
+        Trace.traceExit(Activator.traceCore, "GeronimoServerBehaviourDelegate.publishEARModule");
+    }
+    
+    private void publishSingleModule(int kind, MultiStatus multi, IProgressMonitor monitor,
ModuleDeltaList moduleList) {
+        Trace.traceEntry(Activator.traceCore, "GeronimoServerBehaviourDelegate.publishSingleModule",
Arrays.toString(moduleList.getRootModule()));
 
-        } else {
-            multi.add(status);
+        if (getServerDelegate().isNoRedeploy() && !isRemote()) {    
+            if (moduleList.getEffectiveRootDelta() == CHANGED) {
+                // contents changed - try to do replacement
+                IModule[] rootModule = moduleList.getRootModule();
+                IModuleResourceDelta[] delta = getPublishedResourceDelta(rootModule);
+                IStatus status = tryFileReplace(rootModule, delta);
+                if (status != null) {
+                    // replacement was possible - we're done
+                    setStatus(rootModule, status, multi);
+                    Trace.traceExit(Activator.traceCore, "GeronimoServerBehaviourDelegate.publishSingleModule",
"File replace");
+                    return;
+                } 
+                  
+                // fall-through: replacement was not possible - deploy the entire module
              
+            }
         }
+        
+        // deploy the entire module
+        publishEntireModule(kind, multi, monitor, moduleList);
+        
+        Trace.traceExit(Activator.traceCore, "GeronimoServerBehaviourDelegate.publishSingleModule");
+    }
+    
+    private void publishEntireModule(int kind, MultiStatus multi, IProgressMonitor monitor,
ModuleDeltaList moduleList) {
+        Trace.traceEntry(Activator.traceCore, "GeronimoServerBehaviourDelegate.publishEntireModule",
Arrays.toString(moduleList.getRootModule()));
 
-        Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.publishModules");
+        IStatus status = publishModule(kind, moduleList.getRootModule(), moduleList.getEffectiveRootDelta(),
ProgressUtil.getSubMonitorFor(monitor, 3000));
+        if (status != null && !status.isOK()) {
+            multi.add(status);
+        } else {
+            for (ModuleInfo moduleDelta : moduleList.getChildModules()) {
+                setModulePublishState(moduleDelta.module, IServer.PUBLISH_STATE_NONE);
+                setModuleStatus(moduleDelta.module, null);
+            }
+        }
+        
+        Trace.traceExit(Activator.traceCore, "GeronimoServerBehaviourDelegate.publishEntireModule",
status);
     }
         
     private AbstractName getApplicationGBeanName(IModule ebaModule) {
@@ -576,46 +662,14 @@ public class GeronimoServerBehaviourDele
         Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.getApplicationGBeanName",
ebaName);
         return ebaName;
     }
-    
-    private IStatus refreshBundles(IModule ebaModule, AbstractName ebaName, List<IModule[]>
bundleModules, IProgressMonitor monitor) {
-        Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.refreshBundles",
ebaModule, ebaName, bundleModules, monitor);
         
-        if (monitor.isCanceled()) {
-            return Status.CANCEL_STATUS;
-        }
-        
-        MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, 0, "", null);
-        
-        try {
-            for (IModule[] bundleModule : bundleModules) {
-                if (monitor.isCanceled()) {
-                    return Status.CANCEL_STATUS;
-                }
-                IStatus status = refreshBundle(ebaModule, bundleModule[1], ebaName); 
-                setStatus(bundleModule, status, multiStatus);
-            }
-        } catch (Exception e) {
-            multiStatus.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.REFRESH_FAIL,
e));
-        }
-        
-        IStatus status;
-        if (multiStatus.isOK()) {
-            status = Status.OK_STATUS;
-        } else {
-            status = multiStatus;
-        }
-        
-        Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.refreshBundles",
status);
-        
-        return status;
-    }
-    
-    private IStatus refreshBundle(IModule ebaModule, IModule bundleModule, AbstractName ebaName)
{
-        Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.refreshBundle",
ebaModule, bundleModule, ebaName);
-
+    private IStatus refreshBundle(AbstractName ebaName, ModuleInfo module) {
+        Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.refreshBundle",
ebaName, module);
+        IModule ebaModule = module.module[0];
+        IModule bundleModule = module.module[1];
         try {
             ExtendedDeploymentManager dm = (ExtendedDeploymentManager) DeploymentCommandFactory.getDeploymentManager(getServer());
-            
+
             BundleInfo bundleInfo = AriesHelper.getBundleInfo(bundleModule.getProject());
             long bundleId = dm.getEBAContentBundleId(ebaName, bundleInfo.getSymbolicName(),
bundleInfo.getVersion().toString());
             
@@ -627,7 +681,7 @@ public class GeronimoServerBehaviourDele
             /*
              * Try class hot swap first and if it fails fallback to regular bundle update.
              */
-            ClassReplaceResult result = refreshBundleClasses(dm, ebaModule, bundleModule,
ebaName, bundleId);
+            ClassReplaceResult result = refreshBundleClasses(dm, ebaName, module, bundleId);
             if (result != ClassReplaceResult.SUCCESS) {
                 File file = DeploymentUtils.getTargetFile(getServer(), bundleModule);
                 dm.updateEBAContent(ebaName, bundleId, file);
@@ -647,16 +701,18 @@ public class GeronimoServerBehaviourDele
 
     private enum ClassReplaceResult { SUCCESS, FAIL, FAIL_FORCE_GC };
     
-    private ClassReplaceResult refreshBundleClasses(ExtendedDeploymentManager dm, IModule
ebaModule, IModule bundleModule, AbstractName ebaName, long bundleId) throws Exception {
-        Trace.traceEntry(Activator.traceCore, "GeronimoServerBehaviourDelegate.refreshBundleClasses",
ebaModule, bundleModule, ebaName, bundleId);    
+    private ClassReplaceResult refreshBundleClasses(ExtendedDeploymentManager dm, AbstractName
ebaName, ModuleInfo module, long bundleId) throws Exception {
+        Trace.traceEntry(Activator.traceCore, "GeronimoServerBehaviourDelegate.refreshBundleClasses",
ebaName, module, bundleId);    
         // check if class hot swap is supported
         if (!dm.isRedefineClassesSupported()) {
             Trace.traceExit(Activator.traceCore, "GeronimoServerBehaviourDelegate.refreshBundleClasses",
"Class redefinition is not supported");        
             return ClassReplaceResult.FAIL;
         }
         // ensure only classes have changed
-        IModule[] module = new IModule[] { ebaModule, bundleModule };
-        IModuleResourceDelta[] delta = getPublishedResourceDelta(module);
+        IModuleResourceDelta[] delta = module.resourceDelta;
+        if (delta == null) {
+            delta = getPublishedResourceDelta(module.module);
+        }
         IModuleResource[] classResources = DeploymentUtils.getChangedClassResources(delta);
         if (classResources == null) {
             Trace.traceExit(Activator.traceCore, "GeronimoServerBehaviourDelegate.refreshBundleClasses",
"Non-class resource modifications found");
@@ -742,24 +798,29 @@ public class GeronimoServerBehaviourDele
         return enabled;
     }
     
-    private static class ModuleDelta {
+    private static class ModuleInfo {
         private final IModule[] module;
         private int delta = NO_CHANGE;
+        private IModuleResourceDelta[] resourceDelta;
         
-        public ModuleDelta(IModule[] module, int delta) {
+        public ModuleInfo(IModule[] module, int delta) {
             this.module = module;
             this.delta = delta;
         }
+        
+        public String toString() {
+            return Arrays.toString(module);
+        }
     }
     
-    private static class ModuleDeltaList {       
+    private static class ModuleDeltaList {
         
-        private ModuleDelta root;
-        private List<ModuleDelta> children;
+        private ModuleInfo root;
+        private List<ModuleInfo> children;
         
         public ModuleDeltaList(IModule rootModule) {
-            this.root = new ModuleDelta(new IModule [] {rootModule}, NO_CHANGE);
-            this.children = new ArrayList<ModuleDelta>();
+            this.root = new ModuleInfo(new IModule [] {rootModule}, NO_CHANGE);
+            this.children = new ArrayList<ModuleInfo>();
         }
 
         public IModule[] getRootModule() {
@@ -768,7 +829,7 @@ public class GeronimoServerBehaviourDele
         
         public int getEffectiveRootDelta() {
             if (root.delta == NO_CHANGE) {
-                for (ModuleDelta child : children) {
+                for (ModuleInfo child : children) {
                     if (child.delta == ADDED || child.delta == REMOVED || child.delta ==
CHANGED) {
                         return CHANGED;
                     }
@@ -782,10 +843,10 @@ public class GeronimoServerBehaviourDele
         }
         
         public void addChildModule(IModule[] module, int moduleDelta) {
-            children.add(new ModuleDelta(module, moduleDelta));
+            children.add(new ModuleInfo(module, moduleDelta));
         }
         
-        public List<ModuleDelta> getChildModules() {
+        public List<ModuleInfo> getChildModules() {
             return children;
         }
 
@@ -813,7 +874,7 @@ public class GeronimoServerBehaviourDele
         public int getChangedChildModulesOnly() {
             if (root.delta == NO_CHANGE) {
                 int changed = 0;
-                for (ModuleDelta child : children) {
+                for (ModuleInfo child : children) {
                     if (child.delta == ADDED || child.delta == REMOVED) {
                         return -1;
                     } else if (child.delta == CHANGED) {
@@ -1154,7 +1215,7 @@ public class GeronimoServerBehaviourDele
         }
     }
     
-    private IStatus tryFileReplace(IModule[] module) {
+    private IStatus tryFileReplace(IModule[] module, IModuleResourceDelta[] deltas) {
         Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.tryFileReplace",
Arrays.asList(module));
         
         String publishLocation = getModulePublishLocation(module);
@@ -1163,7 +1224,6 @@ public class GeronimoServerBehaviourDele
             return null;
         }
 
-        IModuleResourceDelta[] deltas = getPublishedResourceDelta(module);
         if (!canPublishDelta(deltas)) {
             Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.tryFileReplace",
"Some modified files cannot be replaced");
             return null;



Mime
View raw message