Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 98894 invoked from network); 11 Mar 2011 21:25:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 11 Mar 2011 21:25:04 -0000 Received: (qmail 29858 invoked by uid 500); 11 Mar 2011 21:25:04 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 29811 invoked by uid 500); 11 Mar 2011 21:25:04 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 29804 invoked by uid 99); 11 Mar 2011 21:25:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Mar 2011 21:25:04 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Mar 2011 21:25:03 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id E918A23888CD; Fri, 11 Mar 2011 21:24:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1080765 - /geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java Date: Fri, 11 Mar 2011 21:24:40 -0000 To: scm@geronimo.apache.org From: gawor@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110311212440.E918A23888CD@eris.apache.org> Author: gawor Date: Fri Mar 11 21:24:40 2011 New Revision: 1080765 URL: http://svn.apache.org/viewvc?rev=1080765&view=rev Log: GERONIMODEVTOOLS-715: Mark the application instead of the module as republish when a module within an application is updated. Modified: 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/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=1080765&r1=1080764&r2=1080765&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 Fri Mar 11 21:24:40 2011 @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Timer; @@ -109,6 +110,7 @@ abstract public class GeronimoServerBeha abstract protected ClassLoader getContextClassLoader(); + private PublishStateListener publishStateListener; /* * (non-Javadoc) @@ -242,7 +244,7 @@ abstract public class GeronimoServerBeha * @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", "GeronimoServerBehaviourDelegate.publishModules", deltaKindToString(kind), Arrays.asList(modules).toString(), Arrays.asList(deltaKind).toString(), multi, monitor); + Trace.tracePoint("Entry", "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 @@ -273,6 +275,24 @@ abstract public class GeronimoServerBeha IModule[] toProcess = (IModule[])rootModules.toArray(new IModule[rootModules.size()]); status = updateSharedLib(toProcess, ProgressUtil.getSubMonitorFor(monitor, 1000)); } + + /* + * Build a map of root modules that need to be published. This is to ensure that + * we avoid redeploys and it guarantees that publishModule() is called once per + * deployed application. + */ + Map publishMap = new LinkedHashMap(); + for (int i = 0; i < modules.size(); i++) { + IModule[] module = (IModule[]) modules.get(i); + Integer moduleDeltaKind = (Integer) deltaKind.get(i); + ModuleList list = publishMap.get(module[0]); + if (list == null) { + list = new ModuleList(module[0]); + publishMap.put(module[0], list); + } + list.addModule(module, moduleDeltaKind.intValue()); + } + if(status.isOK()) { if (modules == null) return; @@ -284,6 +304,16 @@ abstract public class GeronimoServerBeha if (monitor.isCanceled()) return; + for (ModuleList moduleList : publishMap.values()) { + status = publishModule(kind, moduleList.getRootModule(), moduleList.getDelta(), ProgressUtil.getSubMonitorFor(monitor, 3000)); + if (status != null && !status.isOK()) { + multi.add(status); + } + for (IModule[] module : moduleList.getModules()) { + setModulePublishState(module, IServer.PUBLISH_STATE_NONE); + } + } + /* List rootModulesPublished = new ArrayList(); for (int i = 0; i < size; i++) { IModule[] module = (IModule[]) modules.get(i); @@ -303,12 +333,46 @@ abstract public class GeronimoServerBeha Trace.trace(Trace.INFO, "root module for " + Arrays.asList(module).toString() + " already published. Skipping."); } } + */ } else { multi.add(status); } Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.publishModules"); } + + private static class ModuleList { + private final IModule rootModule; + private final List modules; + private int delta = NO_CHANGE; + + public ModuleList(IModule rootModule) { + this.rootModule = rootModule; + this.modules = new ArrayList(); + } + + public IModule[] getRootModule() { + return new IModule[] { rootModule }; + } + + public void addModule(IModule[] module, int moduleDelta) { + if (module.length > 1) { + modules.add(module); + } + if (delta == NO_CHANGE) { + delta = moduleDelta; + } + } + + public List getModules() { + return modules; + } + + public int getDelta() { + return delta; + } + + } /* * This method is used to invoke DependencyHelper of different version @@ -324,12 +388,10 @@ abstract public class GeronimoServerBeha * org.eclipse.core.runtime.IProgressMonitor) */ public void publishModule(int kind, int deltaKind, IModule[] module, IProgressMonitor monitor) throws CoreException { - Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.publishModule", deltaKindToString(kind), deltaKindToString(deltaKind), Arrays.asList(module).toString(), monitor); + Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.publishModule", publishKindToString(kind), deltaKindToString(deltaKind), Arrays.asList(module), monitor); _monitor = monitor; - - setModuleStatus(module, null); - setModulePublishState(module, IServer.PUBLISH_STATE_NONE); + try { //NO_CHANGE need if app is associated but not started and no delta if (deltaKind == NO_CHANGE && module.length == 1) { @@ -338,19 +400,22 @@ abstract public class GeronimoServerBeha else if (deltaKind == CHANGED || deltaKind == ADDED || deltaKind == REMOVED) { invokeCommand(deltaKind, module[0]); } - } + setModuleStatus(module, null); + setModulePublishState(module, IServer.PUBLISH_STATE_NONE); + } catch (CoreException e) { // - // Set the module publish state to UNKNOWN so that WTP will display "Republish" instead + // Set the parent module publish state to UNKNOWN so that WTP will display "Republish" instead // "Synchronized" for the server state, and set the module status to an error message // for the GEP end-user to see. - // + // setModuleStatus(module, new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error publishing module to server")); setModulePublishState(module, IServer.PUBLISH_STATE_UNKNOWN); + setModuleState(module, IServer.STATE_UNKNOWN); throw e; } - - // Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.publishModule"); + + Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.publishModule"); } /* @@ -364,11 +429,18 @@ abstract public class GeronimoServerBeha IModule[] modules = this.getServer().getModules(); boolean allpublished = true; for (int i = 0; i < modules.length; i++) { - if (this.getServer().getModulePublishState(new IModule[] { modules[i] }) != IServer.PUBLISH_STATE_NONE) + int state = getServer().getModulePublishState(new IModule[] { modules[i] }); + if (state != IServer.PUBLISH_STATE_NONE) { allpublished = false; + break; + } } - if (allpublished) + if (allpublished) { setServerPublishState(IServer.PUBLISH_STATE_NONE); + } else { + setServerPublishState(IServer.PUBLISH_STATE_UNKNOWN); + setServerStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error publishing one or more modules to server")); + } GeronimoConnectionFactory.getInstance().destroy(getServer()); @@ -384,12 +456,48 @@ abstract public class GeronimoServerBeha * @param monitor a progress monitor, or null if progress reporting and cancellation * are not desired */ + @Override protected void initialize(IProgressMonitor monitor) { Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.initialize", monitor); + + publishStateListener = new PublishStateListener(); + getServer().addServerListener(publishStateListener, ServerEvent.MODULE_CHANGE | ServerEvent.PUBLISH_STATE_CHANGE); + Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.initialize"); } - + /* + * GERONIMODEVTOOLS-715: Update parent module publish state to "publish" if a child + * publish state was changed to "publish". This is because GEP right now is redeploying the + * entire application instead of the individual bundle/module that has changed. Once that is + * supported this listener can be removed. + */ + private class PublishStateListener implements IServerListener { + public void serverChanged(ServerEvent event) { + if (event.getPublishState() == IServer.PUBLISH_STATE_INCREMENTAL || + event.getPublishState() == IServer.PUBLISH_STATE_FULL) { + // reset server status in case it was set + setServerStatus(null); + + IModule[] modules = event.getModule(); + if (modules.length > 1) { + int publishState = (getServer().getServerState() == IServer.STATE_STARTED) ? IServer.PUBLISH_STATE_NONE : IServer.PUBLISH_STATE_UNKNOWN; + // reset child module publish state + setModulePublishState(event.getModule(), publishState); + + IModule[] newModules = new IModule[modules.length - 1]; + System.arraycopy(modules, 0, newModules, 0, newModules.length); + + // update parent module publish state to "publish" + setModulePublishState(newModules, event.getPublishState()); + // reset parent module status message + setModuleStatus(newModules, null); + } + } + + } + } + /* * (non-Javadoc) * @@ -398,6 +506,9 @@ abstract public class GeronimoServerBeha public void dispose() { stopUpdateServerStateTask(); stopSynchronizeProjectOnServerTask(); + if (publishStateListener != null) { + getServer().removeServerListener(publishStateListener); + } } public abstract String getRuntimeClass(); @@ -965,7 +1076,7 @@ abstract public class GeronimoServerBeha } protected IPath getModulePath(IModule[] module, URL baseURL) { - Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.getModulePath", Arrays.asList(module).toString(), baseURL); + Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.getModulePath", Arrays.asList(module), baseURL); IPath modulePath = new Path(baseURL.getFile()); @@ -1041,6 +1152,20 @@ abstract public class GeronimoServerBeha return Integer.toString(kind); } + public static String publishKindToString(int kind) { + switch(kind) { + case IServer.PUBLISH_AUTO: + return "Auto"; + case IServer.PUBLISH_CLEAN: + return "Clean"; + case IServer.PUBLISH_FULL: + return "Full"; + case IServer.PUBLISH_INCREMENTAL: + return "Incremental"; + } + return Integer.toString(kind); + } + public String getConfigId(IModule module) throws Exception { return getGeronimoServer().getVersionHandler().getConfigID(module); }