geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sppa...@apache.org
Subject svn commit: r463118 - in /geronimo/devtools/eclipse-plugin/trunk/plugins: org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/ org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/ org.apache.geronimo.st.v11.core/src/org/apach...
Date Thu, 12 Oct 2006 03:02:55 GMT
Author: sppatel
Date: Wed Oct 11 20:02:53 2006
New Revision: 463118

URL: http://svn.apache.org/viewvc?view=rev&rev=463118
Log:
sharedlib processd for all projects before publishing

Modified:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GeronimoServerBehaviourDelegate.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/ISharedLibEntryCreationDataModelProperties.java
    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.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryDataModelProvider.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/GeronimoServerBehaviourDelegate.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GeronimoServerBehaviourDelegate.java?view=diff&rev=463118&r1=463117&r2=463118
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GeronimoServerBehaviourDelegate.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GeronimoServerBehaviourDelegate.java
Wed Oct 11 20:02:53 2006
@@ -39,10 +39,14 @@
 import org.apache.geronimo.st.core.commands.IDeploymentCommand;
 import org.apache.geronimo.st.core.internal.Messages;
 import org.apache.geronimo.st.core.internal.Trace;
+import org.apache.geronimo.st.core.operations.ISharedLibEntryCreationDataModelProperties;
+import org.apache.geronimo.st.core.operations.SharedLibEntryCreationOperation;
+import org.apache.geronimo.st.core.operations.SharedLibEntryDataModelProvider;
 import org.apache.geronimo.xbeans.eclipse.deployment.ModuleDocument;
 import org.apache.geronimo.xbeans.eclipse.deployment.ChildrenDocument.Children;
 import org.apache.geronimo.xbeans.eclipse.deployment.ModuleDocument.Module;
 import org.apache.xmlbeans.XmlOptions;
+import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
@@ -58,6 +62,7 @@
 import org.eclipse.debug.core.ILaunch;
 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
 import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.jdt.core.IClasspathEntry;
 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
 import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
 import org.eclipse.jdt.launching.IVMInstall;
@@ -67,11 +72,15 @@
 import org.eclipse.wst.common.componentcore.internal.resources.VirtualArchiveComponent;
 import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
 import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
+import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
 import org.eclipse.wst.server.core.IModule;
 import org.eclipse.wst.server.core.IServer;
 import org.eclipse.wst.server.core.IServerListener;
 import org.eclipse.wst.server.core.ServerEvent;
 import org.eclipse.wst.server.core.ServerPort;
+import org.eclipse.wst.server.core.internal.ProgressUtil;
 import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
 import org.eclipse.wst.server.core.util.SocketUtil;
 
@@ -177,6 +186,33 @@
 		if (state == IServer.STATE_STARTING || state == IServer.STATE_STOPPING)
 			terminate();
 	}
