You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by sp...@apache.org on 2006/09/19 20:42:28 UTC

svn commit: r447927 - in /geronimo/devtools/eclipse-plugin/trunk/plugins: org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/ org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/

Author: sppatel
Date: Tue Sep 19 11:42:27 2006
New Revision: 447927

URL: http://svn.apache.org/viewvc?view=rev&rev=447927
Log:
stop sharedlib before updating to avoid windows file locking, check if sharedlib entries need update on NO_CHANGE

Modified:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryCreationOperation.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerBehaviour.java

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryCreationOperation.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryCreationOperation.java?view=diff&rev=447927&r1=447926&r2=447927
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryCreationOperation.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryCreationOperation.java Tue Sep 19 11:42:27 2006
@@ -27,11 +27,16 @@
 import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
 
+import javax.enterprise.deploy.spi.DeploymentManager;
+import javax.enterprise.deploy.spi.TargetModuleID;
+import javax.enterprise.deploy.spi.status.DeploymentStatus;
+import javax.enterprise.deploy.spi.status.ProgressObject;
 import javax.management.MBeanServerConnection;
 import javax.management.ObjectInstance;
 import javax.management.ObjectName;
 
 import org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate;
+import org.apache.geronimo.st.core.commands.DeploymentCommandFactory;
 import org.apache.geronimo.st.core.internal.Trace;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.resources.IProject;
