Author: rob.stryker(a)jboss.com
Date: 2008-10-21 18:06:31 -0400 (Tue, 21 Oct 2008)
New Revision: 11064
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerRuntime.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/LocalJBossServerRuntime.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/AbstractJBossLaunchConfigType.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/JBossServerStartupLaunchConfiguration.java
Log:
JBIDE-2735 - environment vars for native support
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerRuntime.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerRuntime.java 2008-10-21
21:54:02 UTC (rev 11063)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerRuntime.java 2008-10-21
22:06:31 UTC (rev 11064)
@@ -21,6 +21,8 @@
*/
package org.jboss.ide.eclipse.as.core.server;
+import java.util.HashMap;
+
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.wst.server.core.IRuntime;
@@ -43,4 +45,5 @@
// for startup
public String getDefaultRunArgs();
public String getDefaultRunVMArgs();
+ public HashMap<String, String> getDefaultRunEnvVars();
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/LocalJBossServerRuntime.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/LocalJBossServerRuntime.java 2008-10-21
21:54:02 UTC (rev 11063)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/LocalJBossServerRuntime.java 2008-10-21
22:06:31 UTC (rev 11064)
@@ -21,6 +21,8 @@
*/
package org.jboss.ide.eclipse.as.core.server.internal;
+import java.util.HashMap;
+
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
@@ -127,4 +129,10 @@
return ret;
}
+
+ public HashMap<String, String> getDefaultRunEnvVars(){
+ HashMap<String, String> envVars = new HashMap<String, String>(1);
+ envVars.put("Path", "native");
+ return envVars;
+ }
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/AbstractJBossLaunchConfigType.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/AbstractJBossLaunchConfigType.java 2008-10-21
21:54:02 UTC (rev 11063)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/AbstractJBossLaunchConfigType.java 2008-10-21
22:06:31 UTC (rev 11064)
@@ -1,219 +1,223 @@
-package org.jboss.ide.eclipse.as.core.server.internal.launch;
-
-import java.io.File;
-import java.io.FilenameFilter;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchManager;
-import org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate;
-import org.eclipse.jdt.launching.ExecutionArguments;
-import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
-import org.eclipse.jdt.launching.IVMInstall;
-import org.eclipse.jdt.launching.IVMRunner;
-import org.eclipse.jdt.launching.JavaRuntime;
-import org.eclipse.jdt.launching.VMRunnerConfiguration;
-import org.eclipse.jst.server.core.ServerProfilerDelegate;
-import org.eclipse.wst.server.core.IRuntime;
-import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.ServerCore;
-import org.eclipse.wst.server.core.ServerUtil;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.Messages;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
-import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
-import org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior;
-import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-
-public abstract class AbstractJBossLaunchConfigType extends
AbstractJavaLaunchConfigurationDelegate {
- public static final String SERVER_ID = "server-id";
-
- // we have no need to do anything in pre-launch check
- public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode,
IProgressMonitor monitor) throws CoreException {
- return true;
- }
-
- protected void preLaunch(ILaunchConfiguration configuration,
- String mode, ILaunch launch, IProgressMonitor monitor) {
- // override me
- }
- protected void postLaunch(ILaunchConfiguration configuration,
- String mode, ILaunch launch, IProgressMonitor monitor) {
- // override me
- }
-
- public void launch(ILaunchConfiguration configuration, String mode,
- ILaunch launch, IProgressMonitor monitor) throws CoreException {
- preLaunch(configuration, mode, launch, monitor);
- actualLaunch(configuration, mode, launch, monitor);
- postLaunch(configuration, mode, launch, monitor);
- }
-
- protected void actualLaunch(ILaunchConfiguration configuration,
- String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
- // And off we go!
- IVMInstall vm = verifyVMInstall(configuration);
- IVMRunner runner = vm.getVMRunner(mode);
-
- if(runner == null && ILaunchManager.PROFILE_MODE.equals(mode)){
- runner = vm.getVMRunner(ILaunchManager.RUN_MODE);
- }
- if(runner == null){
- throw new CoreException(new
Status(IStatus.ERROR,JBossServerCorePlugin.PLUGIN_ID,0,Messages.runModeNotSupported,null));
- }
-
- File workingDir = verifyWorkingDirectory(configuration);
- String workingDirName = null;
- if (workingDir != null)
- workingDirName = workingDir.getAbsolutePath();
-
- // Program & VM args
- String pgmArgs = getProgramArguments(configuration);
- String vmArgs = getVMArguments(configuration);
- ExecutionArguments execArgs = new ExecutionArguments(vmArgs, pgmArgs);
-
- // VM-specific attributes
- Map vmAttributesMap = getVMSpecificAttributesMap(configuration);
-
- // Classpath
- String[] classpath = getClasspath(configuration);
-
- // Create VM config
- String mainType = getMainTypeName(configuration);
- VMRunnerConfiguration runConfig = new VMRunnerConfiguration(mainType, classpath);
- runConfig.setProgramArguments(execArgs.getProgramArgumentsArray());
- runConfig.setVMArguments(execArgs.getVMArgumentsArray());
- runConfig.setWorkingDirectory(workingDirName);
- runConfig.setVMSpecificAttributesMap(vmAttributesMap);
-
- // Bootpath
- String[] bootpath = getBootpath(configuration);
- if (bootpath != null && bootpath.length > 0)
- runConfig.setBootClassPath(bootpath);
-
- setDefaultSourceLocator(launch, configuration);
-
- if (ILaunchManager.PROFILE_MODE.equals(mode)) {
- try {
- ServerProfilerDelegate.configureProfiling(launch, vm, runConfig, monitor);
- } catch (CoreException ce) {
- IServer server = ServerUtil.getServer(configuration);
- JBossServerBehavior jbsb = (JBossServerBehavior)
server.getAdapter(JBossServerBehavior.class);
- jbsb.stop(true);
- //genericServer.stopImpl();
- throw ce;
- }
- }
- // Launch the configuration
- runner.run(runConfig, launch, monitor);
- }
-
-
- protected static JBossServer findJBossServer(String serverId) throws CoreException {
- if( serverId == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"No server specified"));
-
- IServer s = ServerCore.findServer(serverId);
- if( s == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Server Not Found"));
-
- JBossServer jbs = ServerConverter.getJBossServer(s);
- if( jbs == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Server Not Found"));
-
- return jbs;
- }
-
- protected static IJBossServerRuntime findJBossServerRuntime(IServer server) throws
CoreException {
- IRuntime rt = server.getRuntime();
- IJBossServerRuntime jbrt = null;
- if( rt != null )
- jbrt = (IJBossServerRuntime)rt.loadAdapter(IJBossServerRuntime.class, new
NullProgressMonitor());
- if( jbrt == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Runtime Not Found"));
- return jbrt;
- }
-
- protected static void addCPEntry(ArrayList<IRuntimeClasspathEntry> list,
JBossServer jbs, String relative) {
- list.add(JavaRuntime.newArchiveRuntimeClasspathEntry(new
Path(getServerHome(jbs)).append(relative)));
- }
-
- @Deprecated
- protected static ArrayList<String>
convertClasspath(ArrayList<IRuntimeClasspathEntry> cp, IVMInstall vmInstall) {
- addJREEntry(cp, vmInstall);
- return convertClasspath(cp);
- }
-
- protected static void addJREEntry(ArrayList<IRuntimeClasspathEntry> cp, IVMInstall
vmInstall) {
- if (vmInstall != null) {
- try {
- cp.add(JavaRuntime.newRuntimeContainerClasspathEntry(
- new Path(JavaRuntime.JRE_CONTAINER)
- .append(vmInstall.getVMInstallType().getId()).append(vmInstall.getName()),
-// "org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType")
- IRuntimeClasspathEntry.BOOTSTRAP_CLASSES));
- } catch (CoreException e) {
- IStatus s = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
- "Unexpected Exception converting launch classpath: ", e);
- JBossServerCorePlugin.getDefault().getLog().log(s);
- }
- }
- }
-
- protected static ArrayList<String>
convertClasspath(ArrayList<IRuntimeClasspathEntry> cp) {
- Iterator<IRuntimeClasspathEntry> cpi = cp.iterator();
- ArrayList<String> list = new ArrayList<String>();
- while (cpi.hasNext()) {
- IRuntimeClasspathEntry entry = cpi.next();
- try {
- list.add(entry.getMemento());
- } catch (Exception e) {
- // Trace.trace(Trace.SEVERE, "Could not resolve classpath entry:
- // " + entry, e);
- }
- }
-
- return list;
- }
-
- protected static void addDirectory(String serverHome,
ArrayList<IRuntimeClasspathEntry> classpath,
- String dirName) {
- String libPath = serverHome + File.separator + dirName;
- File libDir = new File(libPath);
- File libs[] = libDir.listFiles(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return (name != null && name.endsWith("jar"));
- }
- });
-
- if (libs == null)
- return;
-
- for (int i = 0; i < libs.length; i++) {
- classpath.add(JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(
- libPath + File.separator + libs[i].getName())));
- }
- } // end method
-
-
- public static String getServerHome(JBossServer jbs) {
- return jbs.getServer().getRuntime().getLocation().toOSString();
- }
-
- public IVMInstall getVMInstall(ILaunchConfiguration configuration) throws CoreException
{
- String serverId = configuration.getAttribute(SERVER_ID, (String)null);
- JBossServer jbs = findJBossServer(serverId);
- IJBossServerRuntime jbrt = findJBossServerRuntime(jbs.getServer());
- return jbrt.getVM();
- }
-
-}
+package org.jboss.ide.eclipse.as.core.server.internal.launch;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate;
+import org.eclipse.jdt.launching.ExecutionArguments;
+import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
+import org.eclipse.jdt.launching.IVMInstall;
+import org.eclipse.jdt.launching.IVMRunner;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jdt.launching.VMRunnerConfiguration;
+import org.eclipse.jst.server.core.ServerProfilerDelegate;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerCore;
+import org.eclipse.wst.server.core.ServerUtil;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.ide.eclipse.as.core.Messages;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
+import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
+import org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+
+public abstract class AbstractJBossLaunchConfigType extends
AbstractJavaLaunchConfigurationDelegate {
+ public static final String SERVER_ID = "server-id";
+
+ // we have no need to do anything in pre-launch check
+ public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode,
IProgressMonitor monitor) throws CoreException {
+ return true;
+ }
+
+ protected void preLaunch(ILaunchConfiguration configuration,
+ String mode, ILaunch launch, IProgressMonitor monitor) {
+ // override me
+ }
+ protected void postLaunch(ILaunchConfiguration configuration,
+ String mode, ILaunch launch, IProgressMonitor monitor) {
+ // override me
+ }
+
+ public void launch(ILaunchConfiguration configuration, String mode,
+ ILaunch launch, IProgressMonitor monitor) throws CoreException {
+ preLaunch(configuration, mode, launch, monitor);
+ actualLaunch(configuration, mode, launch, monitor);
+ postLaunch(configuration, mode, launch, monitor);
+ }
+
+ protected void actualLaunch(ILaunchConfiguration configuration,
+ String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
+ // And off we go!
+ IVMInstall vm = verifyVMInstall(configuration);
+ IVMRunner runner = vm.getVMRunner(mode);
+
+ if(runner == null && ILaunchManager.PROFILE_MODE.equals(mode)){
+ runner = vm.getVMRunner(ILaunchManager.RUN_MODE);
+ }
+ if(runner == null){
+ throw new CoreException(new
Status(IStatus.ERROR,JBossServerCorePlugin.PLUGIN_ID,0,Messages.runModeNotSupported,null));
+ }
+
+ File workingDir = verifyWorkingDirectory(configuration);
+ String workingDirName = null;
+ if (workingDir != null)
+ workingDirName = workingDir.getAbsolutePath();
+
+ // Program & VM args
+ String pgmArgs = getProgramArguments(configuration);
+ String vmArgs = getVMArguments(configuration);
+ ExecutionArguments execArgs = new ExecutionArguments(vmArgs, pgmArgs);
+
+ // VM-specific attributes
+ Map vmAttributesMap = getVMSpecificAttributesMap(configuration);
+
+ // Classpath
+ String[] classpath = getClasspath(configuration);
+
+ // Environment
+ String[] environment = getEnvironment(configuration);
+
+ // Create VM config
+ String mainType = getMainTypeName(configuration);
+ VMRunnerConfiguration runConfig = new VMRunnerConfiguration(mainType, classpath);
+ runConfig.setProgramArguments(execArgs.getProgramArgumentsArray());
+ runConfig.setVMArguments(execArgs.getVMArgumentsArray());
+ runConfig.setWorkingDirectory(workingDirName);
+ runConfig.setVMSpecificAttributesMap(vmAttributesMap);
+ runConfig.setEnvironment(environment);
+
+ // Bootpath
+ String[] bootpath = getBootpath(configuration);
+ if (bootpath != null && bootpath.length > 0)
+ runConfig.setBootClassPath(bootpath);
+
+ setDefaultSourceLocator(launch, configuration);
+
+ if (ILaunchManager.PROFILE_MODE.equals(mode)) {
+ try {
+ ServerProfilerDelegate.configureProfiling(launch, vm, runConfig, monitor);
+ } catch (CoreException ce) {
+ IServer server = ServerUtil.getServer(configuration);
+ JBossServerBehavior jbsb = (JBossServerBehavior)
server.getAdapter(JBossServerBehavior.class);
+ jbsb.stop(true);
+ //genericServer.stopImpl();
+ throw ce;
+ }
+ }
+ // Launch the configuration
+ runner.run(runConfig, launch, monitor);
+ }
+
+
+ protected static JBossServer findJBossServer(String serverId) throws CoreException {
+ if( serverId == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"No server specified"));
+
+ IServer s = ServerCore.findServer(serverId);
+ if( s == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Server Not Found"));
+
+ JBossServer jbs = ServerConverter.getJBossServer(s);
+ if( jbs == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Server Not Found"));
+
+ return jbs;
+ }
+
+ protected static IJBossServerRuntime findJBossServerRuntime(IServer server) throws
CoreException {
+ IRuntime rt = server.getRuntime();
+ IJBossServerRuntime jbrt = null;
+ if( rt != null )
+ jbrt = (IJBossServerRuntime)rt.loadAdapter(IJBossServerRuntime.class, new
NullProgressMonitor());
+ if( jbrt == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Runtime Not Found"));
+ return jbrt;
+ }
+
+ protected static void addCPEntry(ArrayList<IRuntimeClasspathEntry> list,
JBossServer jbs, String relative) {
+ list.add(JavaRuntime.newArchiveRuntimeClasspathEntry(new
Path(getServerHome(jbs)).append(relative)));
+ }
+
+ @Deprecated
+ protected static ArrayList<String>
convertClasspath(ArrayList<IRuntimeClasspathEntry> cp, IVMInstall vmInstall) {
+ addJREEntry(cp, vmInstall);
+ return convertClasspath(cp);
+ }
+
+ protected static void addJREEntry(ArrayList<IRuntimeClasspathEntry> cp, IVMInstall
vmInstall) {
+ if (vmInstall != null) {
+ try {
+ cp.add(JavaRuntime.newRuntimeContainerClasspathEntry(
+ new Path(JavaRuntime.JRE_CONTAINER)
+ .append(vmInstall.getVMInstallType().getId()).append(vmInstall.getName()),
+// "org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType")
+ IRuntimeClasspathEntry.BOOTSTRAP_CLASSES));
+ } catch (CoreException e) {
+ IStatus s = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
+ "Unexpected Exception converting launch classpath: ", e);
+ JBossServerCorePlugin.getDefault().getLog().log(s);
+ }
+ }
+ }
+
+ protected static ArrayList<String>
convertClasspath(ArrayList<IRuntimeClasspathEntry> cp) {
+ Iterator<IRuntimeClasspathEntry> cpi = cp.iterator();
+ ArrayList<String> list = new ArrayList<String>();
+ while (cpi.hasNext()) {
+ IRuntimeClasspathEntry entry = cpi.next();
+ try {
+ list.add(entry.getMemento());
+ } catch (Exception e) {
+ // Trace.trace(Trace.SEVERE, "Could not resolve classpath entry:
+ // " + entry, e);
+ }
+ }
+
+ return list;
+ }
+
+ protected static void addDirectory(String serverHome,
ArrayList<IRuntimeClasspathEntry> classpath,
+ String dirName) {
+ String libPath = serverHome + File.separator + dirName;
+ File libDir = new File(libPath);
+ File libs[] = libDir.listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return (name != null && name.endsWith("jar"));
+ }
+ });
+
+ if (libs == null)
+ return;
+
+ for (int i = 0; i < libs.length; i++) {
+ classpath.add(JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(
+ libPath + File.separator + libs[i].getName())));
+ }
+ } // end method
+
+
+ public static String getServerHome(JBossServer jbs) {
+ return jbs.getServer().getRuntime().getLocation().toOSString();
+ }
+
+ public IVMInstall getVMInstall(ILaunchConfiguration configuration) throws CoreException
{
+ String serverId = configuration.getAttribute(SERVER_ID, (String)null);
+ JBossServer jbs = findJBossServer(serverId);
+ IJBossServerRuntime jbrt = findJBossServerRuntime(jbs.getServer());
+ return jbrt.getVM();
+ }
+
+}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/JBossServerStartupLaunchConfiguration.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/JBossServerStartupLaunchConfiguration.java 2008-10-21
21:54:02 UTC (rev 11063)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/JBossServerStartupLaunchConfiguration.java 2008-10-21
22:06:31 UTC (rev 11064)
@@ -1,222 +1,231 @@
-/**
- * JBoss, a Division of Red Hat
- * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
-* This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.ide.eclipse.as.core.server.internal.launch;
-
-import java.util.ArrayList;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationType;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.debug.core.ILaunchManager;
-import org.eclipse.debug.core.model.IProcess;
-import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
-import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
-import org.eclipse.jdt.launching.IVMInstall;
-import org.eclipse.jdt.launching.JavaRuntime;
-import org.eclipse.jdt.launching.StandardClasspathProvider;
-import org.eclipse.wst.server.core.IRuntime;
-import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.ServerUtil;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
-import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
-import org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior;
-
-public class JBossServerStartupLaunchConfiguration extends AbstractJBossLaunchConfigType
{
-
- protected static final char[] INVALID_CHARS = new char[] {'\\', '/',
':', '*', '?', '"', '<', '>',
'|', '\0', '@', '&'};
- private static final String LAUNCH_TYPE =
"org.jboss.ide.eclipse.as.core.server.startupConfiguration";
- private static final String DEFAULTS_SET = "jboss.defaults.been.set";
- private static final String START_JAR_LOC = "bin" + Path.SEPARATOR +
"run.jar";
- private static final String START_MAIN_TYPE = "org.jboss.Main";
-
-
- public static ILaunchConfigurationWorkingCopy setupLaunchConfiguration(IServer server,
String action) throws CoreException {
- ILaunchConfigurationWorkingCopy config = createLaunchConfiguration(server);
- setupLaunchConfiguration(config, server);
- return config;
- }
-
- public static void setupLaunchConfiguration(
- ILaunchConfigurationWorkingCopy workingCopy, IServer server) throws CoreException {
- if(!workingCopy.getAttributes().containsKey(DEFAULTS_SET)) {
- forceDefaultsSet(workingCopy, server);
- }
- }
-
- public static void forceDefaultsSet(ILaunchConfigurationWorkingCopy wc, IServer server)
throws CoreException {
- JBossServer jbs = findJBossServer(server.getId());
- if( jbs == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Server " + server.getName() + " is not a proper JBoss Server"));
-
- String serverHome = getServerHome(jbs);
- if( serverHome == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Server " + server.getName() + " is corrupt and the server home is unable
to be located."));
-
- IRuntime rt = jbs.getServer().getRuntime();
- String jrePath = null;
- if( rt != null ) {
- IJBossServerRuntime jbrt =
(IJBossServerRuntime)rt.getAdapter(IJBossServerRuntime.class);
- if( jbrt != null ) {
- IVMInstall install = jbrt.getVM();
- IPath path = JavaRuntime.newJREContainerPath(install);
- jrePath = path.toPortableString();
- }
- }
-
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
getDefaultArgs(jbs));
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
getDefaultVMArgs(jbs));
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
START_MAIN_TYPE);
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, serverHome +
Path.SEPARATOR + "bin");
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER,
"org.jboss.ide.eclipse.as.core.launch.classpathProvider");
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, jrePath);
- wc.setAttribute(DEFAULTS_SET, true);
- }
-
- public static String getDefaultArgs(JBossServer jbs) throws CoreException {
- IJBossServerRuntime rt = findJBossServerRuntime(jbs.getServer());
- if (rt != null) {
- return rt.getDefaultRunArgs() + " -b " + jbs.getServer().getHost();
- }
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Runtime not found"));
- }
-
- public static String getDefaultVMArgs(JBossServer jbs) throws CoreException {
- IJBossServerRuntime rt = findJBossServerRuntime(jbs.getServer());
- if (rt != null) {
- return rt.getDefaultRunVMArgs();
- }
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Runtime not found"));
- }
-
-
- protected void preLaunch(ILaunchConfiguration configuration,
- String mode, ILaunch launch, IProgressMonitor monitor) {
- try {
- JBossServerBehavior jbsBehavior = getServerBehavior(configuration);
- jbsBehavior.setRunMode(mode);
- jbsBehavior.serverStarting();
- } catch( CoreException ce ) {
- // report it
- }
- }
-
- public void postLaunch(ILaunchConfiguration configuration, String mode,
- ILaunch launch, IProgressMonitor monitor) {
- try {
- IProcess[] processes = launch.getProcesses();
- JBossServerBehavior jbsBehavior = getServerBehavior(configuration);
- jbsBehavior.setProcess(processes[0]);
- } catch( CoreException ce ) {
- // report
- }
- }
-
- public static JBossServerBehavior getServerBehavior(ILaunchConfiguration configuration)
throws CoreException {
- IServer server = ServerUtil.getServer(configuration);
- JBossServerBehavior jbossServerBehavior = (JBossServerBehavior)
server.getAdapter(JBossServerBehavior.class);
- return jbossServerBehavior;
- }
-
- protected static String getValidLaunchConfigurationName(String s) {
- if (s == null || s.length() == 0)
- return "1";
- int size = INVALID_CHARS.length;
- for (int i = 0; i < size; i++) {
- s = s.replace(INVALID_CHARS[i], '_');
- }
- return s;
- }
-
- /**
- * Will create a launch configuration for the server
- * if one does not already exist.
- */
- public static ILaunchConfigurationWorkingCopy createLaunchConfiguration(IServer server)
throws CoreException {
- ILaunchConfigurationType launchConfigType =
DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(LAUNCH_TYPE);
- if (launchConfigType == null)
- return null;
-
- ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
- ILaunchConfiguration[] launchConfigs = null;
- try {
- launchConfigs = launchManager.getLaunchConfigurations(launchConfigType);
- } catch (CoreException e) {
- // ignore
- }
-
- if (launchConfigs != null) {
- int size = launchConfigs.length;
- for (int i = 0; i < size; i++) {
- try {
- String serverId = launchConfigs[i].getAttribute(SERVER_ID, (String) null);
- if (server.getId().equals(serverId)) {
- ILaunchConfigurationWorkingCopy wc = launchConfigs[i].getWorkingCopy();
- return wc;
- }
- } catch (CoreException e) {
- }
- }
- }
-
- // create a new launch configuration
- String launchName = getValidLaunchConfigurationName(server.getName());
- launchName = launchManager.generateUniqueLaunchConfigurationNameFrom(launchName);
- ILaunchConfigurationWorkingCopy wc = launchConfigType.newInstance(null, launchName);
- wc.setAttribute(SERVER_ID, server.getId());
- return wc;
- }
-
-
- public static class StartupClasspathProvider extends StandardClasspathProvider {
-
- public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration
configuration) throws CoreException {
- boolean useDefault =
configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH,
true);
- if (useDefault) {
- return computeUnresolvedDefaultClasspath(configuration);
- }
- // recover persisted classpath
- return recoverRuntimePath(configuration,
IJavaLaunchConfigurationConstants.ATTR_CLASSPATH);
- }
-
- protected IRuntimeClasspathEntry[]
computeUnresolvedDefaultClasspath(ILaunchConfiguration configuration) throws CoreException
{
- String serverId = configuration.getAttribute(SERVER_ID, (String)null);
- JBossServer jbs = findJBossServer(serverId);
- IJBossServerRuntime jbrt = findJBossServerRuntime(jbs.getServer());
- ArrayList<IRuntimeClasspathEntry> classpath = new
ArrayList<IRuntimeClasspathEntry>();
- addCPEntry(classpath, jbs, START_JAR_LOC);
- addJREEntry(classpath, jbrt.getVM());
- return (IRuntimeClasspathEntry[]) classpath
- .toArray(new IRuntimeClasspathEntry[classpath.size()]);
- }
-
- }
-
-}
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+* This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as.core.server.internal.launch;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
+import org.eclipse.jdt.launching.IVMInstall;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jdt.launching.StandardClasspathProvider;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerUtil;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
+import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
+import org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior;
+
+public class JBossServerStartupLaunchConfiguration extends AbstractJBossLaunchConfigType
{
+
+ protected static final char[] INVALID_CHARS = new char[] {'\\', '/',
':', '*', '?', '"', '<', '>',
'|', '\0', '@', '&'};
+ private static final String LAUNCH_TYPE =
"org.jboss.ide.eclipse.as.core.server.startupConfiguration";
+ private static final String DEFAULTS_SET = "jboss.defaults.been.set";
+ private static final String START_JAR_LOC = "bin" + Path.SEPARATOR +
"run.jar";
+ private static final String START_MAIN_TYPE = "org.jboss.Main";
+
+
+ public static ILaunchConfigurationWorkingCopy setupLaunchConfiguration(IServer server,
String action) throws CoreException {
+ ILaunchConfigurationWorkingCopy config = createLaunchConfiguration(server);
+ setupLaunchConfiguration(config, server);
+ return config;
+ }
+
+ public static void setupLaunchConfiguration(
+ ILaunchConfigurationWorkingCopy workingCopy, IServer server) throws CoreException {
+ if(!workingCopy.getAttributes().containsKey(DEFAULTS_SET)) {
+ forceDefaultsSet(workingCopy, server);
+ }
+ }
+
+ public static void forceDefaultsSet(ILaunchConfigurationWorkingCopy wc, IServer server)
throws CoreException {
+ JBossServer jbs = findJBossServer(server.getId());
+ if( jbs == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Server " + server.getName() + " is not a proper JBoss Server"));
+
+ String serverHome = getServerHome(jbs);
+ if( serverHome == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Server " + server.getName() + " is corrupt and the server home is unable
to be located."));
+
+ IRuntime rt = jbs.getServer().getRuntime();
+ String jrePath = null;
+ if( rt != null ) {
+ IJBossServerRuntime jbrt =
(IJBossServerRuntime)rt.getAdapter(IJBossServerRuntime.class);
+ if( jbrt != null ) {
+ IVMInstall install = jbrt.getVM();
+ IPath path = JavaRuntime.newJREContainerPath(install);
+ jrePath = path.toPortableString();
+ }
+ }
+
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
getDefaultArgs(jbs));
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
getDefaultVMArgs(jbs));
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
START_MAIN_TYPE);
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, serverHome +
Path.SEPARATOR + "bin");
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER,
"org.jboss.ide.eclipse.as.core.launch.classpathProvider");
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, jrePath);
+ wc.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, getDefaultEnvVars(jbs));
+ wc.setAttribute(DEFAULTS_SET, true);
+ }
+
+ public static String getDefaultArgs(JBossServer jbs) throws CoreException {
+ IJBossServerRuntime rt = findJBossServerRuntime(jbs.getServer());
+ if (rt != null) {
+ return rt.getDefaultRunArgs() + " -b " + jbs.getServer().getHost();
+ }
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Runtime not found"));
+ }
+
+ public static String getDefaultVMArgs(JBossServer jbs) throws CoreException {
+ IJBossServerRuntime rt = findJBossServerRuntime(jbs.getServer());
+ if (rt != null) {
+ return rt.getDefaultRunVMArgs();
+ }
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Runtime not found"));
+ }
+
+ public static HashMap<String, String> getDefaultEnvVars(JBossServer jbs) throws
CoreException {
+ IJBossServerRuntime rt = findJBossServerRuntime(jbs.getServer());
+ if (rt != null) {
+ return rt.getDefaultRunEnvVars();
+ }
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Runtime not found"));
+ }
+
+ protected void preLaunch(ILaunchConfiguration configuration,
+ String mode, ILaunch launch, IProgressMonitor monitor) {
+ try {
+ JBossServerBehavior jbsBehavior = getServerBehavior(configuration);
+ jbsBehavior.setRunMode(mode);
+ jbsBehavior.serverStarting();
+ } catch( CoreException ce ) {
+ // report it
+ }
+ }
+
+ public void postLaunch(ILaunchConfiguration configuration, String mode,
+ ILaunch launch, IProgressMonitor monitor) {
+ try {
+ IProcess[] processes = launch.getProcesses();
+ JBossServerBehavior jbsBehavior = getServerBehavior(configuration);
+ jbsBehavior.setProcess(processes[0]);
+ } catch( CoreException ce ) {
+ // report
+ }
+ }
+
+ public static JBossServerBehavior getServerBehavior(ILaunchConfiguration configuration)
throws CoreException {
+ IServer server = ServerUtil.getServer(configuration);
+ JBossServerBehavior jbossServerBehavior = (JBossServerBehavior)
server.getAdapter(JBossServerBehavior.class);
+ return jbossServerBehavior;
+ }
+
+ protected static String getValidLaunchConfigurationName(String s) {
+ if (s == null || s.length() == 0)
+ return "1";
+ int size = INVALID_CHARS.length;
+ for (int i = 0; i < size; i++) {
+ s = s.replace(INVALID_CHARS[i], '_');
+ }
+ return s;
+ }
+
+ /**
+ * Will create a launch configuration for the server
+ * if one does not already exist.
+ */
+ public static ILaunchConfigurationWorkingCopy createLaunchConfiguration(IServer server)
throws CoreException {
+ ILaunchConfigurationType launchConfigType =
DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(LAUNCH_TYPE);
+ if (launchConfigType == null)
+ return null;
+
+ ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfiguration[] launchConfigs = null;
+ try {
+ launchConfigs = launchManager.getLaunchConfigurations(launchConfigType);
+ } catch (CoreException e) {
+ // ignore
+ }
+
+ if (launchConfigs != null) {
+ int size = launchConfigs.length;
+ for (int i = 0; i < size; i++) {
+ try {
+ String serverId = launchConfigs[i].getAttribute(SERVER_ID, (String) null);
+ if (server.getId().equals(serverId)) {
+ ILaunchConfigurationWorkingCopy wc = launchConfigs[i].getWorkingCopy();
+ return wc;
+ }
+ } catch (CoreException e) {
+ }
+ }
+ }
+
+ // create a new launch configuration
+ String launchName = getValidLaunchConfigurationName(server.getName());
+ launchName = launchManager.generateUniqueLaunchConfigurationNameFrom(launchName);
+ ILaunchConfigurationWorkingCopy wc = launchConfigType.newInstance(null, launchName);
+ wc.setAttribute(SERVER_ID, server.getId());
+ return wc;
+ }
+
+
+ public static class StartupClasspathProvider extends StandardClasspathProvider {
+
+ public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration
configuration) throws CoreException {
+ boolean useDefault =
configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH,
true);
+ if (useDefault) {
+ return computeUnresolvedDefaultClasspath(configuration);
+ }
+ // recover persisted classpath
+ return recoverRuntimePath(configuration,
IJavaLaunchConfigurationConstants.ATTR_CLASSPATH);
+ }
+
+ protected IRuntimeClasspathEntry[]
computeUnresolvedDefaultClasspath(ILaunchConfiguration configuration) throws CoreException
{
+ String serverId = configuration.getAttribute(SERVER_ID, (String)null);
+ JBossServer jbs = findJBossServer(serverId);
+ IJBossServerRuntime jbrt = findJBossServerRuntime(jbs.getServer());
+ ArrayList<IRuntimeClasspathEntry> classpath = new
ArrayList<IRuntimeClasspathEntry>();
+ addCPEntry(classpath, jbs, START_JAR_LOC);
+ addJREEntry(classpath, jbrt.getVM());
+ return (IRuntimeClasspathEntry[]) classpath
+ .toArray(new IRuntimeClasspathEntry[classpath.size()]);
+ }
+
+ }
+
+}