+	
+	/* 
+	 * Override this method to be able to process in-place shared lib entries and restart the
shared lib configuration for all projects prior
+	 * to publishing each IModule.
+	 * 
+	 * (non-Javadoc)
+	 * @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) {
+		IStatus status = Status.OK_STATUS;
+		if (modules != null && modules.size() > 0 && getGeronimoServer().isInPlaceSharedLib())
{
+			List rootModules = new ArrayList();
+			for(int i = 0; i < modules.size(); i++) {
+				IModule[] module = (IModule[]) modules.get(i);
+				if(!rootModules.contains(module[0])) {
+					rootModules.add(module[0]);
+				}
+			}
+			IModule[] toProcess = (IModule[])rootModules.toArray(new IModule[rootModules.size()]);
+			status = updateSharedLib(toProcess, monitor);
+		}
+		if(status.isOK()) {
+			super.publishModules(kind, modules, deltaKind, multi, monitor);
+		} else {
+			multi.add(status);
+		}
+	}
 
 	/*
 	 * (non-Javadoc)
@@ -709,6 +745,19 @@
 	
 	public String getConfigId(IModule module) {
 		return getGeronimoServer().getVersionHandler().getConfigID(module);
+	}
+	
+	private IStatus updateSharedLib(IModule[] module, IProgressMonitor monitor) {
+		IDataModel model = DataModelFactory.createDataModel(new SharedLibEntryDataModelProvider());
+		model.setProperty(ISharedLibEntryCreationDataModelProperties.MODULES, module);
+		model.setProperty(ISharedLibEntryCreationDataModelProperties.SERVER, getServer());
+		IDataModelOperation op = new SharedLibEntryCreationOperation(model);
+		try {
+			op.execute(monitor, null);
+		} catch (ExecutionException e) {
+			return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getMessage(), e.getCause());
+		}
+		return Status.OK_STATUS;
 	}
 	
 }

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/ISharedLibEntryCreationDataModelProperties.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/ISharedLibEntryCreationDataModelProperties.java?view=diff&rev=463118&r1=463117&r2=463118
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/ISharedLibEntryCreationDataModelProperties.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/ISharedLibEntryCreationDataModelProperties.java
Wed Oct 11 20:02:53 2006
@@ -19,7 +19,7 @@
 
 public interface ISharedLibEntryCreationDataModelProperties extends IDataModelProperties
{
 
-	public static final String MODULE = "ISharedLibEntryCreationDataModelProperties.MODULE";
-	public static final String SERVER = "ISharedLibEntryCreationDataModelProperties.SERVER";
+	public static final String MODULES = "ISharedLibEntryCreationDataModelProperties.MODULE";
//array of IModules
+	public static final String SERVER = "ISharedLibEntryCreationDataModelProperties.SERVER";
//IServer
 	
 }

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=463118&r1=463117&r2=463118
==============================================================================
--- 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
Wed Oct 11 20:02:53 2006
@@ -16,10 +16,17 @@
 package org.apache.geronimo.st.core.operations;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.jar.Attributes;
@@ -35,6 +42,7 @@
 import javax.management.ObjectInstance;
 import javax.management.ObjectName;
 
+import org.apache.geronimo.st.core.Activator;
 import org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate;
 import org.apache.geronimo.st.core.GeronimoUtils;
 import org.apache.geronimo.st.core.commands.DeploymentCommandFactory;
@@ -65,6 +73,8 @@
 	private TargetModuleID sharedLibTarget;
 	private IServer server;
 	private IProgressMonitor monitor;
+	private IPath sharedLibLocation;
+	private static final IPath TEMP_LOCATION = Activator.getDefault().getStateLocation().append("shared-lib-temp");
 
 	public SharedLibEntryCreationOperation() {
 	}
@@ -86,80 +96,119 @@
 		Trace.trace(Trace.INFO, ">> SharedLibEntryCreationOperation.execute()");
 		
 		this.monitor = monitor;
-		IModule module = (IModule) model.getProperty(MODULE);
+		IModule[] modules = (IModule[]) model.getProperty(MODULES);
 		this.server = (IServer) model.getProperty(SERVER);
 		
-		IProject project = module.getProject();
+		HashMap addList = new HashMap();
+		List deleteList = new ArrayList();
 		
 		try {
-			// locate the path of the first sharedlib library folder
-			String sharedLibPath = null;
-			GeronimoServerBehaviourDelegate gsDelegate = (GeronimoServerBehaviourDelegate) server.getAdapter(GeronimoServerBehaviourDelegate.class);
-			MBeanServerConnection connection = gsDelegate.getServerConnection();
-			Set result = connection.queryMBeans(new ObjectName("*:j2eeType=GBean,name=SharedLib,*"),
null);
-			if (!result.isEmpty()) {
-				ObjectInstance instance = (ObjectInstance) result.toArray()[0];
-				String[] libDirs = (String[]) connection.getAttribute(instance.getObjectName(),"libDirs");
-				if (libDirs != null && libDirs.length > 0) {
-					sharedLibPath = libDirs[0];
-				}
-			}
-			
+			String sharedLibPath = getSharedLibPath();
 			if(sharedLibPath == null) 
 				return Status.CANCEL_STATUS;
 			
-			// determine the absolute path of the dummy jar
-			String dummyJarName = project.getName() + ".eclipse.jar";
-			File dummyJarFile = server.getRuntime().getLocation().append(sharedLibPath).append(dummyJarName).toFile();
-
-			// delete the dummy jar and return if module no longer associated
-			// with server
-			if (!ServerUtil.containsModule(server, module, monitor)) {
-				if (dummyJarFile.exists()) {
-					stopSharedLib();
-					delete(dummyJarFile);
-					startSharedLib();
-					return Status.OK_STATUS;
+			sharedLibLocation = server.getRuntime().getLocation().append(sharedLibPath);
+			
+			for(int i = 0; i < modules.length; i++) {
+				IModule module = modules[i];
+				IProject project = module.getProject();
+				
+				File dummyJarFile = sharedLibLocation.append(project.getName() + ".eclipse.jar").toFile();
+				// delete the dummy jar if module no longer associated with server
+				if (!ServerUtil.containsModule(server, module, monitor) && dummyJarFile.exists())
{
+					deleteList.add(dummyJarFile);
 				} else {
-					// don't need to recycle shared lib
-					return Status.CANCEL_STATUS;
+					HashSet entries = new HashSet();
+					J2EEFlexProjDeployable j2eeModule = (J2EEFlexProjDeployable) module.loadAdapter(J2EEFlexProjDeployable.class,
null);
+					if(GeronimoUtils.isEarModule(module)) {
+						IModule[] childModules = j2eeModule.getChildModules();
+						for(int j = 0; j < modules.length; j++) {
+							entries.addAll(processModule(childModules[i]));
+						}
+					} else {
+						entries.addAll(processModule(module));
+					}
+
+					// regen the jar only if required
+					if (regenerate(dummyJarFile, entries)) {
+						TEMP_LOCATION.toFile().mkdirs();
+						File temp = TEMP_LOCATION.append(project.getName() + ".eclipse.jar").toFile();
+						Trace.trace(Trace.INFO, "Updating external sharedlib entries for " + module.getName());
+						if(temp.exists())
+							delete(temp);
+						Manifest manifest = new Manifest();
+						Attributes attributes = manifest.getMainAttributes();
+						attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
+						attributes.put(Attributes.Name.CLASS_PATH, getCPEntriesAsString(entries));
+						JarOutputStream os = new JarOutputStream(new FileOutputStream(temp), manifest);
+						os.flush();
+						os.close();
+						addList.put(temp, dummyJarFile);
+					}
 				}
 			}
 			
-			HashSet entries = new HashSet();
-			J2EEFlexProjDeployable j2eeModule = (J2EEFlexProjDeployable) module.loadAdapter(J2EEFlexProjDeployable.class,
null);
-			if(GeronimoUtils.isEarModule(module)) {
-				IModule[] modules = j2eeModule.getChildModules();
-				for(int i = 0; i < modules.length; i++) {
-					entries.addAll(processModule(modules[i]));
-				}
-			} else {
-				entries.addAll(processModule(module));
-			}
+			updateAndRecycleSharedLib(addList, deleteList);
 			
-			// regen the jar only if required
-			if (regenerate(dummyJarFile, entries)) {
-				stopSharedLib();
-				Trace.trace(Trace.INFO, "Updating external sharedlib entries for " + module.getName());
-				if(dummyJarFile.exists())
-					delete(dummyJarFile);
-				Manifest manifest = new Manifest();
-				Attributes attributes = manifest.getMainAttributes();
-				attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
-				attributes.put(Attributes.Name.CLASS_PATH, getCPEntriesAsString(entries));
-				JarOutputStream os = new JarOutputStream(new FileOutputStream(dummyJarFile), manifest);
-				os.flush();
-				os.close();
-				startSharedLib();
-			}
 		} catch (Exception e) {
 			Trace.trace(Trace.SEVERE, "Failure in updating shared library.", e);
 			throw new ExecutionException("Failure in updating shared library", e);
 		} 
 		
 		Trace.trace(Trace.INFO, "<< SharedLibEntryCreationOperation.execute()");
-		
 		return Status.OK_STATUS;
+	}
+	
+	private void updateAndRecycleSharedLib(HashMap addList, List deleteList) throws Exception
{
+		if(addList.size() > 0 || deleteList.size() > 0) {
+			stopSharedLib();
+			for(int i = 0; i < deleteList.size(); i++) {
+				File file = (File) deleteList.get(i);
+				delete(file);
+			}
+			Iterator i = addList.keySet().iterator();
+			while(i.hasNext()) {
+				File src = (File) i.next();
+				File dest = (File) addList.get(src);
+				if(dest.exists()) {
+					delete(dest);
+				}
+				copy(src, dest);
+			}
+			startSharedLib();
+		}
+	}
+	
+	private void copy(File src, File dest) throws Exception {
+		try {
+			InputStream in = new FileInputStream(src);
+			OutputStream out = new FileOutputStream(dest);
+			byte[] buf = new byte[1024];
+			int len;
+			while ((len = in.read(buf)) > 0) {
+				out.write(buf, 0, len);
+			}
+			in.close();
+			out.close();
+		} catch (Exception e) {
+			throw e;
+		}
+		Trace.trace(Trace.INFO, "Created " + dest.getAbsolutePath());
+	}
+
+	private String getSharedLibPath() throws Exception {
+		// locate the path of the first sharedlib library folder
+		GeronimoServerBehaviourDelegate gsDelegate = (GeronimoServerBehaviourDelegate) server.getAdapter(GeronimoServerBehaviourDelegate.class);
+		MBeanServerConnection connection = gsDelegate.getServerConnection();
+		Set result = connection.queryMBeans(new ObjectName("*:j2eeType=GBean,name=SharedLib,*"),
null);
+		if (!result.isEmpty()) {
+			ObjectInstance instance = (ObjectInstance) result.toArray()[0];
+			String[] libDirs = (String[]) connection.getAttribute(instance.getObjectName(),"libDirs");
+			if (libDirs != null && libDirs.length > 0) {
+				return libDirs[0];
+			}
+		}
+		return null;
 	}
 	
 	private HashSet processModule(IModule module) throws Exception {

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryDataModelProvider.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/SharedLibEntryDataModelProvider.java?view=diff&rev=463118&r1=463117&r2=463118
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryDataModelProvider.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryDataModelProvider.java
Wed Oct 11 20:02:53 2006
@@ -29,7 +29,7 @@
 	 */
 	public Set getPropertyNames() {
 		Set names = super.getPropertyNames();
-		names.add(MODULE);
+		names.add(MODULES);
 		names.add(SERVER);
 		return names;
 	}

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=463118&r1=463117&r2=463118
==============================================================================
--- 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
Wed Oct 11 20:02:53 2006
@@ -34,21 +34,10 @@
 import org.apache.geronimo.st.core.Activator;
 import org.apache.geronimo.st.core.GeronimoConnectionFactory;
 import org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate;
