geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sppa...@apache.org
Subject svn commit: r440863 - 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/
Date Wed, 06 Sep 2006 20:47:40 GMT
Author: sppatel
Date: Wed Sep  6 13:47:39 2006
New Revision: 440863

URL: http://svn.apache.org/viewvc?view=rev&rev=440863
Log:
GERONIMO-2324 first drop.. allow sharedlib entries in place

Added:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/ISharedLibEntryCreationDataModelProperties.java
  (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryCreationOperation.java
  (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryDataModelProvider.java
  (with props)
Modified:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerBehaviour.java

Added: 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=auto&rev=440863
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/ISharedLibEntryCreationDataModelProperties.java
(added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/ISharedLibEntryCreationDataModelProperties.java
Wed Sep  6 13:47:39 2006
@@ -0,0 +1,24 @@
+/**
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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.core.operations;
+
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelProperties;
+
+public interface ISharedLibEntryCreationDataModelProperties extends IDataModelProperties
{
+
+	public static final String MODULE = "ISharedLibEntryCreationDataModelProperties.MODULE";
+	
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/ISharedLibEntryCreationDataModelProperties.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/ISharedLibEntryCreationDataModelProperties.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/ISharedLibEntryCreationDataModelProperties.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 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=auto&rev=440863
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryCreationOperation.java
(added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryCreationOperation.java
Wed Sep  6 13:47:39 2006
@@ -0,0 +1,190 @@
+/**
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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.core.operations;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jst.server.core.FacetUtil;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IModuleType;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerUtil;
+
+public class SharedLibEntryCreationOperation extends AbstractDataModelOperation implements
ISharedLibEntryCreationDataModelProperties {
+
+	public SharedLibEntryCreationOperation() {
+	}
+
+	/**
+	 * @param model
+	 */
+	public SharedLibEntryCreationOperation(IDataModel model) {
+		super(model);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor,
+	 *      org.eclipse.core.runtime.IAdaptable)
+	 */
+	public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException
{
+		IModule module = (IModule) model.getProperty(MODULE);
+		
+		//TODO process child modules if ear project
+		
+		IProject project = module.getProject();
+		try {
+
+			// determine the dummy jar path from project name and runtime
+			// location
+			IFacetedProject fp = ProjectFacetsManager.create(project);
+			IRuntime runtime = FacetUtil.getRuntime(fp.getPrimaryRuntime());
+			String dummyJarName = project.getName() + ".eclipse.jar";
+			File dummyJarFile = runtime.getLocation().append("var/shared/lib").append((dummyJarName)).toFile();
+
+			// delete the dummy jar and return if module no longer associated
+			// with server with the same runtime
+			boolean delete = true;
+			IServer[] servers = ServerUtil.getServersByModule(module, monitor);
+			for (int i = 0; i < servers.length; i++) {
+				if (runtime.equals(servers[i].getRuntime())) {
+					delete = false;
+					break;
+				}
+			}
+			if (delete) {
+				if (dummyJarFile.delete()) {
+					return Status.OK_STATUS;
+				} else {
+					// don't need to recycle shared lib
+					return Status.CANCEL_STATUS;
+				}
+			}
+
+			// filter the cp entries needed to be added to the dummy shared lib
+			// jar
+			HashSet entries = new HashSet();
+			IJavaProject jp = JavaCore.create(project);
+			IClasspathEntry[] cp = jp.getRawClasspath();
+			for (int i = 0; i < cp.length; i++) {
+				IClasspathEntry entry = cp[i];
+				int kind = entry.getEntryKind();
+				if (kind == IClasspathEntry.CPE_LIBRARY
+						|| kind == IClasspathEntry.CPE_VARIABLE) {
+					if (kind == IClasspathEntry.CPE_VARIABLE) {
+						// TODO exclude and return if web-inf/lib entries
+					}
+					IClasspathEntry resolved = JavaCore.getResolvedClasspathEntry(entry);
+					entries.add(resolved.getPath().makeAbsolute().toOSString());
+				}
+			}
+
+			// Set entries = (Set) model.getProperty(CP_ENTRIES);
+			// regen the jar only if required
+			if (regenerate(dummyJarFile, entries)) {
+				dummyJarFile.delete();
+				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();
+			} else {
+				return Status.CANCEL_STATUS;
+			}
+		} catch (Exception e) {
+			throw new ExecutionException("Failed to update shared lib.", e);
+		}
+
+		return Status.OK_STATUS;
+	}
+
+	/**
+	 * @param entries
+	 * @return
+	 */
+	private String getCPEntriesAsString(Set entries) {
+		StringBuffer buffer = new StringBuffer();
+		Iterator i = entries.iterator();
+		while (i.hasNext()) {
+			String cpEntry = (String) i.next();
+			buffer.append(cpEntry);
+			if (i.hasNext()) {
+				buffer.append(" ");
+			}
+		}
+		return buffer.toString();
+	}
+
+	/**
+	 * @param jarPath
+	 * @param entries
+	 * @return
+	 * @throws Exception
+	 */
+	private boolean regenerate(File jarFile, Set entries) throws Exception {
+		if (jarFile.exists()) {
+			if (entries.isEmpty()) {
+				// go ahead and return if zero entires, dummy jar will be
+				// deleted
+				return true;
+			} else {
+				JarFile jar = new JarFile(jarFile);
+				Manifest manifest = jar.getManifest();
+				Attributes attributes = manifest.getMainAttributes();
+				String value = attributes.getValue(Attributes.Name.CLASS_PATH);
+				jar.close();
+
+				Set currentEntries = new HashSet();
+				if (value != null) {
+					StringTokenizer tokenizer = new StringTokenizer(value);
+					while (tokenizer.hasMoreTokens()) {
+						currentEntries.add(tokenizer.nextToken());
+					}
+				}
+				// regen dummy jar if old and new entries don't match
+				return !entries.equals(currentEntries);
+			}
+		}
+
+		return !entries.isEmpty();
+	}
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryCreationOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryCreationOperation.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryCreationOperation.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 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=auto&rev=440863
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryDataModelProvider.java
(added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryDataModelProvider.java
Wed Sep  6 13:47:39 2006
@@ -0,0 +1,42 @@
+/**
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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.core.operations;
+
+import java.util.Set;
+
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
+
+public class SharedLibEntryDataModelProvider extends AbstractDataModelProvider implements
ISharedLibEntryCreationDataModelProperties {
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider#getPropertyNames()
+	 */
+	public Set getPropertyNames() {
+		Set names = super.getPropertyNames();
+		names.add(MODULE);
+		return names;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider#getDefaultOperation()
+	 */
+	public IDataModelOperation getDefaultOperation() {
+		return new SharedLibEntryCreationOperation(model);
+	}
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryDataModelProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryDataModelProvider.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/operations/SharedLibEntryDataModelProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=440863&r1=440862&r2=440863
==============================================================================
--- 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 Sep  6 13:47:39 2006
@@ -18,11 +18,17 @@
 import java.net.URL;
 import java.util.Set;
 
-import javax.enterprise.deploy.spi.Target;
+import javax.enterprise.deploy.spi.DeploymentManager;
+import javax.enterprise.deploy.spi.TargetModuleID;
+import javax.enterprise.deploy.spi.exceptions.TargetException;
+import javax.enterprise.deploy.spi.status.ProgressEvent;
+import javax.enterprise.deploy.spi.status.ProgressListener;
+import javax.enterprise.deploy.spi.status.ProgressObject;
 import javax.management.MBeanServerConnection;
 import javax.naming.directory.NoSuchAttributeException;
 
-import org.apache.geronimo.deployment.plugin.TargetImpl;
+import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl;
+import org.apache.geronimo.deployment.util.DeploymentUtil;
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.gbean.GBeanData;
@@ -33,12 +39,25 @@
 import org.apache.geronimo.kernel.config.InvalidConfigException;
 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.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;
@@ -89,7 +108,8 @@
 			} catch (SecurityException e) {
 				throw e;
 			} catch (Exception e) {
-				Trace.trace(Trace.WARNING, "Kernel connection failed. " + e.getMessage());
+				Trace.trace(Trace.WARNING, "Kernel connection failed. "
+						+ e.getMessage());
 			}
 		}
 		return kernel;
@@ -189,4 +209,90 @@
 	protected ClassLoader getContextClassLoader() {
 		return Kernel.class.getClassLoader();
 	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate#doDeploy(org.eclipse.wst.server.core.IModule)
+	 */
+	protected void doDeploy(IModule module) throws Exception {
+		updateSharedLib(module);
+		super.doDeploy(module);
+
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate#doRedeploy(org.eclipse.wst.server.core.IModule)
+	 */
+	protected void doRedeploy(IModule module) throws Exception {
+		super.unDeploy(module);
+		updateSharedLib(module);
+		super.doDeploy((module));
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate#doUndeploy(org.eclipse.wst.server.core.IModule)
+	 */
+	protected void doUndeploy(IModule module) throws Exception {
+		super.doUndeploy(module);
+		updateSharedLib(module);
+	}
+
+	private void updateSharedLib(IModule module) throws CoreException {
+		IDataModel model = DataModelFactory.createDataModel(new SharedLibEntryDataModelProvider());
+		model.setProperty(ISharedLibEntryCreationDataModelProperties.MODULE, module);
+		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.");
+					}
+				}
+			}
+		} 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();
+			}
+		}
+		return;
+	}
+
 }



Mime
View raw message