geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1363511 - in /geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core: ./ internal/
Date Thu, 19 Jul 2012 20:02:47 GMT
Author: gawor
Date: Thu Jul 19 20:02:47 2012
New Revision: 1363511

URL: http://svn.apache.org/viewvc?rev=1363511&view=rev
Log:
GERONIMODEVTOOLS-791: Simplify code a bit and make it consistent with other related feature.
Fix NPE on start.

Added:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/RemovedModuleHelper.java
  (with props)
Removed:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/ServerDelegateHelper.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
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoLaunchConfigurationDelegate.java
    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/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=1363511&r1=1363510&r2=1363511&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
Thu Jul 19 20:02:47 2012
@@ -137,13 +137,18 @@ public class DeploymentUtils {
             //file = generateRunFromWorkspaceConfig(getModule());
             throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Run from
workspace is unsupported."));
         } else {
-            IPath outputDir = DeploymentUtils.STATE_LOC.append("server_" + server.getId());
-            outputDir.toFile().mkdirs();
+            IPath outputDir = getServerDirectory(server);
             file = DeploymentUtils.createJarFile(module, outputDir);
         }
         return file;
     }
     
+    public static IPath getServerDirectory(IServer server) {
+        IPath outputDir = DeploymentUtils.STATE_LOC.append("server_" + server.getId());
+        outputDir.toFile().mkdirs();
+        return outputDir;
+    }
+    
     public static int getModuleState(IServer server, IModule module) {
         return server.getModuleState(new IModule[] {module});
     }

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoLaunchConfigurationDelegate.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/GeronimoLaunchConfigurationDelegate.java?rev=1363511&r1=1363510&r2=1363511&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoLaunchConfigurationDelegate.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoLaunchConfigurationDelegate.java
Thu Jul 19 20:02:47 2012
@@ -139,10 +139,25 @@ public class GeronimoLaunchConfiguration
         Trace.trace(Trace.INFO, "GeronimoLaunchConfigurationDelegate: manageApplicationStart:="
+ managedApplicationStart, Activator.traceCore);
         if (managedApplicationStart) {
             Set<String> modifiedConfigs = server.getModifiedConfigIds();
+            Set<String> deletedConfigs = server.getDeletedConfigIds();
+            int params = 0;
             if (!modifiedConfigs.isEmpty()) {
-                String[] newJvmArguments = new String[jvmArguments.length + 1];
+                params++;
+            }
+            if (!deletedConfigs.isEmpty()) {
+                params++;
+            }            
+            if (params > 0) {
+                String[] newJvmArguments = new String[jvmArguments.length + params];
                 System.arraycopy(jvmArguments, 0, newJvmArguments, 0, jvmArguments.length);
-                newJvmArguments[jvmArguments.length] = toString("-Dgeronimo.loadOnlyConfigList=",
modifiedConfigs);
+                int index = jvmArguments.length;
+                if (!modifiedConfigs.isEmpty()) {
+                    newJvmArguments[index] = toString("-Dgeronimo.loadOnlyConfigList=", modifiedConfigs);
+                    index++;
+                }
+                if (!deletedConfigs.isEmpty()) {
+                    newJvmArguments[index] = toString("-Dgeronimo.removedArtifactList=",
deletedConfigs);
+                }
                 return newJvmArguments;
             }
         }

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=1363511&r1=1363510&r2=1363511&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 19 20:02:47 2012
@@ -54,7 +54,7 @@ import org.apache.geronimo.st.core.Geron
 import org.apache.geronimo.st.v30.core.commands.DeploymentCommandFactory;
 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.RemovedModuleHelper;
 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;
@@ -135,6 +135,8 @@ public class GeronimoServerBehaviourDele
     
     private DefaultModuleHandler defaultModuleHandler;
     private OSGiModuleHandler osgiModuleHandler;
+    
+    private RemovedModuleHelper removedModuleHelper;
 
     protected ClassLoader getContextClassLoader() {
         return Kernel.class.getClassLoader();
@@ -845,6 +847,8 @@ public class GeronimoServerBehaviourDele
         defaultModuleHandler = new DefaultModuleHandler(this);
         osgiModuleHandler = new OSGiModuleHandler(this);
         
+        removedModuleHelper = new RemovedModuleHelper(this);
+        
         Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.initialize");
     }
 
@@ -907,14 +911,7 @@ 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);
-        }
+        removedModuleHelper.clearRemoveModules();
     }
 
     public void setServerStopped() {
@@ -1710,4 +1707,16 @@ public class GeronimoServerBehaviourDele
         Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.getModifiedConfigIds",
configIds);        
         return configIds;
     }
+    
+    public Set<String> getDeletedConfigIds() {
+        Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.getDeletedConfigIds");
+        Set<String> configIds = removedModuleHelper.getRemovedConfigIds();
+        Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.getDeletedConfigIds",
configIds);        
+        return configIds;
+    }
+    
+    protected RemovedModuleHelper getRemovedModuleHelper() {
+        return removedModuleHelper;
+    }
+    
 }

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=1363511&r1=1363510&r2=1363511&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 19 20:02:47 2012
@@ -38,7 +38,6 @@ 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;
@@ -153,8 +152,6 @@ 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;
@@ -165,8 +162,6 @@ public class GeronimoServerDelegate exte
 
     private static DeploymentFactory deploymentFactory = new DeploymentFactoryImpl();
     
