Author: koen.aers(a)jboss.com
Date: 2011-08-10 14:36:56 -0400 (Wed, 10 Aug 2011)
New Revision: 33780
Modified:
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeLaunchHelper.java
Log:
forge runtime swith to jboss modules
Modified:
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeLaunchHelper.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeLaunchHelper.java 2011-08-10
18:31:00 UTC (rev 33779)
+++
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeLaunchHelper.java 2011-08-10
18:36:56 UTC (rev 33780)
@@ -1,17 +1,11 @@
package org.jboss.tools.forge.core.process;
import java.io.File;
-import java.io.FileFilter;
-import java.io.FilenameFilter;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
@@ -21,26 +15,11 @@
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.JavaRuntime;
import org.jboss.tools.forge.core.ForgeCorePlugin;
+
public class ForgeLaunchHelper {
- private static final FilenameFilter JAR_FILTER = new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith("jar");
- }
- };
-
- private static final FilenameFilter LIB_FILTER = new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith("lib");
- }
- };
-
private static final ILaunchManager LAUNCH_MANAGER =
DebugPlugin.getDefault().getLaunchManager();
private static final ILaunchConfigurationType JAVA_LAUNCH_CONFIGURATION_TYPE =
@@ -62,91 +41,24 @@
ForgeCorePlugin.log(new RuntimeException("CoreException while cleaning up launch
configuration", e));
}
}
-
- private static List<String> createClassPath(String location) {
- List<String> result = new ArrayList<String>();
- result = addUserClasses(result, location);
- if (result != null) {
- result = addExtClasses(result);
- result = addSystemLibs(result);
- }
- return result;
- }
-
- private static List<String> addExtClasses(List<String> classPath) {
- try {
- File file =
FileLocator.getBundleFile(Platform.getBundle("org.jboss.tools.forge.runtime.ext"));
- if (file != null) {
- if (file.isDirectory()) {
- File[] files = file.listFiles(new FileFilter() {
- public boolean accept(File pathname) {
- return pathname.getAbsolutePath().endsWith("bin");
- }
- });
- if (files.length > 0) {
- classPath.add(createUserClassEntryMemento(files[0]));
- }
- } else {
- classPath.add(createUserClassEntryMemento(file));
- }
+
+ public static IProcess launch(String name, String location) {
+ IProcess result = null;
+ String launchConfigurationName = name + System.currentTimeMillis();
+ ILaunch launch = doLaunch(launchConfigurationName, location);
+ removeLaunchConfiguration(launchConfigurationName);
+ if (launch != null) {
+ IProcess[] processes = launch.getProcesses();
+ if (processes.length == 1) {
+ result = processes[0];
}
- } catch (IOException e) {
- ForgeCorePlugin.log(new RuntimeException("Problem while adding ext lib
entry", e));
}
- return classPath;
- }
-
- private static List<String> addSystemLibs(List<String> classPath) {
- try {
- IPath systemLibsPath = new Path(JavaRuntime.JRE_CONTAINER);
- IRuntimeClasspathEntry systemLibsEntry =
JavaRuntime.newRuntimeContainerClasspathEntry(
- systemLibsPath,
- IRuntimeClasspathEntry.STANDARD_CLASSES);
- classPath.add(systemLibsEntry.getMemento());
- return classPath;
- } catch (CoreException e) {
- ForgeCorePlugin.log(new RuntimeException("Problem while creating System libs
entry", e));
- return null;
- }
- }
-
- private static List<String> addUserClasses(List<String> classPath, String
location) {
- File file = new File(location);
- if (!file.exists()) {
- ForgeCorePlugin.log(new RuntimeException(location + " does not point to a correct
Forge runtime."));
- return null;
- } else {
- File[] children = file.listFiles(LIB_FILTER);
- if (children.length != 1) {
- ForgeCorePlugin.log(new RuntimeException(location + " does not point to a
correct Forge runtime."));
- return null;
- } else {
- for (File jarFile : children[0].listFiles(JAR_FILTER)) {
- String memento = createUserClassEntryMemento(jarFile);
- if (memento != null) {
- classPath.add(memento);
- }
- }
- return classPath;
- }
- }
- }
-
- private static String createUserClassEntryMemento(File file) {
- String result = null;
- try {
- IRuntimeClasspathEntry entry = JavaRuntime.newArchiveRuntimeClasspathEntry(new
Path(file.getAbsolutePath()));
- entry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
- result = entry.getMemento();
- } catch (CoreException e) {
- ForgeCorePlugin.log(new RuntimeException("Problem while creating classpath entry
memento", e));
- }
return result;
}
- private static ILaunch launch(String name, List<String> classPath) {
+ private static ILaunch doLaunch(String launchConfigurationName, String location) {
ILaunch launch = null;
- ILaunchConfigurationWorkingCopy workingCopy = createWorkingCopy(name, classPath);
+ ILaunchConfigurationWorkingCopy workingCopy =
createWorkingCopy(launchConfigurationName, location);
if (workingCopy != null) {
try {
launch = workingCopy.doSave().launch(ILaunchManager.RUN_MODE, null, false, false);
@@ -157,36 +69,55 @@
return launch;
}
- private static ILaunchConfigurationWorkingCopy createWorkingCopy(String name,
List<String> classPath) {
+
+
+ private static ILaunchConfigurationWorkingCopy createWorkingCopy(String name, String
location) {
ILaunchConfigurationWorkingCopy result = null;
try {
- result = JAVA_LAUNCH_CONFIGURATION_TYPE.newInstance(null, name);
- result.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
"org.jboss.forge.shell.Bootstrap");
- result.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classPath);
- result.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
+ String launchConfigurationName = name + System.currentTimeMillis();
+ result = JAVA_LAUNCH_CONFIGURATION_TYPE.newInstance(null, launchConfigurationName);
+ result.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
"org.jboss.modules.Main");
result.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
WORKING_DIR.getAbsolutePath());
- result.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
"-Dforge.compatibility.IDE=true");
+ result.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
createVmArguments(location));
+ result.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
createProgramArguments(location));
} catch (CoreException e) {
ForgeCorePlugin.log(new RuntimeException("Problem while creating launch
configuration working copy.", e));
}
return result;
}
- public static IProcess launch(String name, String location) {
- IProcess result = null;
- String launchConfigurationName = name + System.currentTimeMillis();
- List<String> classPath = createClassPath(location);
- if (classPath != null) {
- ILaunch launch = launch(launchConfigurationName, classPath);
- removeLaunchConfiguration(launchConfigurationName);
- if (launch != null) {
- IProcess[] processes = launch.getProcesses();
- if (processes.length == 1) {
- result = processes[0];
- }
- }
+ private static String createProgramArguments(String location) {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(createJBossModulesPathArgument(location)).append(' ');
+ buffer.append("org.jboss.forge");
+ return buffer.toString();
+ }
+
+ private static String createJBossModulesPathArgument(String location) {
+ StringBuffer buffer = new StringBuffer("-modulepath ");
+ buffer.append(location).append("/modules").append(File.pathSeparator);
+ buffer.append(System.getProperty("user.home")).append("/.forge/plugins").append(File.pathSeparator);
+ buffer.append(getExtLocation());
+ return buffer.toString();
+ }
+
+ private static String getExtLocation() {
+ String result = "";
+ try {
+ result =
FileLocator.getBundleFile(Platform.getBundle("org.jboss.tools.forge.runtime.ext")).getAbsolutePath()
+ "/modules";
+ } catch (IOException e) {
+ ForgeCorePlugin.log(new RuntimeException("Problem while obtaining location of
extra runtime classes.", e));
}
return result;
}
+ private static String createVmArguments(String location) {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("-Dforge.home=").append(location).append(' ');
+ buffer.append("-DDforge.shell.colorEnabled=true").append(' ');
+ buffer.append("-Dforge.compatibility.IDE=true").append(' ');
+ buffer.append("-cp ").append(location).append("/jboss-modules.jar
");
+ return buffer.toString();
+ }
+
}
Show replies by date