geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johnx...@apache.org
Subject svn commit: r1357610 - in /geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core: GeronimoServerBehaviourDelegate.java GeronimoServerDelegate.java internal/ServerDelegateHelper.java
Date Thu, 05 Jul 2012 13:57:07 GMT
Author: johnxiao
Date: Thu Jul  5 13:57:06 2012
New Revision: 1357610

URL: http://svn.apache.org/viewvc?rev=1357610&view=rev
Log:
GERONIMODEVTOOLS-791 Delete module while server is stopped

Added:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/ServerDelegateHelper.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/GeronimoServerBehaviourDelegate.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerDelegate.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=1357610&r1=1357609&r2=1357610&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
Thu Jul  5 13:57:06 2012
@@ -22,7 +22,6 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -41,8 +40,6 @@ import javax.enterprise.deploy.spi.excep
 import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
 import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
 import javax.naming.directory.NoSuchAttributeException;
 
 import org.apache.geronimo.deployment.plugin.jmx.ExtendedDeploymentManager;
@@ -59,11 +56,11 @@ import org.apache.geronimo.kernel.config
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.st.core.GeronimoJMXConnectorFactory;
 import org.apache.geronimo.st.core.GeronimoJMXConnectorFactory.JMXConnectorInfo;
-import org.apache.geronimo.st.v30.core.UpdateServerStateTask;
 import org.apache.geronimo.st.v30.core.commands.DeploymentCommandFactory;
 import org.apache.geronimo.st.v30.core.commands.TargetModuleIdNotFoundException;
 import org.apache.geronimo.st.v30.core.internal.DependencyHelper;
 import org.apache.geronimo.st.v30.core.internal.Messages;
+import org.apache.geronimo.st.v30.core.internal.ServerDelegateHelper;
 import org.apache.geronimo.st.v30.core.internal.Trace;
 import org.apache.geronimo.st.v30.core.operations.ISharedLibEntryCreationDataModelProperties;
 import org.apache.geronimo.st.v30.core.operations.SharedLibEntryCreationOperation;
@@ -940,6 +937,14 @@ public class GeronimoServerBehaviourDele
         setServerState(IServer.STATE_STARTED);
         GeronimoConnectionFactory.getInstance().destroy(getServer());
         startSynchronizeProjectOnServerTask();