-import org.apache.geronimo.st.core.IGeronimoServer;
-import org.apache.geronimo.st.core.operations.ISharedLibEntryCreationDataModelProperties;
-import org.apache.geronimo.st.core.operations.SharedLibEntryCreationOperation;
-import org.apache.geronimo.st.core.operations.SharedLibEntryDataModelProvider;
 import org.apache.geronimo.st.v11.core.internal.Trace;
 import org.apache.geronimo.system.jmx.KernelDelegate;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Status;
-import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
 import org.eclipse.wst.server.core.IModule;
 import org.eclipse.wst.server.core.IServer;
 import org.eclipse.wst.server.core.internal.IModulePublishHelper;
@@ -190,56 +179,5 @@
 	 */
 	protected ClassLoader getContextClassLoader() {
 		return Kernel.class.getClassLoader();
-	}
-
-	/* (non-Javadoc)
-	 * @see org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate#doAdded(org.eclipse.wst.server.core.IModule,
java.lang.String)
-	 */
-	protected void doAdded(IModule module, String configId) throws Exception {
-		updateSharedLib(module);
-		super.doAdded(module, configId);
-
-	}
-
-	/* (non-Javadoc)
-	 * @see org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate#doChanged(org.eclipse.wst.server.core.IModule,
java.lang.String)
-	 */
-	protected void doChanged(IModule module, String configId) throws Exception {
-		updateSharedLib(module);
-		super.doChanged(module, configId);
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate#doUndeploy(org.eclipse.wst.server.core.IModule)
-	 */
-	protected void doRemoved(IModule module) throws Exception {
-		super.doRemoved(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;
-		}
-		
-		IDataModel model = DataModelFactory.createDataModel(new SharedLibEntryDataModelProvider());
-		model.setProperty(ISharedLibEntryCreationDataModelProperties.MODULE, module);
-		model.setProperty(ISharedLibEntryCreationDataModelProperties.SERVER, getServer());
-		IDataModelOperation op = new SharedLibEntryCreationOperation(model);
-		try {
-			op.execute(_monitor, null);
-		} catch (ExecutionException e) {
-			throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getMessage(),
e.getCause()));
-		}
 	}
 }



Mime
View raw message