@@ -53,6 +58,9 @@
 import org.eclipse.wst.server.core.model.ModuleDelegate;
 
 public class SharedLibEntryCreationOperation extends AbstractDataModelOperation implements ISharedLibEntryCreationDataModelProperties {
+	
+	private TargetModuleID sharedLibTarget;
+	private IServer server;
 
 	public SharedLibEntryCreationOperation() {
 	}
@@ -72,7 +80,7 @@
 	 */
 	public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
 		IModule module = (IModule) model.getProperty(MODULE);
-		IServer server = (IServer) model.getProperty(SERVER);
+		this.server = (IServer) model.getProperty(SERVER);
 		
 		//TODO process child modules if ear project
 		
@@ -101,7 +109,10 @@
 
 			// delete the dummy jar and return if module no longer associated with server 
 			if (!ServerUtil.containsModule(server, module, monitor)) {
-				if (dummyJarFile.delete()) {
+				if (dummyJarFile.exists()) {
+					stopSharedLib();
+					delete(dummyJarFile);
+					startSharedLib();
 					return Status.OK_STATUS;
 				} else {
 					// don't need to recycle shared lib
@@ -134,8 +145,10 @@
 
 			// regen the jar only if required
 			if (regenerate(dummyJarFile, entries)) {
+				stopSharedLib();
 				Trace.trace(Trace.INFO, "Updating external sharedlib entries for " + module.getName());
-				dummyJarFile.delete();
+				if(dummyJarFile.exists())
+					delete(dummyJarFile);
 				Manifest manifest = new Manifest();
 				Attributes attributes = manifest.getMainAttributes();
 				attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
@@ -143,6 +156,7 @@
 				JarOutputStream os = new JarOutputStream(new FileOutputStream(dummyJarFile), manifest);
 				os.flush();
 				os.close();
+				startSharedLib();
 			} else {
 				return Status.CANCEL_STATUS;
 			}
@@ -153,6 +167,14 @@
 		return Status.OK_STATUS;
 	}
 
+	private void delete(File dummyJarFile) {
+		if(dummyJarFile.delete()) {
+			Trace.trace(Trace.INFO, dummyJarFile.getAbsolutePath() + " deleted sucessfully.");
+		} else {
+			Trace.trace(Trace.SEVERE, "Failed to delete " + dummyJarFile.getAbsolutePath(), null);
+		}
+	}
+
 	private void processJavaProject(IProject project, HashSet entries, boolean includeOutputLocations) throws JavaModelException {
 		IJavaProject jp = JavaCore.create(project);
 		IClasspathEntry[] cp = jp.getRawClasspath();
@@ -257,5 +279,59 @@
 		}
 
 		return !entries.isEmpty();
+	}
+	
+	private void stopSharedLib() throws Exception {
+		DeploymentManager dm = DeploymentCommandFactory.getDeploymentManager(server);
+		TargetModuleID id = getSharedLibTargetModuleID();
+		TargetModuleID[] ids = new TargetModuleID[]{id};
+		ProgressObject po = dm.stop(ids);
+		waitForProgress(po);
+		if(po.getDeploymentStatus().isFailed()) {
+			throw new Exception(po.getDeploymentStatus().getMessage());
+		} 
+	}
+	
+	private void startSharedLib() throws Exception {
+		DeploymentManager dm = DeploymentCommandFactory.getDeploymentManager(server);
+		TargetModuleID id = getSharedLibTargetModuleID();
+		ProgressObject po = dm.start(new TargetModuleID[]{id});
+		waitForProgress(po);
+		if(po.getDeploymentStatus().isFailed()) {
+			throw new Exception(po.getDeploymentStatus().getMessage());
+		} 
+	}
+	
+	private TargetModuleID getSharedLibTargetModuleID() throws Exception {
+		if(sharedLibTarget == null) {
+			DeploymentManager dm = DeploymentCommandFactory.getDeploymentManager(server);
+			TargetModuleID[] ids = dm.getAvailableModules(null, dm.getTargets());
+			for(int i = 0; i < ids.length; i++) {
+				if(ids[i].getModuleID().indexOf("sharedlib") > 0) {
+					sharedLibTarget = ids[i];
+					break;
+				}
+			}	
+		}
+		
+		if(sharedLibTarget == null) {
+			throw new Exception("Could not determine SharedLib TargetModuleID.");
+		}
+		
+		return sharedLibTarget;
+	}
+
+	private void waitForProgress(ProgressObject po) {
+		while (po.getDeploymentStatus().isRunning()) {
+			try {
+				Thread.sleep(100);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}
+		DeploymentStatus status = po.getDeploymentStatus();
+		String command = status.getCommand().toString();
+		String state = status.getState().toString();
+		Trace.trace(Trace.INFO, "SharedLib " + " " + command + " " + state);
 	}
 }

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerBehaviour.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerBehaviour.java?view=diff&rev=447927&r1=447926&r2=447927
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerBehaviour.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerBehaviour.java Tue Sep 19 11:42:27 2006
@@ -18,9 +18,7 @@
 import java.net.URL;
 import java.util.Set;
 
-import javax.enterprise.deploy.spi.DeploymentManager;
 import javax.enterprise.deploy.spi.TargetModuleID;
-import javax.enterprise.deploy.spi.status.ProgressObject;
 import javax.management.MBeanServerConnection;
 import javax.naming.directory.NoSuchAttributeException;
 
@@ -35,9 +33,11 @@
 import org.apache.geronimo.kernel.config.PersistentConfigurationList;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.st.core.Activator;
+import org.apache.geronimo.st.core.DeploymentUtils;
 import org.apache.geronimo.st.core.GeronimoConnectionFactory;
 import org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate;
 import org.apache.geronimo.st.core.commands.DeploymentCommandFactory;
+import org.apache.geronimo.st.core.commands.TargetModuleIdNotFoundException;
 import org.apache.geronimo.st.core.operations.ISharedLibEntryCreationDataModelProperties;
 import org.apache.geronimo.st.core.operations.SharedLibEntryCreationOperation;
 import org.apache.geronimo.st.core.operations.SharedLibEntryDataModelProvider;
@@ -235,9 +235,16 @@
 		super.doUndeploy(module);
 		updateSharedLib(module);
 	}
+	
+	/* (non-Javadoc)
+	 * @see org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate#doNoChange(org.eclipse.wst.server.core.IModule)
+	 */
+	protected void doNoChange(IModule module) throws Exception {
+		updateSharedLib(module);
+		super.doNoChange(module);
+	}
 
 	private void updateSharedLib(IModule module) throws CoreException {
-		
 		if(isRemote() || !getGeronimoServer().isInPlaceSharedLib()) {
 			return;
 		}
@@ -247,52 +254,9 @@
 		model.setProperty(ISharedLibEntryCreationDataModelProperties.SERVER, getServer());
 		IDataModelOperation op = new SharedLibEntryCreationOperation(model);
 		try {
-			IStatus status = op.execute(new NullProgressMonitor(), null);
-			if (status.isOK()) {
-				DeploymentManager dm = DeploymentCommandFactory.getDeploymentManager(getServer());
-				TargetModuleID id = null;
-				try {
-					TargetModuleID[] ids = dm.getAvailableModules(null, dm.getTargets());
-					for(int i = 0; i < ids.length; i++) {
-						if(ids[i].getModuleID().indexOf("sharedlib") > 0) {
-							id = ids[i];
-							break;
-						}
-					}	
-				} catch (Exception e) {
-					e.printStackTrace();
-				} 
-				
-				if(id != null) {
-					TargetModuleID[] ids = new TargetModuleID[]{id};
-					ProgressObject po = dm.stop(ids);
-					waitForProgress(po);
-					if(po.getDeploymentStatus().isCompleted()) {
-						Trace.trace(Trace.INFO, id.getModuleID() + " stopped.");
-					}
-					
-					po = dm.start(ids);
-					waitForProgress(po);
-					
-					if(po.getDeploymentStatus().isCompleted()) {
-						Trace.trace(Trace.INFO, id.getModuleID() + " started.");
-					}
-				}
-			}
+			op.execute(new NullProgressMonitor(), null);
 		} catch (ExecutionException e) {
-			throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Error updating shared lib configuration.", e));
-		}
-	}
-
-	protected void waitForProgress(ProgressObject po) throws CoreException {
-		while (po.getDeploymentStatus().isRunning()) {
-			try {
-				Thread.sleep(100);
-			} catch (InterruptedException e) {
-				e.printStackTrace();
-			}
+			throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getMessage(), e.getCause()));
 		}
-		return;
 	}
-
 }