+        
+        ServerDelegateHelper helper = getServerDelegate().getServerDelegateHelper();
+        String jvmArgs = helper.deleteRemovedArtifactListFromJVMArgs(getServerDelegate().getVMArgs());
+        try {
+            helper.persistJVMArgs(jvmArgs, new NullProgressMonitor());
+        } catch (CoreException e) {
+            Trace.trace(Trace.ERROR, e.getMessage(), e, Activator.traceCore);
+        }
     }
 
     public void setServerStopped() {

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerDelegate.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/GeronimoServerDelegate.java?rev=1357610&r1=1357609&r2=1357610&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerDelegate.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerDelegate.java
Thu Jul  5 13:57:06 2012
@@ -22,7 +22,6 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
@@ -39,6 +38,7 @@ import javax.enterprise.deploy.spi.facto
 import org.apache.geronimo.crypto.EncryptionManager;
 import org.apache.geronimo.deployment.plugin.factories.DeploymentFactoryImpl;
 import org.apache.geronimo.deployment.plugin.jmx.JMXDeploymentManager;
+import org.apache.geronimo.st.v30.core.internal.ServerDelegateHelper;
 import org.apache.geronimo.st.v30.core.internal.Trace;
 import org.apache.geronimo.st.v30.core.osgi.AriesHelper;
 import org.apache.geronimo.st.v30.core.osgi.OsgiConstants;
@@ -54,6 +54,7 @@ import org.eclipse.jst.server.core.inter
 import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
 import org.eclipse.wst.server.core.IModule;
 import org.eclipse.wst.server.core.IModuleType;
+import org.eclipse.wst.server.core.IServer;
 import org.eclipse.wst.server.core.ServerPort;
 import org.eclipse.wst.server.core.ServerUtil;
 import org.eclipse.wst.server.core.internal.ServerMonitorManager;
@@ -152,6 +153,8 @@ public class GeronimoServerDelegate exte
     
     public static final String ENABLE_REMOTE_KARAF_SHELL = "-Dkaraf.startRemoteShell=true";
     
+    public static final String REMOVE_ARTIFACT_LIST = "-Dgeronimo.removedArtifactList";
+    
     public static final int KARAF_SHELL_DEFAULT_TIMEOUT = 0;
     
     public static final int KARAF_SHELL_DEFAULT_KEEPALIVE = 300;
@@ -162,6 +165,8 @@ public class GeronimoServerDelegate exte
 
     private static DeploymentFactory deploymentFactory = new DeploymentFactoryImpl();
     
+    private final ServerDelegateHelper serverDelegateHelper = new ServerDelegateHelper(this);
+    
     private boolean suspendArgUpdates;
     
     /*
@@ -254,7 +259,17 @@ public class GeronimoServerDelegate exte
      */
     public void modifyModules(IModule[] add, IModule[] remove, IProgressMonitor monitor)
throws CoreException {
         Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerDelegate.modifyModules",
add, remove, monitor);
-
+        // Now, only handle the remov/add modules when the server is shutdown 
+        // and the attribute org.apache.geronimo.st.v30.core.manageApplicationStart is true
+        int serverState = getServer().getServerState();
+        if(serverState == IServer.STATE_STOPPED && isManageApplicationStart()) {
+            if(remove != null && remove.length > 0) {
+                serverDelegateHelper.markRemoveModules(remove, monitor);
+            } 
+            if(add != null && add.length > 0) {
+                serverDelegateHelper.unMarkRemoveModules(add, monitor);
+            }
+        }
         // TODO servermodule.info should be pushed to here and set as instance
         // property
 
@@ -1187,6 +1202,9 @@ public class GeronimoServerDelegate exte
     public void setServerInstanceProperties(Map map) {
         setAttribute(GeronimoRuntimeDelegate.SERVER_INSTANCE_PROPERTIES, map);
     }
-
+    
+    public ServerDelegateHelper getServerDelegateHelper() {
+        return serverDelegateHelper;
+    }
     
 }

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/ServerDelegateHelper.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/internal/ServerDelegateHelper.java?rev=1357610&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/ServerDelegateHelper.java
(added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/ServerDelegateHelper.java
Thu Jul  5 13:57:06 2012
@@ -0,0 +1,159 @@
+/**
+ *  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.internal;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.geronimo.st.v30.core.Activator;
+import org.apache.geronimo.st.v30.core.DeploymentUtils;
+import org.apache.geronimo.st.v30.core.GeronimoServerDelegate;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.wst.server.core.IModule;
+
+/**
+ * Using the class to help the Server delegate
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServerDelegateHelper {
+    public final GeronimoServerDelegate serverDelegate;
+    
+    public ServerDelegateHelper(GeronimoServerDelegate serverDelegate) {
+        this.serverDelegate = serverDelegate;
+    }
+    
+    public void markRemoveModules(IModule[] modules, IProgressMonitor monitor) throws CoreException
{
+        String jvmArgs = serverDelegate.getVMArgs();
+        String trimedJvmArgs = deleteRemovedArtifactListFromJVMArgs(jvmArgs);
+        String removedModuleString = getRemovedModuleStringFromJVMArgs(jvmArgs);
+        
+        // mark the module as removed
+        for(IModule rModule : modules) {
+            String configId = DeploymentUtils.getConfigId(serverDelegate.getServer(), rModule);
+            
+            boolean needChange = true;
+            if(! removedModuleString.equals("")) {
+                String[] rArtifactIds = removedModuleString.split(",");
+                
+                for(String rArtifactId : rArtifactIds) {
+                    if(rArtifactId.equals(configId)) {
+                        needChange = false;
+                        break;
+                    }
+                }
+            } else {// it means no modules need to be removed before, so just adds it
+                needChange = true;// 
+            }
+            if(needChange) {
+                removedModuleString = removedModuleString == "" ? configId : removedModuleString
+ "," + configId;
+                //persist the removed module to jvm args
+                trimedJvmArgs = trimedJvmArgs.endsWith(" ") ? trimedJvmArgs : trimedJvmArgs
+ " ";
+                persistJVMArgs(trimedJvmArgs + GeronimoServerDelegate.REMOVE_ARTIFACT_LIST
+ "=" + removedModuleString, monitor);
+                Trace.trace(Trace.INFO, rModule.getName() + ":" + rModule.getModuleType()
+ " is marked as REMOVED", Activator.traceCore);
+            }
+        }
+    }
+
+    public void unMarkRemoveModules(IModule[] modules, IProgressMonitor monitor) throws CoreException
{
+        String jvmArgs = serverDelegate.getVMArgs();
+        String trimedJvmArgs = deleteRemovedArtifactListFromJVMArgs(jvmArgs);
+        String removedModuleString = getRemovedModuleStringFromJVMArgs(jvmArgs);
+        
+        for(IModule rModule : modules) {
+            String configId = DeploymentUtils.getConfigId(serverDelegate.getServer(), rModule);
+            List<String> rArtifactList = new ArrayList<String>();
+            boolean needChange = false;
+            
+            if(! removedModuleString.equals("")) {
+                String[] rArtifactIds = removedModuleString.split(",");
+                
+                rArtifactList.addAll(Arrays.asList(rArtifactIds));
+                Iterator<String> iter = rArtifactList.iterator();
+                while(iter.hasNext()) {
+                    if(iter.next().equals(configId)) {
+                        iter.remove();
+                        needChange = true;
+                        break;
+                    }
+                }
+            }
+            if(needChange) {
+                Iterator<String> iter = rArtifactList.iterator();
+                StringBuilder sBuilder = new StringBuilder("");
+                while(iter.hasNext()) {
+                    sBuilder.append(iter.next()).append(",");
+                }
+                if(sBuilder.length() > 0) {
+                    removedModuleString = sBuilder.substring(0, sBuilder.length() - 1);
+                    trimedJvmArgs = trimedJvmArgs.endsWith(" ") ? trimedJvmArgs : trimedJvmArgs
+ " ";
+                    trimedJvmArgs = trimedJvmArgs + GeronimoServerDelegate.REMOVE_ARTIFACT_LIST
+ "=" + removedModuleString;
+                }
+                //persist the removed module to jvm args
+                persistJVMArgs(trimedJvmArgs, monitor);
+                Trace.trace(Trace.INFO, rModule.getName() + ":" + rModule.getModuleType()
+ " is unmarked", Activator.traceCore);
+            }
+        }
+    }
+    
+    public String deleteRemovedArtifactListFromJVMArgs(String jvmArgs) {
+        String newJvmArgs = "";
+        
+        int index = jvmArgs.indexOf(GeronimoServerDelegate.REMOVE_ARTIFACT_LIST);
+        if(index >= 0) {
+            newJvmArgs = jvmArgs.substring(0, index);
+            int splitIndex = jvmArgs.indexOf(0x20, index);
+            
+            if(splitIndex > 0) {
+                newJvmArgs += jvmArgs.substring(splitIndex + 1);// the new jvm args eliminate
the -Dgeronimo.removedArtifactList=...
+            }
+            return newJvmArgs;
+        }
+        return jvmArgs;
+    }
+    
+    public String getRemovedModuleStringFromJVMArgs(String jvmArgs) {
+        String removedModuleString = "";
+        
+        int index = jvmArgs.indexOf(GeronimoServerDelegate.REMOVE_ARTIFACT_LIST);
+        if(index >= 0) {
+            removedModuleString = jvmArgs.substring(index);
+            int splitIndex = removedModuleString.indexOf(0x20);
+            
+            if(splitIndex == -1) {// it means the -Dgeronimo.removedArtifactList=... is the
last jvm arg
+                removedModuleString = removedModuleString.substring(GeronimoServerDelegate.REMOVE_ARTIFACT_LIST.length()
+ 1);
+            } else if(splitIndex > 0) {
+                removedModuleString = removedModuleString.substring(GeronimoServerDelegate.REMOVE_ARTIFACT_LIST.length()
+ 1, splitIndex);
+            }
+        }
+        return removedModuleString;
+    }
+    
+    public void persistJVMArgs(String jvmArgs, IProgressMonitor monitor) throws CoreException
{
+        jvmArgs = jvmArgs.trim();
+        ILaunchConfigurationWorkingCopy launchConfigWc = serverDelegate.getServer().getLaunchConfiguration(true,
monitor).getWorkingCopy();
+        launchConfigWc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
jvmArgs);
+        launchConfigWc.doSave();
+
+        serverDelegate.setVMArgs(jvmArgs);
+    }
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/ServerDelegateHelper.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/internal/ServerDelegateHelper.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/internal/ServerDelegateHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message