You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by de...@apache.org on 2010/06/18 10:10:16 UTC
svn commit: r955877 [5/6] - in
/geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins:
org.apache.geronimo.runtime.common/
org.apache.geronimo.runtime.common/META-INF/
org.apache.geronimo.runtime.v20/ org.apache.geronimo.runtime.v20/META-INF/
org.apa...
Modified: geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/plugin.xml
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/plugin.xml?rev=955877&r1=955876&r2=955877&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/plugin.xml (original)
+++ geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/plugin.xml Fri Jun 18 08:10:13 2010
@@ -39,12 +39,12 @@
<serverType id="org.apache.geronimo.server.22"
name="%serverTypeName" description="%serverTypeDescription"
runtime="true"
- class="org.apache.geronimo.st.v21.core.GeronimoServer"
+ class="org.apache.geronimo.st.v22.core.GeronimoServer"
initialState="stopped" supportsRemoteHosts="true"
startTimeout="240000" stopTimeout="30000" startBeforePublish="true"
runtimeTypeId="org.apache.geronimo.runtime.22"
- launchConfigId="org.apache.geronimo.st.core.launchConfigurationType"
- behaviourClass="org.apache.geronimo.st.v21.core.GeronimoServerBehaviour"
+ launchConfigId="org.apache.geronimo.st.v22.core.launchConfigurationType"
+ behaviourClass="org.apache.geronimo.st.v22.core.GeronimoServerBehaviour"
hasConfiguration="false" launchModes="run,debug,profile">
</serverType>
</extension>
@@ -112,4 +112,37 @@
</default-facets>
</extension>
+ <extension
+ point="org.apache.geronimo.st.v21.core.geronimoinfo">
+ <provider
+ class="org.apache.geronimo.st.v22.core.GeronimoV22ServerInfo"
+ versions="2.2">
+ </provider>
+ </extension>
+
+ <extension
+ point="org.eclipse.hyades.trace.ui.launchConfigMechanismAssociator">
+ <association
+ launchConfigID = "org.apache.geronimo.st.v22.core.launchConfigurationType">
+
+ <mechanism mechanismID = "org.eclipse.tptp.trace.ui.jvmpiMechanism">
+ <configuration
+ launchDelegate = "org.eclipse.tptp.trace.ui.internal.launcher.deleg.application.PIAttachLauncherDelegate"
+ configurationId = "org.eclipse.tptp.trace.ui.jvmpiConfiguration"
+ associatedAgent = "org.eclipse.tptp.trace.ui.jvmpiAgent"
+ filter = "org.eclipse.tptp.platform.profile.server.core.internal.PICollectorFiltration">
+ </configuration>
+ </mechanism>
+
+ <mechanism mechanismID = "org.eclipse.tptp.trace.jvmti.jvmtiMechanism">
+ <configuration
+ launchDelegate = "org.eclipse.tptp.platform.jvmti.client.internal.launcher.TIAttachLauncherDelegate"
+ configurationId = "org.eclipse.tptp.trace.jvmti.tiConfiguration"
+ associatedAgent = "org.eclipse.tptp.platform.jvmti.TIAgent"
+ filter = "org.eclipse.tptp.platform.profile.server.core.internal.TICollectorFiltration">
+ </configuration>
+ </mechanism>
+ </association>
+ </extension>
+
</plugin>
Added: geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/GeronimoServer.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/GeronimoServer.java?rev=955877&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/GeronimoServer.java (added)
+++ geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/GeronimoServer.java Fri Jun 18 08:10:13 2010
@@ -0,0 +1,207 @@
+/*
+ * 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.v22.core;
+
+import java.io.File;
+import javax.enterprise.deploy.spi.DeploymentManager;
+import javax.enterprise.deploy.spi.factories.DeploymentFactory;
+
+import org.apache.geronimo.deployment.plugin.factories.DeploymentFactoryImpl;
+import org.apache.geronimo.deployment.plugin.jmx.JMXDeploymentManager;
+import org.apache.geronimo.st.core.GeronimoRuntimeDelegate;
+import org.apache.geronimo.st.v21.core.GeronimoServerDelegate;
+import org.apache.geronimo.st.v21.core.GeronimoV21Utils;
+import org.apache.geronimo.st.v21.core.IGeronimoVersionHandler;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.launching.IVMInstall;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jdt.launching.LibraryLocation;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.util.SocketUtil;
+
+/**
+ * @version $Rev: 554980 $ $Date: 2007-07-10 11:35:58 -0400 (Tue, 10 Jul 2007) $
+ */
+public class GeronimoServer extends GeronimoServerDelegate {
+
+ public static final String PROPERTY_IN_PLACE_SHARED_LIB = "inPlaceSharedLib";
+ public static final String PROPERTY_RUN_FROM_WORKSPACE = "runFromWorkspace";
+
+ private static IGeronimoVersionHandler versionHandler = null;
+
+ private static DeploymentFactory deploymentFactory;
+
+ static {
+ deploymentFactory = new DeploymentFactoryImpl();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.geronimo.st.core.GenericGeronimoServer#getContextRoot(org.eclipse.wst.server.core.IModule)
+ */
+ public String getContextRoot(IModule module) throws Exception {
+ return GeronimoV21Utils.getContextRoot(module);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.geronimo.st.v21.core.IGeronimoServer#getDeployerURL()
+ */
+ public String getDeployerURL() {
+ return "deployer:geronimo:jmx://" + getServer().getHost() + ":" + getRMINamingPort();
+ }
+
+ @Override
+ public String getVMArgs() {
+ String superVMArgs = super.getVMArgs();
+ if (superVMArgs != null && superVMArgs.trim().length() > 0) {
+ return superVMArgs;
+ }
+
+ String runtimeLocation = getServer().getRuntime().getLocation().toString();
+ GeronimoRuntimeDelegate geronimoRuntimeDelegate = (GeronimoRuntimeDelegate) getServer().getRuntime().getAdapter(GeronimoRuntimeDelegate.class);
+ if (geronimoRuntimeDelegate == null) {
+ geronimoRuntimeDelegate = (GeronimoRuntimeDelegate) getServer().getRuntime().loadAdapter(GeronimoRuntimeDelegate.class,new NullProgressMonitor());
+ }
+ IVMInstall vmInstall = geronimoRuntimeDelegate.getVMInstall();
+
+ LibraryLocation[] libLocations = JavaRuntime.getLibraryLocations(vmInstall);
+ IPath vmLibDir = null;
+ for(int i = 0; i < libLocations.length; i++) {
+ LibraryLocation loc = libLocations[i];
+ IPath libDir = loc.getSystemLibraryPath().removeLastSegments(2);
+ if(libDir.toOSString().endsWith("lib")) {
+ vmLibDir = libDir;
+ break;
+ }
+ }
+
+ String cp = System.getProperty("path.separator");
+
+ //-javaagent:"GERONIMO_BASE/bin/jpa.jar"
+ String javaagent = "";
+ File jpaJar = new File(runtimeLocation + "/bin/jpa.jar");
+ if (jpaJar.exists()) {
+ javaagent = "-javaagent:\"" + runtimeLocation + "/bin/jpa.jar\"";
+ }
+
+ //-Djava.ext.dirs="GERONIMO_BASE/lib/ext;JRE_HOME/lib/ext"
+ String javaExtDirs = "-Djava.ext.dirs=\"" + runtimeLocation + "/lib/ext" + cp + vmLibDir.append("ext").toOSString() + "\"";
+
+ //-Djava.endorsed.dirs="GERONIMO_BASE/lib/endorsed;JRE_HOME/lib/endorsed"
+ String javaEndorsedDirs = "-Djava.endorsed.dirs=\"" + runtimeLocation + "/lib/endorsed" + cp + vmLibDir.append("endorsed").toOSString() + "\"";
+
+ // Specify the minimum memory options for the Geronimo server
+ String memoryOpts = "-Xms256m -Xmx512m -XX:MaxPermSize=128m";
+
+ // Specify GERONIMO_BASE
+ String homeDirectory = "-Dorg.apache.geronimo.home.dir=\"" + runtimeLocation;
+
+ return javaagent + " " + javaExtDirs + " " + javaEndorsedDirs + " " + memoryOpts + " " + homeDirectory;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.geronimo.st.v21.core.IGeronimoServer#getJMXServiceURL()
+ */
+ public String getJMXServiceURL() {
+ String host = getServer().getHost();
+ return "service:jmx:rmi://" + host + "/jndi/rmi://" + host + ":" + getRMINamingPort() + "/JMXConnector";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.geronimo.st.v21.core.IGeronimoServer#getJSR88DeployerJar()
+ */
+ public IPath getJSR88DeployerJar() {
+ return getServer().getRuntime().getLocation().append("/lib/jsr88-deploymentfactory.jar");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.geronimo.st.v21.core.IGeronimoServer#getDeploymentFactory()
+ */
+ public DeploymentFactory getDeploymentFactory() {
+ return deploymentFactory;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.geronimo.st.v21.core.IGeronimoServer#configureDeploymentManager(javax.enterprise.deploy.spi.DeploymentManager)
+ */
+ public void configureDeploymentManager(DeploymentManager dm) {
+ ((JMXDeploymentManager) dm).setLogConfiguration(true, true);
+ boolean enableInPlace = SocketUtil.isLocalhost(getServer().getHost()) && isRunFromWorkspace();
+ setInPlaceDeployment(dm, enableInPlace);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.geronimo.st.v21.core.IGeronimoServer#getVersionHandler()
+ */
+ public IGeronimoVersionHandler getVersionHandler() {
+ if (versionHandler == null)
+ versionHandler = new GeronimoV22VersionHandler();
+ return versionHandler;
+ }
+
+ public void setInPlaceDeployment(DeploymentManager dm, boolean enable) {
+ ((JMXDeploymentManager) dm).setInPlace(enable);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.geronimo.st.v21.core.IGeronimoServer#isInPlace()
+ */
+ public boolean isInPlaceSharedLib() {
+ return getAttribute(PROPERTY_IN_PLACE_SHARED_LIB, false);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.geronimo.st.v21.core.IGeronimoServer#isRunFromWorkspace()
+ */
+ public boolean isRunFromWorkspace() {
+ return getAttribute(PROPERTY_RUN_FROM_WORKSPACE, false);
+ }
+
+ public void setInPlaceSharedLib(boolean enable) {
+ setAttribute(PROPERTY_IN_PLACE_SHARED_LIB, enable);
+ }
+
+ public void setRunFromWorkspace(boolean enable) {
+ setAttribute(PROPERTY_RUN_FROM_WORKSPACE, enable);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.geronimo.st.core.GeronimoServerDelegate#setDefaults(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void setDefaults(IProgressMonitor monitor) {
+ super.setDefaults(monitor);
+ setInPlaceSharedLib(false);
+ setRunFromWorkspace(false);
+ }
+
+ public boolean isNotRedeployJSPFiles() {
+ return getAttribute(PROPERTY_NOT_REDEPLOY_JSP_FILES,false);
+ }
+}
\ No newline at end of file
Added: geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/GeronimoServerBehaviour.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/GeronimoServerBehaviour.java?rev=955877&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/GeronimoServerBehaviour.java (added)
+++ geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/GeronimoServerBehaviour.java Fri Jun 18 08:10:13 2010
@@ -0,0 +1,235 @@
+/*
+ * 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.v22.core;
+
+import java.net.URL;
+import java.util.List;
+import java.util.Set;
+
+import javax.management.MBeanServerConnection;
+import javax.naming.directory.NoSuchAttributeException;
+
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.InternalKernelException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.config.Configuration;
+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.v21.core.Activator;
+import org.apache.geronimo.st.v21.core.GeronimoServerBehaviourDelegate;
+import org.apache.geronimo.st.v21.core.internal.DependencyHelper;
+import org.apache.geronimo.st.v21.core.internal.Trace;
+import org.apache.geronimo.system.jmx.KernelDelegate;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.internal.IModulePublishHelper;
+
+/**
+ * @version $Rev: 540136 $ $Date: 2007-05-21 09:15:31 -0400 (Mon, 21 May 2007) $
+ */
+public class GeronimoServerBehaviour extends GeronimoServerBehaviourDelegate implements IModulePublishHelper {
+
+ private Kernel kernel = null;
+
+ public GeronimoServerBehaviour() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate#stopKernel()
+ */
+ protected void stopKernel() {
+ if (kernel != null) {
+ kernel.shutdown();
+ kernel = null;
+ }
+ }
+
+ /**
+ * @return
+ * @throws SecurityException
+ */
+ protected Kernel getKernel() throws SecurityException {
+ if (kernel == null) {
+ try {
+ MBeanServerConnection connection = getServerConnection();
+ if (connection != null)
+ kernel = new KernelDelegate(connection);
+ } catch (SecurityException e) {
+ throw e;
+ } catch (Exception e) {
+ Trace.trace(Trace.WARNING, "Kernel connection failed. "
+ + e.getMessage());
+ }
+ }
+ return kernel;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.geronimo.st.v21.core.IGeronimoServerBehavior#isKernelAlive()
+ */
+ public boolean isKernelAlive() {
+ try {
+ return getKernel() != null && kernel.isRunning();
+ } catch (SecurityException e) {
+ Trace.trace(Trace.SEVERE, "Invalid username and/or password.", e);
+
+ pingThread.interrupt();
+ if (getServer().getServerState() != IServer.STATE_STOPPED) {
+ forceStopJob(true,e);
+
+ }
+ } catch (Exception e) {
+ Activator.log(Status.WARNING, "Geronimo Server may have been terminated manually outside of workspace.", e);
+ kernel = null;
+ }
+ return false;
+ }
+
+ private void forceStopJob(boolean b, final SecurityException e) {
+ /*
+ *
+ * Currently, there is another Status is returned by StartJob in Server.
+ * The message doesn't contain reason for the exception.
+ * So this job is created to show a message(Invalid username and/or password) to user.
+ *
+ * TODO: Need a method to remove the error message thrown by StartJob in Server.
+ *
+ */
+
+ String jobName = NLS.bind(org.eclipse.wst.server.core.internal.Messages.errorStartFailed, getServer().getName());
+
+ //This message has different variable names in WTP 3.0 and 3.1, so we define it here instead of using that in WTP
+ final String jobStartingName = NLS.bind("Starting {0}", getServer().getName());
+
+ new Job(jobName){
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, 0, jobStartingName, null);
+ multiStatus.add(new Status(IStatus.ERROR,Activator.PLUGIN_ID,0,"Invalid username and/or password.",e));
+ try{
+ GeronimoServerBehaviour.this.stop(true);
+ }catch (Exception e){
+ multiStatus.add(new Status(IStatus.ERROR,Activator.PLUGIN_ID,0,"Failed to stop server",e));
+ }
+
+ return multiStatus;
+ }
+ }.schedule();
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.geronimo.st.v21.core.IGeronimoServerBehavior#isFullyStarted()
+ */
+ public boolean isFullyStarted() {
+ if (isKernelAlive()) {
+ AbstractNameQuery query = new AbstractNameQuery(PersistentConfigurationList.class.getName());
+ Set configLists = kernel.listGBeans(query);
+ if (!configLists.isEmpty()) {
+ AbstractName on = (AbstractName) configLists.toArray()[0];
+ try {
+ Boolean b = (Boolean) kernel.getAttribute(on, "kernelFullyStarted");
+ return b.booleanValue();
+ } catch (GBeanNotFoundException e) {
+ // ignore
+ } catch (NoSuchAttributeException e) {
+ // ignore
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else {
+ Trace.trace(Trace.INFO, "configLists is empty");
+ }
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate#getRuntimeClass()
+ */
+ public String getRuntimeClass() {
+ return "org.apache.geronimo.cli.daemon.DaemonCLI";
+ }
+
+ public IPath getPublishDirectory(IModule[] module) {
+ if (module == null || module.length == 0)
+ return null;
+
+ if (getGeronimoServer().isRunFromWorkspace()) {
+ // TODO fix me, see if project root, component root, or output
+ // container should be returned
+ return module[module.length - 1].getProject().getLocation();
+ } else {
+ ClassLoader old = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(getContextClassLoader());
+ String configId = getConfigId(module[0]);
+ Artifact artifact = Artifact.create(configId);
+ AbstractName name = Configuration.getConfigurationAbstractName(artifact);
+ GBeanData data = kernel.getGBeanData(name);
+ URL url = (URL) data.getAttribute("baseURL");
+ return getModulePath(module, url);
+ } catch (InvalidConfigException e) {
+ e.printStackTrace();
+ } catch (GBeanNotFoundException e) {
+ e.printStackTrace();
+ } catch (InternalKernelException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ Thread.currentThread().setContextClassLoader(old);
+ }
+ }
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.geronimo.st.core.GenericGeronimoServerBehaviour#getContextClassLoader()
+ */
+ protected ClassLoader getContextClassLoader() {
+ return Kernel.class.getClassLoader();
+ }
+
+ @Override
+ protected List getOrderedModules(IServer server, List modules,
+ List deltaKind) {
+ DependencyHelper dh = new DependencyHelper();
+ List list = dh.reorderModules(this.getServer(),modules, deltaKind);
+ return list;
+ }
+}
\ No newline at end of file
Added: geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/GeronimoV22ServerInfo.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/GeronimoV22ServerInfo.java?rev=955877&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/GeronimoV22ServerInfo.java (added)
+++ geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/GeronimoV22ServerInfo.java Fri Jun 18 08:10:13 2010
@@ -0,0 +1,471 @@
+/*
+ * 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.v22.core;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.management.MBeanServerConnection;
+
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.gbean.GAttributeInfo;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.jee.deployment.Dependency;
+import org.apache.geronimo.jee.naming.Pattern;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.InternalKernelException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.NoSuchAttributeException;
+import org.apache.geronimo.kernel.NoSuchOperationException;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.st.v21.core.GeronimoServerBehaviourDelegate;
+import org.apache.geronimo.st.v21.core.IGeronimoServerInfo;
+import org.apache.geronimo.st.v21.core.internal.Trace;
+import org.apache.geronimo.system.jmx.KernelDelegate;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerCore;
+
+/**
+ * @version $Rev: 952535 $ $Date: 2010-06-08 12:40:16 +0800 (Tue, 08 Jun 2010) $
+ */
+public class GeronimoV22ServerInfo implements IGeronimoServerInfo{
+ static final long serialVersionUID = 1L;
+
+ private ArrayList<Kernel> kernels;
+
+ private ArrayList<Pattern> deployedEJBs;
+ private ArrayList<String> securityRealms;
+ private ArrayList<Pattern> jmsConnectionFactories;
+ private ArrayList<Pattern> jmsDestinations;
+ private ArrayList<Pattern> jdbcConnectionPools;
+ private ArrayList<Pattern> javaMailResources;
+ private ArrayList<org.apache.geronimo.jee.deployment.Pattern> credentialStores;
+ private HashMap<org.apache.geronimo.jee.deployment.Pattern,HashMap<String,ArrayList<String>>> credentialStoreAttributes;
+ private ArrayList<Dependency> commonLibs;
+
+ // singleton class
+ private GeronimoV22ServerInfo() {
+ }
+
+ private static GeronimoV22ServerInfo instance = new GeronimoV22ServerInfo();
+
+ public static GeronimoV22ServerInfo getInstance() {
+ return instance;
+ }
+
+ public ArrayList<Pattern> getDeployedEjbs() {
+ return deployedEJBs;
+ }
+
+ public ArrayList<String> getSecurityRealms() {
+ return securityRealms;
+ }
+
+ public ArrayList<Pattern> getJmsConnectionFactories() {
+ return jmsConnectionFactories;
+ }
+
+ public ArrayList<Pattern> getJmsDestinations() {
+ return jmsDestinations;
+ }
+
+ public ArrayList<Pattern> getJdbcConnectionPools() {
+ return jdbcConnectionPools;
+ }
+
+ public ArrayList<Pattern> getJavaMailSessions() {
+ return javaMailResources;
+ }
+
+ public ArrayList<org.apache.geronimo.jee.deployment.Pattern> getDeployedCredentialStores() {
+ return credentialStores;
+ }
+
+ public HashMap<org.apache.geronimo.jee.deployment.Pattern,HashMap<String,ArrayList<String>>> getDeployedCredentialStoreAttributes() {
+ return credentialStoreAttributes;
+ }
+
+ public ArrayList<Dependency> getCommonLibs() {
+ return commonLibs;
+ }
+
+ public void updateInfo() {
+ Job job = new Job("Getting Dynamic Information from Server"){
+ protected IStatus run(IProgressMonitor arg0) {
+ updateKernels();
+ updateDeployedEJBs();
+ updateSecurityRealms();
+ updateJmsConnectionFactories();
+ updateJmsDestinations();
+ updateJdbcConnectionPools();
+ updateJavaMailSessions();
+ updateDeployedCredentialStores();
+ updateCommonLibs();
+ return Status.OK_STATUS;
+ }
+ };
+ job.setPriority(Job.SHORT);
+ job.schedule();
+ }
+
+ private void updateKernels() {
+ kernels = new ArrayList<Kernel>();
+ IServer[] servers = ServerCore.getServers();
+ for (int i = 0; i < servers.length; i++) {
+ if (servers[i].getServerState() == IServer.STATE_STARTED) {
+ try {
+ GeronimoServerBehaviourDelegate delegate = (GeronimoServerBehaviourDelegate) servers[i]
+ .getAdapter(GeronimoServerBehaviourDelegate.class);
+ if (delegate != null) {
+ MBeanServerConnection connection = delegate
+ .getServerConnection();
+ if (connection != null) {
+ kernels.add(new KernelDelegate(connection));
+ }
+ }
+ } catch (SecurityException e) {
+ } catch (Exception e) {
+ Trace.trace(Trace.WARNING, "Kernel connection failed. "
+ + e.getMessage());
+ }
+ }
+ }
+ }
+
+ private void updateDeployedEJBs() {
+ deployedEJBs = new ArrayList<Pattern>();
+ ArrayList<Pattern> statelessSessionBeans = getByType("StatelessSessionBean");
+ ArrayList<Pattern> statefulSessionBeans = getByType("StatefulSessionBean");
+ ArrayList<Pattern> messageDrivenBeans = getByType("MessageDrivenBean");
+ ArrayList<Pattern> entityBeans = getByType("EntityBean");
+ deployedEJBs.addAll(statelessSessionBeans);
+ deployedEJBs.addAll(statefulSessionBeans);
+ deployedEJBs.addAll(messageDrivenBeans);
+ deployedEJBs.addAll(entityBeans);
+ }
+
+ private void updateSecurityRealms() {
+ securityRealms = new ArrayList<String>();
+ Map map = Collections.singletonMap("j2eeType", "SecurityRealm");
+ AbstractNameQuery query = new AbstractNameQuery(null, map,
+ Collections.EMPTY_SET);
+ for (int i = 0; i < kernels.size(); i++) {
+ Set beans = kernels.get(i).listGBeans(query);
+ for (Iterator it = beans.iterator(); it.hasNext();) {
+ AbstractName abstractName = (AbstractName) it.next();
+ String name = (String) abstractName.getName().get("name");
+ if (!securityRealms.contains(name)) {
+ securityRealms.add(name);
+ }
+ }
+ }
+ }
+
+ private void updateJmsConnectionFactories() {
+ String[] requiredInterfaces = new String[] {
+ "javax.jms.ConnectionFactory",
+ "javax.jms.QueueConnectionFactory",
+ "javax.jms.TopicConnectionFactory", };
+ String attribute = "implementedInterfaces";
+ jmsConnectionFactories = getByTypeAttributeValues(
+ "JCAManagedConnectionFactory", attribute, requiredInterfaces);
+ }
+
+ private void updateJmsDestinations() {
+ String[] requiredInterfaces = new String[] { "javax.jms.Queue",
+ "javax.jms.Topic" };
+ String attribute = "adminObjectInterface";
+ jmsDestinations = getByTypeAttributeValues("JCAAdminObject", attribute,
+ requiredInterfaces);
+ }
+
+ private void updateJdbcConnectionPools() {
+ String[] acceptedValues = new String[] { "javax.sql.DataSource" };
+ String attribute = "connectionFactoryInterface";
+ jdbcConnectionPools = getByTypeAttributeValues(
+ "JCAManagedConnectionFactory", attribute, acceptedValues);
+
+ }
+
+ private void updateJavaMailSessions() {
+ javaMailResources = getByType("JavaMailResource");
+ }
+
+ private void updateDeployedCredentialStores() {
+ credentialStores = new ArrayList<org.apache.geronimo.jee.deployment.Pattern>();
+ credentialStoreAttributes = new HashMap<org.apache.geronimo.jee.deployment.Pattern,HashMap<String,ArrayList<String>>> ();
+ Map map = Collections.singletonMap("j2eeType", "GBean");
+ AbstractNameQuery query = new AbstractNameQuery(null, map,
+ Collections.EMPTY_SET);
+ for (int i = 0; i < kernels.size(); i++) {
+ Kernel kernel = (Kernel)kernels.get(i);
+ Set beans = kernel.listGBeans(query);
+ for (Iterator it = beans.iterator(); it.hasNext();) {
+ AbstractName abstractName = (AbstractName) it.next();
+ try {
+ GBeanInfo info = kernel.getGBeanInfo(abstractName);
+ GAttributeInfo attribInfo = info
+ .getAttribute("credentialStore");
+ if (attribInfo != null) {
+ Artifact artifact = abstractName.getArtifact();
+ Object name = abstractName.getName().get("name");
+ org.apache.geronimo.jee.deployment.Pattern pattern = new org.apache.geronimo.jee.deployment.Pattern();
+ pattern.setArtifactId(artifact.getArtifactId());
+ pattern.setGroupId(artifact.getGroupId());
+ pattern.setType(artifact.getType());
+ pattern.setVersion(artifact.getVersion().toString());
+ pattern.setCustomFoo((String) name);
+ if (!credentialStores.contains(pattern)) {
+ credentialStores.add(pattern);
+ }
+
+ //update attributes of credentialStore
+ Map attributeMap = (Map)kernel.getAttribute(abstractName, "credentialStore");
+ if (attributeMap!=null){
+ HashMap<String,ArrayList<String>> realmMap = new HashMap<String,ArrayList<String>>();
+ for (Object obj:attributeMap.keySet()){
+ String realmName = (String)obj;
+ Map idMap = (Map)attributeMap.get(obj);
+ ArrayList<String> idList = new ArrayList<String>();
+ idList.addAll(idMap.keySet());
+
+ realmMap.put(realmName, idList);
+ }
+ credentialStoreAttributes.put(pattern, realmMap);
+ }
+ }
+ } catch (GBeanNotFoundException e) {
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+
+ private void updateCommonLibs() {
+ List<Object> artifacts = null;
+ commonLibs = new ArrayList<Dependency>();
+ Map map = Collections.singletonMap("j2eeType", "Repository");
+ AbstractNameQuery query = new AbstractNameQuery(null, map,
+ Collections.EMPTY_SET);
+ for (int i = 0; i < kernels.size(); i++) {
+ Set beans = kernels.get(i).listGBeans(query);
+ for (Iterator it = beans.iterator(); it.hasNext();) {
+ AbstractName abstractName = (AbstractName) it.next();
+ try {
+ GBeanInfo info = kernels.get(i).getGBeanInfo(abstractName);
+ Object value = kernels.get(i).invoke(abstractName, "list");
+ if (value instanceof TreeSet) {
+ artifacts = Arrays.asList(((TreeSet) value).toArray());
+ }
+ } catch (GBeanNotFoundException e) {
+ Trace.trace(Trace.WARNING, "GBean Not Found. "
+ + e.getMessage());
+ } catch (NoSuchOperationException e) {
+ Trace.trace(Trace.WARNING, "The operation cant invoked. "
+ + e.getMessage());
+ } catch (InternalKernelException e) {
+ throw e;
+ } catch (Exception e) {
+ Trace.trace(Trace.WARNING, "Kernel connection failed. "
+ + e.getMessage());
+ }
+
+ }
+ }
+ if (artifacts != null) {
+ for (int i = 0; i < artifacts.size(); i++) {
+ Dependency dependency = new Dependency();
+ dependency.setArtifactId(((Artifact) artifacts.get(i))
+ .getArtifactId());
+ dependency.setGroupId(((Artifact) artifacts.get(i))
+ .getGroupId());
+ dependency.setVersion(((Artifact) artifacts.get(i))
+ .getVersion().toString());
+ dependency.setType(((Artifact) artifacts.get(i)).getType());
+ if (!commonLibs.contains(dependency)) {
+ commonLibs.add(dependency);
+ }
+ }
+ }
+ }
+
+ private ArrayList<Pattern> getByTypeAttributeValues(String type,
+ String attribute, String[] acceptedValues) {
+ ArrayList<Pattern> result = new ArrayList<Pattern>();
+ Map map = Collections.singletonMap("j2eeType", type);
+ AbstractNameQuery query = new AbstractNameQuery(null, map,
+ Collections.EMPTY_SET);
+ for (int i = 0; i < kernels.size(); i++) {
+ Set beans = kernels.get(i).listGBeans(query);
+ for (Iterator it = beans.iterator(); it.hasNext();) {
+ AbstractName abstractName = (AbstractName) it.next();
+ try {
+ Object value = kernels.get(i).getAttribute(abstractName,
+ attribute);
+ if (value != null) {
+ if (value instanceof String[]) {
+ List<String> interfaces = Arrays
+ .asList((String[]) value);
+ for (int j = 0; j < acceptedValues.length; j++) {
+ if (interfaces.contains(acceptedValues[j])) {
+ Pattern pattern = new Pattern();
+ Artifact artifact = abstractName
+ .getArtifact();
+ pattern.setArtifactId(artifact
+ .getArtifactId());
+ pattern.setGroupId(artifact.getGroupId());
+ pattern.setVersion(artifact.getVersion()
+ .toString());
+ pattern.setName((String) abstractName
+ .getName().get("name"));
+ if (!result.contains(pattern)) {
+ result.add(pattern);
+ }
+ break;
+ }
+ }
+ }
+ if (value instanceof String) {
+ String interfaces = (String) value;
+ for (int j = 0; j < acceptedValues.length; j++) {
+ if (interfaces.contains(acceptedValues[j])) {
+ Pattern pattern = new Pattern();
+ Artifact artifact = abstractName
+ .getArtifact();
+ pattern.setArtifactId(artifact
+ .getArtifactId());
+ pattern.setGroupId(artifact.getGroupId());
+ pattern.setVersion(artifact.getVersion()
+ .toString());
+ pattern.setName((String) abstractName
+ .getName().get("name"));
+ if (!result.contains(pattern)) {
+ result.add(pattern);
+ }
+ break;
+ }
+ }
+ }
+ }
+ } catch (GBeanNotFoundException e) {
+ } catch (NoSuchAttributeException e) {
+ } catch (Exception e) {
+ Trace.trace(Trace.WARNING, "Kernel connection failed. "
+ + e.getMessage());
+ }
+ }
+ }
+ return result;
+ }
+
+ private ArrayList<Pattern> getByType(String type) {
+ ArrayList<Pattern> result = new ArrayList<Pattern>();
+ Map map = Collections.singletonMap("j2eeType", type);
+ AbstractNameQuery query = new AbstractNameQuery(null, map,
+ Collections.EMPTY_SET);
+ for (int i = 0; i < kernels.size(); i++) {
+ Set beans = kernels.get(i).listGBeans(query);
+ for (Iterator it = beans.iterator(); it.hasNext();) {
+ AbstractName abstractName = (AbstractName) it.next();
+ Pattern pattern = new Pattern();
+ Artifact artifact = abstractName.getArtifact();
+ pattern.setArtifactId(artifact.getArtifactId());
+ pattern.setGroupId(artifact.getGroupId());
+ pattern.setVersion(artifact.getVersion().toString());
+ pattern.setName((String) abstractName.getName().get("name"));
+ if (!result.contains(pattern)) {
+ result.add(pattern);
+ }
+ }
+ }
+ return result;
+ }
+
+ protected void printNamingPatternList(List<Pattern> patternList) {
+ for (int i = 0; i < patternList.size(); i++) {
+ Pattern pattern = patternList.get(i);
+ System.out.println("ArtifactID:" + pattern.getArtifactId()
+ + " GroupID:" + pattern.getGroupId() + " Module:"
+ + pattern.getModule() + " Version:" + pattern.getVersion()
+ + " Name:" + pattern.getName());
+ }
+ }
+
+ protected void printDeploymentPatternList(
+ List<org.apache.geronimo.jee.deployment.Pattern> patternList) {
+ for (int i = 0; i < patternList.size(); i++) {
+ org.apache.geronimo.jee.deployment.Pattern pattern = patternList
+ .get(i);
+ System.out.println("ArtifactID:" + pattern.getArtifactId()
+ + " GroupID:" + pattern.getGroupId() + " Module:"
+ + pattern.getVersion() + " Version:" + pattern.getType()
+ + " Name:" + pattern.getCustomFoo());
+ }
+ }
+
+ protected void printDependencies(List<Dependency> dependencyList) {
+ for (int i = 0; i < dependencyList.size(); i++) {
+ Dependency dependency = dependencyList.get(i);
+ System.out.println("ArtifactID:" + dependency.getArtifactId()
+ + " GroupID:" + dependency.getGroupId() + " Type:"
+ + dependency.getType() + " Version:"
+ + dependency.getVersion());
+ }
+ }
+
+ public void printServerInfo() {
+ System.out.println("EJB Modules: \n");
+ List<Pattern> ejbModules = getDeployedEjbs();
+ printNamingPatternList(ejbModules);
+ System.out.println("\n\nSecurity Realms: \n");
+ List<String> securityRealms = getSecurityRealms();
+ System.out.println(securityRealms.toString());
+ System.out.println("\n\nJMS Connection Factories: \n");
+ List<Pattern> jmsConnectionFactories = getJmsConnectionFactories();
+ printNamingPatternList(jmsConnectionFactories);
+ System.out.println("\n\nJMS Destinations: \n");
+ List<Pattern> jmsDestinations = getJmsDestinations();
+ printNamingPatternList(jmsDestinations);
+ System.out.println("\n\nJDBC Connection Pools: \n");
+ List<Pattern> jdbcConnectionPools = getJdbcConnectionPools();
+ printNamingPatternList(jdbcConnectionPools);
+ System.out.println("\n\nJava Mail Resources: \n");
+ List<Pattern> javaMailResources = getJavaMailSessions();
+ printNamingPatternList(javaMailResources);
+ System.out.println("\n\nCredential Stores: \n");
+ List<org.apache.geronimo.jee.deployment.Pattern> credentialStores = getDeployedCredentialStores();
+ printDeploymentPatternList(credentialStores);
+ System.out.println("\n\nCommon Libs: \n");
+ List<Dependency> dependencies = getCommonLibs();
+ printDependencies(dependencies);
+ }
+
+}
Added: geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/GeronimoV22VersionHandler.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/GeronimoV22VersionHandler.java?rev=955877&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/GeronimoV22VersionHandler.java (added)
+++ geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/GeronimoV22VersionHandler.java Fri Jun 18 08:10:13 2010
@@ -0,0 +1,46 @@
+/*
+ * 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.v22.core;
+
+import javax.enterprise.deploy.spi.TargetModuleID;
+
+import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl;
+import org.apache.geronimo.st.v21.core.GeronimoV21Utils;
+import org.apache.geronimo.st.v21.core.IGeronimoVersionHandler;
+import org.eclipse.wst.server.core.IModule;
+
+/**
+ * @version $Rev: 513891 $ $Date: 2007-03-02 14:09:25 -0500 (Fri, 02 Mar 2007) $
+ */
+public class GeronimoV22VersionHandler implements IGeronimoVersionHandler {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.geronimo.st.core.IGeronimoVersionHandler#getConfigID(org.eclipse.wst.server.core.IModule)
+ */
+ public String getConfigID(IModule module) throws Exception {
+ return GeronimoV21Utils.getConfigId(module);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.geronimo.st.core.IGeronimoVersionHandler#createTargetModuleId(java.lang.String)
+ */
+ public TargetModuleID createTargetModuleId(String configId) {
+ return new TargetModuleIDImpl(null, configId);
+ }
+}
Added: geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/internal/Trace.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/internal/Trace.java?rev=955877&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/internal/Trace.java (added)
+++ geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/internal/Trace.java Fri Jun 18 08:10:13 2010
@@ -0,0 +1,114 @@
+/*
+ * 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.v22.core.internal;
+
+import org.apache.geronimo.st.v21.core.Activator;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * Helper class to route trace output.
+ *
+ * @version $Rev: 589873 $ $Date: 2007-10-29 17:48:35 -0400 (Mon, 29 Oct 2007) $
+ */
+public class Trace {
+
+ /**
+ * Finest trace event.
+ */
+ public static byte INFO = 0;
+
+ /**
+ * Warning trace event.
+ */
+ public static byte WARNING = 1;
+
+ /**
+ * Severe trace event.
+ */
+ public static byte SEVERE = 2;
+
+ /**
+ * Trace constructor comment.
+ */
+ private Trace() {
+ super();
+ }
+
+ /**
+ * Trace the given text.
+ *
+ * @param level
+ * the trace level
+ * @param s
+ * a message
+ */
+ public static void trace(byte level, String s) {
+ trace(level, s, null);
+ }
+
+ /**
+ * Trace the given message and exception.
+ *
+ * @param level
+ * the trace level
+ * @param s
+ * a message
+ * @param t
+ * a throwable
+ */
+ public static void trace(byte level, String s, Throwable t) {
+ if (Activator.getDefault() == null
+ || !Activator.getDefault().isDebugging())
+ return;
+
+ System.out.println(Activator.PLUGIN_ID + ": " + s);
+ if (t != null)
+ t.printStackTrace();
+
+ }
+
+ /**
+ * Trace the given message
+ *
+ * @param tracePoint
+ * The trace point (e.g., "Exit", "Entry", "Constructor", etc....
+ *
+ * @param classDotMethod
+ * The class name + method name (e.g., "Class.method()")
+ *
+ * @param parms
+ * Method parameter(s) if the trace point is an "Entry"
+ * or
+ * Return value if the trace point is an "Exit"
+ */
+ public static void tracePoint(String tracePoint, String classDotMethod) {
+ trace(Trace.INFO, tracePoint + ": " + classDotMethod + "()" );
+ }
+ public static void tracePoint(String tracePoint, String classDotMethod, Object... parms) {
+ if ( parms == null ) {
+ trace(Trace.INFO, tracePoint + ": " + classDotMethod + "( null )" );
+ }
+ else {
+ trace(Trace.INFO, tracePoint + ": " + classDotMethod + "(" );
+ for ( int ii=0; ii<parms.length; ii++) {
+ Object parm = parms[ii];
+ trace(Trace.INFO, " parm" + (ii+1) + "=[" + (parm == null ? null : parm.toString()) + "]" );
+ }
+ trace(Trace.INFO, ")" );
+ }
+ }
+}
Added: geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/operations/GeronimoServerPluginManager.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/operations/GeronimoServerPluginManager.java?rev=955877&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/operations/GeronimoServerPluginManager.java (added)
+++ geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.core/src/main/java/org/apache/geronimo/st/v22/core/operations/GeronimoServerPluginManager.java Fri Jun 18 08:10:13 2010
@@ -0,0 +1,761 @@
+/*
+ * 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.v22.core.operations;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import javax.management.MBeanServerConnection;
+import javax.xml.bind.JAXBElement;
+
+import org.apache.geronimo.deployment.plugin.jmx.RemoteDeploymentManager;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.config.ConfigurationData;
+import org.apache.geronimo.kernel.config.ConfigurationInfo;
+import org.apache.geronimo.kernel.config.ConfigurationManager;
+import org.apache.geronimo.kernel.config.ConfigurationUtil;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.Dependency;
+import org.apache.geronimo.kernel.repository.ImportType;
+import org.apache.geronimo.st.core.CommonMessages;
+import org.apache.geronimo.st.v21.core.GeronimoConnectionFactory;
+import org.apache.geronimo.st.v21.core.GeronimoServerBehaviourDelegate;
+import org.apache.geronimo.st.core.jaxb.JAXBUtils;
+import org.apache.geronimo.st.v21.core.internal.Trace;
+import org.apache.geronimo.system.jmx.KernelDelegate;
+import org.apache.geronimo.system.plugin.PluginInstaller;
+import org.apache.geronimo.system.plugin.model.ArtifactType;
+import org.apache.geronimo.system.plugin.model.DependencyType;
+import org.apache.geronimo.system.plugin.model.ObjectFactory;
+import org.apache.geronimo.system.plugin.model.PluginArtifactType;
+import org.apache.geronimo.system.plugin.model.PluginListType;
+import org.apache.geronimo.system.plugin.model.PluginType;
+import org.apache.geronimo.system.plugin.model.PrerequisiteType;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.internal.ServerWorkingCopy;
+
+/**
+ * @version $Rev: 952535 $ $Date: 2010-06-08 12:40:16 +0800 (Tue, 08 Jun 2010) $
+ */
+public class GeronimoServerPluginManager {
+
+ private IServer server;
+ private PluginListType data;
+ private List<String> pluginList;
+ private Kernel kernel;
+ private PluginInstaller pluginInstaller;
+
+ // The ServerWorkingCopy is passed in, not the IServer itself
+ public GeronimoServerPluginManager (IServer aServer) {
+ ServerWorkingCopy copy = (ServerWorkingCopy)aServer;
+ server = copy.getOriginal();
+ try {
+ if (server != null) {
+ GeronimoServerBehaviourDelegate delegate = (GeronimoServerBehaviourDelegate) server
+ .getAdapter(GeronimoServerBehaviourDelegate.class);
+ if (delegate != null) {
+ MBeanServerConnection connection = delegate.getServerConnection();
+ if (connection != null) {
+ kernel = new KernelDelegate(connection);
+ }
+ pluginInstaller = getPluginInstaller();
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ Trace.trace(Trace.WARNING, "Kernel connection failed. "
+ + e.getMessage());
+ }
+ Trace.tracePoint("Constructor", "GeronimoServerPluginManager");
+ }
+
+ private PluginInstaller getPluginInstaller() {
+ Set<AbstractName> set = kernel.listGBeans(new AbstractNameQuery(PluginInstaller.class.getName()));
+ for (AbstractName name : set) {
+ return (PluginInstaller) kernel.getProxyManager().createProxy(name, PluginInstaller.class);
+ }
+ throw new IllegalStateException("No plugin installer found");
+ }
+
+ public List<String> getPluginList () {
+ Trace.tracePoint("Entry", "GeronimoServerPluginManager.getPluginList");
+
+ String name;
+ boolean added;
+ if (pluginInstaller != null){
+ try {
+ data = pluginInstaller.createPluginListForRepositories(null);
+
+ List<PluginType> aList = data.getPlugin();
+ pluginList = new ArrayList<String>(aList.size());
+ for (int i = 0; i < aList.size(); i++) {
+ name = aList.get(i).getName();
+ added = false;
+ for (int j = 0; j < pluginList.size() && added == false; j++) {
+ if (name.compareTo(pluginList.get(j)) < 0) {
+ pluginList.add(j, name);
+ added = true;
+ }
+ }
+ if (added == false) {
+ pluginList.add(name);
+ }
+ }
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+
+ Trace.tracePoint("Exit", "GeronimoServerPluginManager.getPluginList", pluginList);
+ return pluginList;
+ }
+
+ // mimics org.apache.geronimo.console.car.AssemblyViewHandler.actionAfterView
+ public void assembleServer (String group, String artifact, String version,
+ String format, String relativeServerPath, int[] selected) {
+ Trace.tracePoint("Entry", "GeronimoServerPluginManager.assembleServer",
+ group, artifact, version, format);
+
+ PluginListType selectedPlugins = new PluginListType();
+ String name;
+ boolean found;
+
+ for (int i = 0; i < selected.length; i++) {
+ name = pluginList.get(selected[i]);
+ found = false;
+ for (int j = 0 ; j < data.getPlugin().size() && found == false; j++) {
+ if (name.equals(data.getPlugin().get(j).getName())) {
+ selectedPlugins.getPlugin().add(data.getPlugin().get(j));
+ found = true;
+ }
+ }
+ }
+
+ try {
+ GeronimoConnectionFactory gcFactory = GeronimoConnectionFactory.getInstance();
+ RemoteDeploymentManager remoteDM = (RemoteDeploymentManager)gcFactory.getDeploymentManager(server);
+ remoteDM.installPluginList("repository", relativeServerPath, selectedPlugins);
+ remoteDM.archive(relativeServerPath, "var/temp", new Artifact(group, artifact, (String)version, format));
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ Trace.tracePoint("Exit", "GeronimoServerPluginManager.assembleServer");
+ }
+
+ // mimics org.apache.geronimo.console.util.KernelManagementHelper.getConfigurations()
+ public List<String> getConfigurationList () {
+ Trace.tracePoint("Entry", "GeronimoServerPluginManager.getConfigurationList");
+
+ ConfigurationManager mgr = getConfigurationManager();
+ List<AbstractName> stores = mgr.listStores();
+ List<String> results = new ArrayList<String>();
+ for (AbstractName storeName : stores) {
+ try {
+ List<ConfigurationInfo> infos = mgr.listConfigurations(storeName);
+ for (ConfigurationInfo info : infos) {
+ if (info.getConfigID().getType().equalsIgnoreCase("car"))
+ {
+ results.add(info.getConfigID().toString());
+ }
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(CommonMessages.badConfigId, e);
+ }
+ }
+ Collections.sort(results);
+
+ Trace.tracePoint("Entry", "GeronimoServerPluginManager.getConfigurationList", results);
+ return results;
+ }
+
+ public PluginType getPluginMetadata (String configId) {
+ Artifact artifact = Artifact.create(configId);
+ PluginType metadata = null;
+ if (pluginInstaller != null)
+ metadata = pluginInstaller.getPluginMetadata(artifact);
+ return metadata;
+ }
+
+ // mimics org.apache.geronimo.system.plugin.PluginInstallerGBean.updatePluginMetadata
+ // but puts the metadata in our local directory
+ public void savePluginXML (String configId, PluginType metadata) {
+ Trace.tracePoint("Entry", "GeronimoServerPluginManager.savePluginXML", configId, metadata);
+
+ Artifact artifact = Artifact.create(configId);
+ File dir = new File (getArtifactLocation(artifact));
+
+ if (!dir.isDirectory()) { // must be a packed (JAR-formatted) plugin
+ try {
+ File temp = new File(dir.getParentFile(), dir.getName() + ".temp");
+ JarFile input = new JarFile(dir);
+ Manifest manifest = input.getManifest();
+ JarOutputStream out = manifest == null ? new JarOutputStream(
+ new BufferedOutputStream(new FileOutputStream(temp)))
+ : new JarOutputStream(new BufferedOutputStream(new FileOutputStream(temp)), manifest);
+ Enumeration en = input.entries();
+ byte[] buf = new byte[4096];
+ int count;
+ while (en.hasMoreElements()) {
+ JarEntry entry = (JarEntry) en.nextElement();
+ if (entry.getName().equals("META-INF/geronimo-plugin.xml")) {
+ entry = new JarEntry(entry.getName());
+ out.putNextEntry(entry);
+ writePluginMetadata(metadata, out);
+ } else if (entry.getName().equals("META-INF/MANIFEST.MF")) {
+ // do nothing, already passed in a manifest
+ } else {
+ out.putNextEntry(entry);
+ InputStream in = input.getInputStream(entry);
+ while ((count = in.read(buf)) > -1) {
+ out.write(buf, 0, count);
+ }
+ in.close();
+ out.closeEntry();
+ }
+ }
+ out.flush();
+ out.close();
+ input.close();
+ if (!dir.delete()) {
+ String message = CommonMessages.bind(CommonMessages.errorDeletePlugin, dir.getAbsolutePath());
+ Trace.tracePoint("Throw", "GeronimoServerPluginManager.savePluginXML", message);
+ throw new Exception(message);
+ }
+ if (!temp.renameTo(dir)) {
+ String message = CommonMessages.bind(CommonMessages.errorMovePlugin, temp.getAbsolutePath(), dir.getAbsolutePath());
+ Trace.tracePoint("Throw", "GeronimoServerPluginManager.savePluginXML", message);
+ throw new Exception(message);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(CommonMessages.errorUpdateMetadata, e);
+ }
+ } else {
+ File meta = new File(addFilename(dir.getAbsolutePath(), artifact), "META-INF");
+ if (!meta.isDirectory() || !meta.canRead()) {
+ String message = CommonMessages.bind(CommonMessages.badPlugin, artifact);
+ Trace.tracePoint("Throw", "GeronimoServerPluginManager.savePluginXML", message);
+ throw new IllegalArgumentException(message);
+ }
+ File xml = new File(meta, "geronimo-plugin.xml");
+ FileOutputStream fos = null;
+ try {
+ if (!xml.isFile()) {
+ if (!xml.createNewFile()) {
+ String message = CommonMessages.bind(CommonMessages.errorCreateMetadata, artifact);
+ Trace.tracePoint("Throw", "GeronimoServerPluginManager.savePluginXML", message);
+ throw new RuntimeException(message);
+ }
+ }
+ fos = new FileOutputStream(xml);
+ writePluginMetadata(metadata, fos);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (Exception ignored) {
+ ignored.printStackTrace();
+ }
+ }
+ }
+ }
+
+ Trace.tracePoint("Exit", "GeronimoServerPluginManager.savePluginXML");
+ }
+
+ // mimics org.apache.geronimo.system.configuration.RepositoryConfigurationStore.exportConfiguration
+ public void exportCAR (String localRepoDir, String configId) throws Exception {
+ Trace.tracePoint("Entry", "GeronimoServerPluginManager.exportCAR", localRepoDir, configId);
+
+ Artifact artifact = Artifact.create(configId);
+ String filename = createDirectoryStructure (localRepoDir, artifact);
+ File outputDir = new File (filename);
+
+ File serverArtifact = new File(getArtifactLocation (artifact));
+ writeToDirectory(serverArtifact, outputDir);
+
+ Trace.tracePoint("Exit", "GeronimoServerPluginManager.exportCAR");
+ }
+
+ private void writeToDirectory(File inputDir, File outputDir) throws Exception {
+ Trace.tracePoint("Entry", "GeronimoServerPluginManager.writeToZip", inputDir);
+
+ outputDir.mkdirs();
+ File[] all = inputDir.listFiles();
+ for (File file : all) {
+ if (file.isDirectory()) {
+ String oDir = outputDir.getAbsolutePath() + File.separator + file.getName();
+ File temp = new File (oDir);
+ writeToDirectory(file, temp);
+ } else {
+ File entry = new File(outputDir + File.separator + file.getName());
+ FileOutputStream out = new FileOutputStream (entry);
+ FileInputStream in = new FileInputStream(file);
+ byte[] buf = new byte[10240];
+ int count;
+ try {
+ while ((count = in.read(buf, 0, buf.length)) > -1) {
+ out.write(buf, 0, count);
+ }
+ } finally {
+ in.close();
+ out.flush();
+ out.close();
+ }
+ }
+ }
+ Trace.tracePoint("Exit", "GeronimoServerPluginManager.writeToZip");
+ }
+
+ public void updatePluginList (String localRepoDir, PluginType metadata) throws Exception {
+ Trace.tracePoint("Entry", "GeronimoServerPluginManager.updatePluginList", localRepoDir, metadata);
+
+ PluginListType pluginList = readPluginList(localRepoDir);
+ File listFile = new File (localRepoDir, "geronimo-plugins.xml");
+
+ // if this plugin exists, remove it from the list
+ PluginType plugin;
+ for (int i = 0; i < pluginList.getPlugin().size(); i++) {
+ plugin = pluginList.getPlugin().get(i);
+ if (metadata.getName().equals(plugin.getName()) &&
+ metadata.getCategory().equals(plugin.getCategory())) {
+ pluginList.getPlugin().remove(i);
+ break;
+ }
+ }
+
+ // add the current plugin to the list
+ pluginList.getPlugin().add(metadata);
+
+ // write the file
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(listFile);
+ writePluginList(pluginList, fos);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (Exception ignored) {
+ ignored.printStackTrace();
+ }
+ }
+ }
+ Trace.tracePoint("Exit", "GeronimoServerPluginManager.updatePluginList");
+ }
+
+ public PluginListType readPluginList (String localRepoDir) {
+ Trace.tracePoint("Entry", "GeronimoServerPluginManager.readPluginList", localRepoDir);
+
+ PluginListType pluginList = null;
+ File listFile = new File (localRepoDir, "geronimo-plugins.xml");
+ if (listFile.exists() && listFile.exists()) {
+ InputStream in = null;
+ try {
+ in = new FileInputStream(listFile);
+ pluginList = loadPluginList(in);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (Exception e) {}
+ }
+ }
+ }
+ if (pluginList == null) {
+ ObjectFactory factory = new ObjectFactory();
+ pluginList = factory.createPluginListType();
+ }
+
+ Trace.tracePoint("Exit", "GeronimoServerPluginManager.readPluginList", pluginList);
+ return pluginList;
+ }
+
+ public PluginListType loadPluginList (InputStream in) {
+ try {
+ JAXBElement pluginListElement = JAXBUtils.unmarshalPlugin(in);
+ return (PluginListType)pluginListElement.getValue();
+ }
+ catch (Throwable e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private void writePluginList (PluginListType pluginList, OutputStream out) {
+ try {
+ ObjectFactory jeeFactory = new ObjectFactory();
+ JAXBElement element = jeeFactory.createGeronimoPluginList(pluginList);
+ JAXBUtils.marshalPlugin(element, out);
+ }
+ catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void writePluginMetadata (PluginType metadata, OutputStream out) {
+ try {
+ ObjectFactory jeeFactory = new ObjectFactory();
+ JAXBElement element = jeeFactory.createGeronimoPlugin(metadata);
+ JAXBUtils.marshalPlugin(element, out);
+ }
+ catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+
+ private String getArtifactLocation (Artifact artifact) {
+ String ch = File.separator;
+ String temp = server.getRuntime().getLocation().toOSString() + ch + "repository" + ch;
+ String group = artifact.getGroupId();
+ int pos = group.indexOf(".");
+ while (pos > -1) {
+ group = group.substring(0, pos) + ch + group.substring(pos + 1);
+ pos = group.indexOf(".");
+ }
+ temp += group + ch + artifact.getArtifactId() + ch + artifact.getVersion().toString() + ch;
+ return temp;
+ }
+
+ private String addFilename (String path, Artifact artifact) {
+ if (!path.endsWith("/") && !path.endsWith("\\")) {
+ path += "/";
+ }
+ return path + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + artifact.getType();
+ }
+
+ private String createDirectoryStructure (String rootPath, Artifact artifact) {
+ String fileName = rootPath;
+ if (!fileName.endsWith("/") && !fileName.endsWith("\\")) {
+ fileName += "/";
+ }
+
+ String group = artifact.getGroupId();
+ int pos = group.indexOf(".");
+ while (pos > -1) {
+ group = group.substring(0, pos) + File.separator + group.substring(pos + 1);
+ pos = group.indexOf(".");
+ }
+ fileName += group + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/";
+ File temp = new File (fileName);
+ if (!temp.exists()) {
+ temp.mkdirs();
+ }
+
+ return fileName;
+ }
+
+ private ConfigurationManager getConfigurationManager () {
+ Trace.tracePoint("Entry", "GeronimoServerPluginManager.getConfigurationManager");
+
+ if (kernel != null) {
+ Trace.tracePoint("Exit", "GeronimoServerPluginManager.getConfigurationManager");
+ return ConfigurationUtil.getEditableConfigurationManager(kernel);
+ }
+
+ Trace.tracePoint("Exit", "GeronimoServerPluginManager.getConfigurationManager returns null");
+ return null;
+ }
+
+ public ArtifactType toArtifactType(String configId) {
+ return toArtifactType (Artifact.create(configId));
+ }
+
+ public ArtifactType toArtifactType(Artifact id) {
+ ArtifactType artifact = new ArtifactType();
+ artifact.setGroupId(id.getGroupId());
+ artifact.setArtifactId(id.getArtifactId());
+ artifact.setVersion(id.getVersion() == null ? null : id.getVersion().toString());
+ artifact.setType(id.getType());
+ return artifact;
+ }
+
+ public Artifact toArtifact(ArtifactType id) {
+ return new Artifact (id.getGroupId(), id.getArtifactId(), id.getVersion(), id.getType());
+ }
+
+ public void addGeronimoDependencies(ConfigurationData data, List<DependencyType> deps, boolean includeVersion) {
+ processDependencyList(data.getEnvironment().getDependencies(), deps, includeVersion);
+ Map<String, ConfigurationData> children = data.getChildConfigurations();
+ for (ConfigurationData child : children.values()) {
+ processDependencyList(child.getEnvironment().getDependencies(), deps, includeVersion);
+ }
+ }
+
+ private void processDependencyList(List<Dependency> real, List<DependencyType> deps, boolean includeVersion) {
+ for (Dependency dep : real) {
+ DependencyType dependency = toDependencyType(dep, includeVersion);
+ if (!deps.contains(dependency)) {
+ deps.add(dependency);
+ }
+ }
+ }
+
+ public DependencyType toDependencyType(String configId) {
+ return toDependencyType(new Dependency(Artifact.create(configId), ImportType.ALL), true);
+ }
+
+ public DependencyType toDependencyType(Dependency dep, boolean includeVersion) {
+ Artifact id = dep.getArtifact();
+ DependencyType dependency = new DependencyType();
+ dependency.setGroupId(id.getGroupId());
+ dependency.setArtifactId(id.getArtifactId());
+ if (includeVersion) {
+ dependency.setVersion(id.getVersion() == null ? null : id.getVersion().toString());
+ }
+ dependency.setType(id.getType());
+ return dependency;
+ }
+
+ public boolean validatePlugin (PluginType plugin) {
+ Trace.tracePoint("Entry", "GeronimoServerPluginManager.validatePlugin", plugin);
+ boolean valid = true;
+ try {
+ pluginInstaller.validatePlugin(plugin);
+ } catch (Exception e) {
+ e.printStackTrace();
+ valid = false;
+ }
+ Trace.tracePoint("Exit", "GeronimoServerPluginManager.validatePlugin", valid);
+ return valid;
+ }
+
+ // mimics org.apache.geronimo.system.plugin.PluginInstallerGbean.install
+ // but uses our local directory to get the plugins
+ public ArrayList<String> installPlugins (String localRepoDir, List<PluginType> pluginList) {
+ Trace.tracePoint("Entry", "GeronimoServerPluginManager.installPlugins", localRepoDir, pluginList);
+ ArrayList<String> eventLog = new ArrayList<String>();
+
+ //List<Artifact> downloadedArtifacts = new ArrayList<Artifact>();
+ try {
+ ConfigurationManager configManager = getConfigurationManager();
+ Map<Artifact, PluginType> metaMap = new HashMap<Artifact, PluginType>();
+ // Step 1: validate everything
+ List<PluginType> toInstall = new ArrayList<PluginType>();
+ for (PluginType metadata : pluginList) {
+ try {
+ validatePlugin(metadata);
+ verifyPrerequisites(metadata);
+
+ PluginArtifactType instance = metadata.getPluginArtifact().get(0);
+
+ if (instance.getModuleId() != null) {
+ metaMap.put(toArtifact(instance.getModuleId()), metadata);
+ }
+ toInstall.add(metadata);
+ } catch (Exception e) {
+ }
+ }
+
+ // Step 2: everything is valid, do the installation
+ for (PluginType metadata : toInstall) {
+ // 2. Unload obsoleted configurations
+ if (!validatePlugin(metadata)) {
+ // metadata exists
+ PluginArtifactType instance = metadata.getPluginArtifact()
+ .get(0);
+ List<Artifact> obsoletes = new ArrayList<Artifact>();
+ for (ArtifactType obs : instance.getObsoletes()) {
+ Artifact obsolete = toArtifact(obs);
+ if (configManager.isLoaded(obsolete)) {
+ if (configManager.isRunning(obsolete)) {
+ configManager.stopConfiguration(obsolete);
+ eventLog.add(obsolete.toString() + " stopped");
+ }
+ configManager.unloadConfiguration(obsolete);
+ obsoletes.add(obsolete);
+ }
+ }
+
+ // 4. Uninstall obsolete configurations
+ for (Artifact artifact : obsoletes) {
+ configManager.uninstallConfiguration(artifact);
+ }
+ }
+ }
+
+ // Step 3: Start anything that's marked accordingly
+ if (configManager.isOnline()) {
+ for (int i = 0; i < toInstall.size(); i++) {
+ Artifact artifact = toArtifact(toInstall.get(i).getPluginArtifact().get(0).getModuleId());
+ if (!configManager.isRunning(artifact)) {
+ if (!configManager.isLoaded(artifact)) {
+ File serverArtifact = new File(getArtifactLocation (artifact));
+ File localDir = new File (createDirectoryStructure(localRepoDir, artifact));
+ writeToRepository(localDir, serverArtifact);
+ configManager.loadConfiguration(artifact);
+ }
+ configManager.startConfiguration(artifact);
+ eventLog.add(artifact.toString() + " started");
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ Trace.tracePoint("Exit", "GeronimoServerPluginManager.installPlugins", eventLog.toString());
+ return eventLog;
+ }
+
+ // mimics org.apache.geronimo.system.plugin.PluginInstallerGbean.verifyPrerequisistes
+ private void verifyPrerequisites(PluginType plugin) throws Exception {
+ Trace.tracePoint("Exit", "GeronimoServerPluginManager.verifyPrerequisites", plugin);
+ List<Dependency> missingPrereqs = getMissingPrerequisites(plugin);
+ if (!missingPrereqs.isEmpty()) {
+ PluginArtifactType metadata = plugin.getPluginArtifact().get(0);
+ Artifact moduleId = toArtifact(metadata.getModuleId());
+ StringBuffer buf = new StringBuffer();
+ buf.append(moduleId.toString()).append(CommonMessages.requires);
+ Iterator<Dependency> iter = missingPrereqs.iterator();
+ while (iter.hasNext()) {
+ buf.append(iter.next().getArtifact().toString());
+ if (iter.hasNext()) {
+ buf.append(", ");
+ }
+ }
+ buf.append(CommonMessages.installed);
+ Trace.tracePoint("Throw", "GeronimoServerPluginManager.verifyPrerequisites", buf.toString());
+ throw new Exception(buf.toString());
+ }
+
+ Trace.tracePoint("Exit", "GeronimoServerPluginManager.verifyPrerequisites");
+ }
+
+ // mimics org.apache.geronimo.system.plugin.PluginInstallerGbean.getMissingPrerequisistes
+ private List<Dependency> getMissingPrerequisites(PluginType plugin) {
+ Trace.tracePoint("Entry", "GeronimoServerPluginManager.getMissingPrerequisites", plugin);
+
+ if (plugin.getPluginArtifact().size() != 1) {
+ String message = CommonMessages.bind(CommonMessages.configSizeMismatch, plugin.getPluginArtifact().size());
+ Trace.tracePoint("Throw", "GeronimoServerPluginManager.getMissingPrerequisites", message);
+ throw new IllegalArgumentException(message);
+ }
+
+ PluginArtifactType metadata = plugin.getPluginArtifact().get(0);
+ List<PrerequisiteType> prereqs = metadata.getPrerequisite();
+
+ ArrayList<Dependency> missingPrereqs = new ArrayList<Dependency>();
+ for (PrerequisiteType prereq : prereqs) {
+ Artifact artifact = toArtifact(prereq.getId());
+ try {
+ if (getConfigurationManager().getArtifactResolver().queryArtifacts(artifact).length == 0) {
+ missingPrereqs.add(new Dependency(artifact, ImportType.ALL));
+ }
+ } catch (Exception e) {
+ Trace.tracePoint("Throw", "GeronimoServerPluginManager.getMissingPrerequisites", CommonMessages.noDefaultServer);
+ throw new RuntimeException(CommonMessages.noDefaultServer);
+ }
+ }
+
+ Trace.tracePoint("Exit", "GeronimoServerPluginManager.getMissingPrerequisites", missingPrereqs);
+ return missingPrereqs;
+ }
+
+ //Extract the car file
+ private void writeToRepository(File inputDir, File outputDir) throws Exception {
+ Trace.tracePoint("Entry", "GeronimoServerPluginManager.writeToRepository", inputDir,outputDir);
+
+ outputDir.mkdirs();
+ File[] all = inputDir.listFiles();
+ for (File file : all) {
+ if (file.isDirectory()) {
+ String oDir = outputDir.getAbsolutePath() + File.separator + file.getName();
+ File temp = new File (oDir);
+ writeToRepository(file, temp);
+ }else if(file.getName().toLowerCase().endsWith(".car"))
+ {
+ String oDir = outputDir.getAbsolutePath() + File.separator + file.getName();
+ File temp = new File (oDir);
+
+ ZipInputStream in=new ZipInputStream(new FileInputStream(file));
+ try {
+ byte[] buffer = new byte[10240];
+ for (ZipEntry entry = in.getNextEntry(); entry != null; entry = in.getNextEntry()) {
+ File zipFile = new File(temp, entry.getName());
+ if (entry.isDirectory()) {
+ zipFile.mkdirs();
+ } else {
+ if (!entry.getName().equals("META-INF/startup-jar")) {
+ zipFile.getParentFile().mkdirs();
+ OutputStream out = new FileOutputStream(zipFile);
+ try {
+ int count;
+ while ((count = in.read(buffer)) > 0) {
+ out.write(buffer, 0, count);
+ }
+ } finally {
+ out.close();
+ }
+ in.closeEntry();
+ }
+ }
+ }
+ } catch (IOException e) {
+ throw e;
+ } finally {
+ in.close();
+ }
+ }
+ else {
+ File entry = new File(outputDir + File.separator + file.getName());
+ FileOutputStream out = new FileOutputStream (entry);
+ FileInputStream in = new FileInputStream(file);
+ byte[] buf = new byte[10240];
+ int count;
+ try {
+ while ((count = in.read(buf, 0, buf.length)) > -1) {
+ out.write(buf, 0, count);
+ }
+ } finally {
+ in.close();
+ out.flush();
+ out.close();
+ }
+ }
+ }
+ Trace.tracePoint("Exit", "GeronimoServerPluginManager.writeToRepository");
+ }
+}
Modified: geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.ui/.classpath
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.ui/.classpath?rev=955877&r1=955876&r2=955877&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.ui/.classpath (original)
+++ geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.ui/.classpath Fri Jun 18 08:10:13 2010
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry kind="src" path="src/mainjava"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="target/classes"/>
Modified: geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.ui/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.ui/META-INF/MANIFEST.MF?rev=955877&r1=955876&r2=955877&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.ui/META-INF/MANIFEST.MF (original)
+++ geronimo/devtools/eclipse-plugin/branches/2.2.1/plugins/org.apache.geronimo.st.v22.ui/META-INF/MANIFEST.MF Fri Jun 18 08:10:13 2010
@@ -3,11 +3,9 @@ Bundle-ManifestVersion: 2
Bundle-Name: Geronimo Server Tools V22 UI Plug-in
Bundle-SymbolicName: org.apache.geronimo.st.v22.ui;singleton:=true
Bundle-Version: 2.2.1
-Bundle-Activator: org.apache.geronimo.st.v21.ui.Activator
Require-Bundle: org.apache.geronimo.runtime.common,
- org.apache.geronimo.st.v21.core,
- org.apache.geronimo.st.core,
- org.apache.geronimo.st.ui,
+ org.apache.geronimo.runtime.v22,
+ org.apache.geronimo.st.v22.core,
org.apache.geronimo.st.v21.ui,
org.apache.geronimo.jee.v21.jaxbmodel,
org.eclipse.ui,
@@ -15,6 +13,7 @@ Require-Bundle: org.apache.geronimo.runt
org.eclipse.core.commands,
org.eclipse.ui.forms,
org.eclipse.core.resources,
- org.eclipse.wst.common.project.facet.ui
+ org.eclipse.wst.common.project.facet.ui,
+ org.eclipse.wst.server.core
Bundle-ActivationPolicy: lazy
Bundle-Vendor: Apache Software Foundation