-    private final ServerDelegateHelper serverDelegateHelper = new ServerDelegateHelper(this);
-    
     private boolean suspendArgUpdates;
     
     /*
@@ -262,12 +257,13 @@ public class GeronimoServerDelegate exte
         // 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 (serverState == IServer.STATE_STOPPED && isManageApplicationStart()) {
+            GeronimoServerBehaviourDelegate delegate = (GeronimoServerBehaviourDelegate)
getServer().loadAdapter(GeronimoServerBehaviourDelegate.class, monitor);
+            if (remove != null && remove.length > 0) {
+                delegate.getRemovedModuleHelper().markRemoveModules(remove, monitor);
             } 
-            if(add != null && add.length > 0) {
-                serverDelegateHelper.unMarkRemoveModules(add, monitor);
+            if (add != null && add.length > 0) {
+                delegate.getRemovedModuleHelper().unMarkRemoveModules(add, monitor);
             }
         }
         // TODO servermodule.info should be pushed to here and set as instance
@@ -534,6 +530,11 @@ public class GeronimoServerDelegate exte
         return null;        
     }
 
+    @Override
+    protected void initialize() {
+        Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerDelegate.initialize");
+        Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerDelegate.initialize");
+    }
 
     /**
      * Initialize this server with default values when a new server is created
@@ -1203,9 +1204,5 @@ 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/RemovedModuleHelper.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/RemovedModuleHelper.java?rev=1363511&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/RemovedModuleHelper.java
(added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/RemovedModuleHelper.java
Thu Jul 19 20:02:47 2012
@@ -0,0 +1,140 @@
+/**
+ *  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.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.geronimo.kernel.util.IOUtils;
+import org.apache.geronimo.st.v30.core.Activator;
+import org.apache.geronimo.st.v30.core.DeploymentUtils;
+import org.apache.geronimo.st.v30.core.GeronimoServerBehaviourDelegate;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.server.core.IModule;
+
+/**
+ * Using the class to help the Server delegate
+ * 
+ * @version $Rev$ $Date: 2012-07-05 09:57:06 -0400 (Thu, 05 Jul 2012)
+ *          $
+ */
+public class RemovedModuleHelper {
+
+    private final GeronimoServerBehaviourDelegate serverDelegate;
+    private final IPath dataFile;
+    private final Set<String> deletedConfigs;
+
+    public RemovedModuleHelper(GeronimoServerBehaviourDelegate serverDelegate) {
+        this.serverDelegate = serverDelegate;
+        this.dataFile = DeploymentUtils.getServerDirectory(serverDelegate.getServer()).append("deleted-modules.dat");
+        this.deletedConfigs = loadDataFile();
+    }
+
+    public synchronized void markRemoveModules(IModule[] modules, IProgressMonitor monitor)
throws CoreException {
+        // mark the module as removed
+        boolean needChange = false;
+        for (IModule rModule : modules) {
+            String configId = DeploymentUtils.getConfigId(serverDelegate.getServer(), rModule);
+            if (!deletedConfigs.contains(configId)) {
+                deletedConfigs.add(configId);
+                needChange = true;
+            }
+        }
+
+        if (needChange) {
+            saveDataFile();
+        }
+    }
+
+    public synchronized void unMarkRemoveModules(IModule[] modules, IProgressMonitor monitor)
throws CoreException {
+        boolean needChange = false;
+        for (IModule rModule : modules) {
+            String configId = DeploymentUtils.getConfigId(serverDelegate.getServer(), rModule);
+            if (deletedConfigs.remove(configId)) {
+                needChange = true;
+            }
+        }
+
+        if (needChange) {
+            saveDataFile();
+        }
+    }
+
+    public synchronized void clearRemoveModules() {
+        deletedConfigs.clear();
+        deleteDataFile();
+    }
+    
+    public synchronized Set<String> getRemovedConfigIds() {
+        return new HashSet<String>(deletedConfigs);
+    }
+
+    private void deleteDataFile() {
+        Trace.tracePoint("Entry", Activator.traceCore, "ServerDelegateHelper.deleteDataFile",
dataFile);
+        File file = dataFile.toFile();
+        boolean rs = file.delete();
+        Trace.tracePoint("Exit", Activator.traceCore, "ServerDelegateHelper.deleteDataFile",
rs);
+    }
+    
+    private Set<String> loadDataFile() {
+        Trace.tracePoint("Entry", Activator.traceCore, "ServerDelegateHelper.loadDataFile",
dataFile);
+        File file = dataFile.toFile();  
+        Set<String> set = null;
+        if (file.exists()) {
+            ObjectInputStream oi = null;
+            try {
+                oi = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)));
+                set = (Set<String>) oi.readObject();
+            } catch (Exception e) {
+                Trace.trace(Trace.ERROR, e.getMessage(), e, Activator.logCore);
+            } finally {
+                IOUtils.close(oi);
+            }
+        }
+        if (set == null) {
+            set = new HashSet<String>();
+        }
+        Trace.tracePoint("Exit", Activator.traceCore, "ServerDelegateHelper.loadDataFile",
set);
+        return set;
+    }
+
+    private void saveDataFile() {
+        Trace.tracePoint("Entry", Activator.traceCore, "ServerDelegateHelper.saveDataFile",
dataFile, deletedConfigs);
+        File file = dataFile.toFile();
+        ObjectOutputStream oo = null;
+        try {
+            oo = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
+            oo.writeObject(deletedConfigs);
+        } catch (IOException e) {
+            Trace.trace(Trace.ERROR, e.getMessage(), e, Activator.logCore);
+        } finally {
+            IOUtils.close(oo);
+        }
+        Trace.tracePoint("Exit", Activator.traceCore, "ServerDelegateHelper.saveDataFile");
+    }
+
+}

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



Mime
View raw message