Author: koen.aers(a)jboss.com
Date: 2011-06-09 05:22:01 -0400 (Thu, 09 Jun 2011)
New Revision: 31954
Added:
trunk/forge/plugins/org.jboss.tools.forge.core/.classpath
trunk/forge/plugins/org.jboss.tools.forge.core/.project
trunk/forge/plugins/org.jboss.tools.forge.core/.settings/
trunk/forge/plugins/org.jboss.tools.forge.core/.settings/org.eclipse.jdt.core.prefs
trunk/forge/plugins/org.jboss.tools.forge.core/META-INF/
trunk/forge/plugins/org.jboss.tools.forge.core/META-INF/MANIFEST.MF
trunk/forge/plugins/org.jboss.tools.forge.core/build.properties
trunk/forge/plugins/org.jboss.tools.forge.core/src/
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/ForgeCorePlugin.java
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/io/
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeInstallations.java
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/ForgeRuntime.java
Log:
split forge plugin in runtime/core/ui triplet
Added: trunk/forge/plugins/org.jboss.tools.forge.core/.classpath
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.core/.classpath (rev
0)
+++ trunk/forge/plugins/org.jboss.tools.forge.core/.classpath 2011-06-09 09:22:01 UTC (rev
31954)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/forge/plugins/org.jboss.tools.forge.core/.project
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.core/.project (rev
0)
+++ trunk/forge/plugins/org.jboss.tools.forge.core/.project 2011-06-09 09:22:01 UTC (rev
31954)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.tools.forge.core</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added:
trunk/forge/plugins/org.jboss.tools.forge.core/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.core/.settings/org.eclipse.jdt.core.prefs
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.forge.core/.settings/org.eclipse.jdt.core.prefs 2011-06-09
09:22:01 UTC (rev 31954)
@@ -0,0 +1,8 @@
+#Tue May 31 15:58:07 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
Added: trunk/forge/plugins/org.jboss.tools.forge.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.core/META-INF/MANIFEST.MF
(rev 0)
+++ trunk/forge/plugins/org.jboss.tools.forge.core/META-INF/MANIFEST.MF 2011-06-09
09:22:01 UTC (rev 31954)
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Forge Core
+Bundle-SymbolicName: org.jboss.tools.forge.core;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
+ org.eclipse.debug.core;bundle-version="3.7.0",
+ org.eclipse.jdt.launching;bundle-version="3.6.0"
+Bundle-ActivationPolicy: lazy
+Export-Package: org.jboss.tools.forge.core,
+ org.jboss.tools.forge.core.process
+Bundle-Activator: org.jboss.tools.forge.core.ForgeCorePlugin
Added: trunk/forge/plugins/org.jboss.tools.forge.core/build.properties
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.core/build.properties
(rev 0)
+++ trunk/forge/plugins/org.jboss.tools.forge.core/build.properties 2011-06-09 09:22:01
UTC (rev 31954)
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
Added:
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/ForgeCorePlugin.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/ForgeCorePlugin.java
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/ForgeCorePlugin.java 2011-06-09
09:22:01 UTC (rev 31954)
@@ -0,0 +1,36 @@
+package org.jboss.tools.forge.core;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
+import org.osgi.framework.BundleContext;
+
+public class ForgeCorePlugin extends Plugin {
+
+ public static final String PLUGIN_ID = "org.jboss.tools.forge.core";
+
+ private static ForgeCorePlugin plugin;
+
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ public static ForgeCorePlugin getDefault() {
+ return plugin;
+ }
+
+ public static void log(Throwable t) {
+ getDefault().getLog().log(newErrorStatus("Error logged from Forge Core Plugin:
", t));
+ }
+
+ private static IStatus newErrorStatus(String message, Throwable exception) {
+ return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.INFO, message, exception);
+ }
+
+}
Added:
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeInstallations.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeInstallations.java
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeInstallations.java 2011-06-09
09:22:01 UTC (rev 31954)
@@ -0,0 +1,5 @@
+package org.jboss.tools.forge.core.process;
+
+public class ForgeInstallations {
+
+}
Added:
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
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeLaunchHelper.java 2011-06-09
09:22:01 UTC (rev 31954)
@@ -0,0 +1,164 @@
+package org.jboss.tools.forge.core.process;
+
+import java.io.File;
+import java.io.FilenameFilter;
+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.IPath;
+import org.eclipse.core.runtime.Path;
+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.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 =
+ LAUNCH_MANAGER.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
+
+ private static final File WORKING_DIR =
ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile();
+
+ private static void removeLaunchConfiguration(String name) {
+ try {
+ ILaunchConfiguration[] configurations =
LAUNCH_MANAGER.getLaunchConfigurations(JAVA_LAUNCH_CONFIGURATION_TYPE);
+ for (int i = 0; i < configurations.length; i++) {
+ ILaunchConfiguration configuration = configurations[i];
+ if (configuration.getName().equals(name)) {
+ configuration.delete();
+ break;
+ }
+ }
+ } catch (CoreException e) {
+ 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 = addSystemLibs(result);
+ }
+ return result;
+ }
+
+ 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) {
+ ILaunch launch = null;
+ ILaunchConfigurationWorkingCopy workingCopy = createWorkingCopy(name, classPath);
+ if (workingCopy != null) {
+ try {
+ launch = workingCopy.doSave().launch(ILaunchManager.RUN_MODE, null, false, false);
+ } catch (CoreException e) {
+ ForgeCorePlugin.log(new RuntimeException("Problem while launching working
copy.", e));
+ }
+ }
+ return launch;
+ }
+
+ private static ILaunchConfigurationWorkingCopy createWorkingCopy(String name,
List<String> classPath) {
+ 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);
+ result.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
WORKING_DIR.getAbsolutePath());
+ result.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
"-Dforge.compatibility.IDE=true");
+ } 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];
+ }
+ }
+ }
+ return result;
+ }
+
+}
Added:
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeRuntime.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeRuntime.java
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeRuntime.java 2011-06-09
09:22:01 UTC (rev 31954)
@@ -0,0 +1,39 @@
+package org.jboss.tools.forge.core.process;
+
+import java.beans.PropertyChangeSupport;
+
+import org.eclipse.debug.core.model.IProcess;
+
+public class ForgeRuntime {
+
+ public static final String STATE_NOT_RUNNING =
"org.jboss.tools.forge.notRunning";
+ public static final String STATE_RUNNING = "org.jboss.tools.forge.running";
+ public static final String STATE_STARTING = "org.jboss.tools.forge.starting";
+ public static final String STATE_STOPPING = "org.jboss.tools.forge.stopping";
+
+ private IProcess forgeProcess = null;
+ private String runtimeState = STATE_NOT_RUNNING;
+ private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
+
+ private String name;
+ private String location;
+
+ public ForgeRuntime(String name, String location) {
+ this.name = name;
+ this.location = location;
+ }
+
+ public void start() {
+ if (!isTerminated()) return;
+
+ }
+
+ public void stop() {
+ if (isTerminated()) return;
+ }
+
+ public boolean isTerminated() {
+ return forgeProcess == null || forgeProcess.isTerminated();
+ }
+
+}