Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[eclipse] Add application runner for running inside the SARL project VM.
Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Sep 10, 2016
1 parent 082c8ba commit 3b9cfdb
Show file tree
Hide file tree
Showing 15 changed files with 207 additions and 17 deletions.
17 changes: 10 additions & 7 deletions eclipse-sarl/features/io.sarl.ide/feature.xml
Expand Up @@ -226,6 +226,7 @@ tools upon the Eclipse IDE.
<import plugin="io.sarl.lang.ui" version="0.4.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.xtend.core" version="2.10.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.xtext.ui" version="2.10.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.xtext.common.types.ui" version="2.10.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.ui.ide" version="3.12.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.core.filesystem" version="1.6.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.equinox.bidi" version="1.0.0" match="greaterOrEqual"/>
Expand All @@ -234,18 +235,14 @@ tools upon the Eclipse IDE.
<import plugin="org.eclipse.jdt.ui" version="3.12.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.jdt.launching" version="3.8.100" match="greaterOrEqual"/>
<import plugin="org.eclipse.jdt.debug.ui" version="3.7.200" match="greaterOrEqual"/>
<import plugin="org.eclipse.search" version="3.11.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.ui.console" version="3.6.200" match="greaterOrEqual"/>
<import plugin="org.eclipse.ui" version="3.108.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.core.runtime" version="3.12.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.core.resources" version="3.11.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.ui" version="3.108.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.m2e.maven.runtime" version="1.7.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.m2e.core" version="1.7.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.m2e.jdt" version="1.7.0" match="greaterOrEqual"/>
<import feature="io.sarl.compiler" version="0.4.0.qualifier"/>
<import feature="org.eclipse.m2e.feature" version="1.7.0.20160603-1933"/>
<import feature="org.jboss.tools.m2e.jdt.feature" version="1.0.1.201209200903"/>
<import plugin="org.eclipse.xtext.common.types.ui" version="2.10.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.search" version="3.11.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.ui.console" version="3.6.200" match="greaterOrEqual"/>
<import plugin="org.eclipse.core.expressions" version="3.4.0" match="compatible"/>
<import plugin="org.eclipse.ui" version="3.5.0" match="compatible"/>
<import plugin="org.eclipse.ui.console" version="3.5.300" match="compatible"/>
Expand All @@ -259,6 +256,12 @@ tools upon the Eclipse IDE.
<import plugin="org.eclipse.core.filesystem" version="1.2.0" match="compatible"/>
<import plugin="org.eclipse.core.resources" version="3.5.0" match="compatible"/>
<import plugin="org.eclipse.core.runtime" version="3.3.0" match="compatible"/>
<import feature="org.eclipse.m2e.feature" version="1.7.0.20160603-1933"/>
<import feature="org.jboss.tools.m2e.jdt.feature" version="1.0.1.201209200903"/>
<import plugin="org.eclipse.ui.intro" version="3.5.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.ui.intro.quicklinks" version="1.0.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.ui.intro.universal" version="3.3.0" match="greaterOrEqual"/>
<import plugin="org.arakhne.afc.core.vmutils" version="14.0.0" match="greaterOrEqual"/>
</requires>

<plugin
Expand Down
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?><target name="io.sarl.lang.targetplatform" sequenceNumber="95">
<?pde version="3.8"?><target name="io.sarl.lang.targetplatform" sequenceNumber="96">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.xtend.sdk.feature.group" version="2.10.0.v201605250459"/>
Expand All @@ -26,14 +26,6 @@
<repository location="http://download.jboss.org/jbosstools/updates/m2e-extensions/m2e-jdt-compiler/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="net.bytebuddy.byte-buddy" version="1.4.17"/>
<unit id="org.objenesis" version="2.4.0"/>
<unit id="org.arakhne.afc.core.references" version="14.0.0.20160829082847"/>
<unit id="org.mockito.mockito-core" version="2.0.111.beta"/>
<unit id="org.arakhne.afc.core.vmutils" version="14.0.0.20160829082847"/>
<repository location="http://download.tuxfamily.org/arakhne/p2/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="aopalliance.source" version="1.0.0"/>
<unit id="com.google.inject" version="4.0.0"/>
<unit id="javassist" version="3.20.0.GA"/>
Expand All @@ -52,6 +44,15 @@
<unit id="javax.inject.javax.inject.source" version="1.0.0"/>
<repository location="http://dependencies.sarl.io"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.arakhne.afc.core.vmutils" version="14.0.0.20160829082847"/>
<unit id="net.bytebuddy.byte-buddy" version="1.4.17"/>
<unit id="org.objenesis" version="2.4.0"/>
<unit id="org.arakhne.afc.core.util" version="14.0.0.20160829082847"/>
<unit id="org.mockito.mockito-core" version="2.0.111.beta"/>
<unit id="org.arakhne.afc.core.references" version="14.0.0.20160829082847"/>
<repository location="http://download.tuxfamily.org/arakhne/p2/"/>
</location>
</locations>
<targetJRE path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
</target>
3 changes: 2 additions & 1 deletion eclipse-sarl/plugins/io.sarl.eclipse/META-INF/MANIFEST.MF
Expand Up @@ -26,7 +26,8 @@ Require-Bundle: io.sarl.lang.ui;bundle-version="0.4.0";visibility:=reexport,
org.eclipse.ui,
org.eclipse.ui.intro;bundle-version="3.5.0",
org.eclipse.ui.intro.quicklinks;bundle-version="1.0.0",
org.eclipse.ui.intro.universal;bundle-version="3.3.0"
org.eclipse.ui.intro.universal;bundle-version="3.3.0",
org.arakhne.afc.core.vmutils;bundle-version="14.0.0"
Bundle-Activator: io.sarl.eclipse.SARLEclipsePlugin
Export-Package: io.sarl.eclipse,
io.sarl.eclipse.buildpath,
Expand Down
Expand Up @@ -133,4 +133,11 @@ public interface ILaunchConfigurationAccessor {
*/
String getJRELaunchingArguments(ILaunchConfiguration configuration);

/** Replies the agent should be launched in the current Eclipse VM.
*
* @param configuration the configuration.
* @return <code>true</code> if the current Eclipse VM must be used for running the agent.
*/
boolean isEmbeddedSRE(ILaunchConfiguration configuration);

}
Expand Up @@ -143,4 +143,11 @@ void setLaunchingFlags(ILaunchConfigurationWorkingCopy configuration, Boolean sh
*/
void setJRELaunchingArguments(ILaunchConfigurationWorkingCopy configuration, String arguments);

/** Set if the agent should be launched in the current Eclipse VM.
*
* @param configuration the configuration to change.
* @param embedded <code>true</code> if the current Eclipse VM must be used for running the agent.
*/
void setEmbeddedSRE(ILaunchConfigurationWorkingCopy configuration, boolean embedded);

}
Expand Up @@ -106,6 +106,12 @@ public class LaunchConfigurationConfigurator implements ILaunchConfigurationConf
public static final String ATTR_SARL_RUNTIME_ENVIRONMENT_ARGUMENTS = SARLEclipsePlugin.PLUGIN_ID
+ ".SARL_RUNTIME_ENVIRONMENT_ARGUMENTS"; //$NON-NLS-1$

/**
* Launch configuration attribute key. The value indicates if the agents are run in the same VM as
* the Eclipse product.
*/
public static final String ATTR_EMBEDDED_SRE = SARLEclipsePlugin.PLUGIN_ID + ".EMBEDDED_SRE"; //$NON-NLS-1$

/** Identifier of the type of launch configuration dedicated to SARL
* (value <code>io.sarl.eclipse.debug.LaunchConfigType</code>).
*/
Expand All @@ -121,6 +127,8 @@ public class LaunchConfigurationConfigurator implements ILaunchConfigurationConf

private static final boolean DEFAULT_USE_PROJECT_SRE = false;

private static final boolean DEFAULT_EMBEDDED_SRE = false;

@Override
public String getLaunchConfigurationType() {
return SARL_LAUNCH_CONFIG_TYPE;
Expand Down Expand Up @@ -390,4 +398,22 @@ public String getJRELaunchingArguments(ILaunchConfiguration configuration) {
}
}

/** {@inheritDoc}
*/
@Override
public boolean isEmbeddedSRE(ILaunchConfiguration configuration) {
try {
return configuration.getAttribute(ATTR_EMBEDDED_SRE, DEFAULT_EMBEDDED_SRE);
} catch (CoreException e) {
return DEFAULT_EMBEDDED_SRE;
}
}

/** {@inheritDoc}
*/
@Override
public void setEmbeddedSRE(ILaunchConfigurationWorkingCopy configuration, boolean embedded) {
configuration.setAttribute(ATTR_EMBEDDED_SRE, embedded);
}

}
Expand Up @@ -63,6 +63,7 @@ public class Messages extends NLS {
public static String SARLArgumentsTab_2;
public static String SARLArgumentsTab_3;
public static String SARLArgumentsTab_4;
public static String SARLMainLaunchConfigurationTab_0;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Expand Down
Expand Up @@ -95,6 +95,8 @@ public class SARLMainLaunchConfigurationTab extends AbstractJavaMainTab {

private Button offlineButton;

private Button runInEclipseButton;

private Button defaultContextIdentifierButton;

private Button randomContextIdentifierButton;
Expand Down Expand Up @@ -225,6 +227,8 @@ protected void createLaunchOptionEditor(Composite parent, String text) {
this.showLogInfoButton.addSelectionListener(this.defaultListener);
this.offlineButton = createCheckButton(group, Messages.MainLaunchConfigurationTab_16);
this.offlineButton.addSelectionListener(this.defaultListener);
this.runInEclipseButton = createCheckButton(group, Messages.SARLMainLaunchConfigurationTab_0);
this.runInEclipseButton.addSelectionListener(this.defaultListener);
}

@Override
Expand Down Expand Up @@ -266,9 +270,11 @@ protected void updateLaunchOptionsFromConfig(ILaunchConfiguration config) {
final boolean showLogo = this.accessor.getShowLogoFlag(config);
final boolean showLogInfo = this.accessor.getShowLogInfoFlag(config);
final boolean offline = this.accessor.getOfflineFlag(config);
final boolean runInEclipse = this.accessor.isEmbeddedSRE(config);
this.showLogoOptionButton.setSelection(showLogo);
this.showLogInfoButton.setSelection(showLogInfo);
this.offlineButton.setSelection(offline);
this.runInEclipseButton.setSelection(runInEclipse);
}

/**
Expand Down Expand Up @@ -377,6 +383,7 @@ public void performApply(ILaunchConfigurationWorkingCopy config) {
this.showLogoOptionButton.getSelection(),
this.showLogInfoButton.getSelection(),
this.offlineButton.getSelection());
this.configurator.setEmbeddedSRE(config, this.runInEclipseButton.getSelection());
mapResources(config);
}

Expand Down
Expand Up @@ -28,3 +28,4 @@ SARLArgumentsTab_1=Arguments for the SARL runtime environment (SRE):
SARLArgumentsTab_2=Arguments for the Java virtual machine (JVM):
SARLArgumentsTab_3=Arguments for the Java virtual machine (JVM):
SARLArgumentsTab_4=Exception occurred reading configuration: {0}
SARLMainLaunchConfigurationTab_0=Run in the SARL product VM (experimental)
@@ -0,0 +1,117 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2016 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.sarl.eclipse.launching.runner;

import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.Arrays;

import org.arakhne.afc.vmutil.ClassLoaderFinder;
import org.arakhne.afc.vmutil.DynamicURLClassLoader;
import org.arakhne.afc.vmutil.FileSystem;
import org.arakhne.afc.vmutil.URISchemeType;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
import org.eclipse.jdt.launching.IVMRunner;
import org.eclipse.jdt.launching.VMRunnerConfiguration;
import org.eclipse.swt.widgets.Shell;

import io.sarl.eclipse.SARLEclipsePlugin;

/**
* Implementation of a VM runner that is running in the current Eclipse VM.
* This implementation is for debugging of SREs.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
public class EmbeddedVMRunner implements IVMRunner {

private static final String JAR_EXTENSION = ".jar"; //$NON-NLS-1$

private static final String SLASH = "/"; //$NON-NLS-1$

@Override
public void run(VMRunnerConfiguration configuration, ILaunch launch, IProgressMonitor monitor)
throws CoreException {
try {
final String[] classpath = configuration.getClassPath();
final URL[] classPathURLs = new URL[classpath.length];
Arrays.parallelSetAll(classPathURLs, (index) -> {
String path = classpath[index];
final URL url = FileSystem.convertStringToURL(path, false);
path = url.getFile();
if (!path.endsWith(JAR_EXTENSION) && !path.endsWith(SLASH)) {
path = path + SLASH;
}
try {
return new URL(URISchemeType.FILE.name(), null, path);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
});
monitor.done();
final Job myJob = new Job(launch.getLaunchConfiguration().getName()) {
@Override
public IStatus run(IProgressMonitor monitor) {
monitor.subTask(MessageFormat.format(Messages.EmbeddedVMRunner_0, launch.getLaunchConfiguration().getName()));
final DynamicURLClassLoader classLoader = DynamicURLClassLoader.newInstance(
ClassLoader.getSystemClassLoader(), classPathURLs);
try {
ClassLoaderFinder.setPreferredClassLoader(classLoader);
final String mainClass = configuration.getClassToLaunch();
final Class<?> clazz = classLoader.loadClass(mainClass);
final Method mainMethod = clazz.getDeclaredMethod("main", String[].class); //$NON-NLS-1$
mainMethod.invoke(null, (Object) configuration.getProgramArguments());
return SARLEclipsePlugin.getDefault().createOkStatus();
} catch (Throwable exception) {
return SARLEclipsePlugin.getDefault().createStatus(IStatus.ERROR, exception);
} finally {
ClassLoaderFinder.popPreferredClassLoader();
monitor.done();
}
}
};
myJob.schedule();
} catch (Exception exception) {
throw new CoreException(SARLEclipsePlugin.getDefault().createStatus(IStatus.ERROR, exception));
}
}

/**
* Convenience method to return the active workbench window shell.
*
* @return active workbench window shell
*/
protected static Shell getShell() {
return JDIDebugUIPlugin.getActiveWorkbenchShell();
}

}
Expand Up @@ -42,6 +42,7 @@ public class Messages extends NLS {
public static String SARLLaunchConfigurationDelegate_6;
public static String SARLLaunchConfigurationDelegate_7;
public static String SARLLaunchConfigurationDelegate_8;
public static String EmbeddedVMRunner_0;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Expand Down
Expand Up @@ -661,6 +661,14 @@ private static String join(String... values) {
return buffer.toString();
}

@Override
public IVMRunner getVMRunner(ILaunchConfiguration configuration, String mode) throws CoreException {
if (this.accessor.isEmbeddedSRE(configuration)) {
return new EmbeddedVMRunner();
}
return super.getVMRunner(configuration, mode);
}

/** Definition of the launching process splitted in separated steps for
* making easier the cancellation.
*
Expand Down
Expand Up @@ -7,3 +7,4 @@ SARLLaunchConfigurationDelegate_5=Configuration of the stop-in-main configuratio
SARLLaunchConfigurationDelegate_6=Launching {0}...
SARLLaunchConfigurationDelegate_7=Post validation of the configuration
SARLLaunchConfigurationDelegate_8=<unspecified sre>
EmbeddedVMRunner_0=Running {0}...
8 changes: 8 additions & 0 deletions sre/io.janusproject/io.janusproject.feature/feature.xml
Expand Up @@ -236,6 +236,7 @@
<import plugin="org.eclipse.core.runtime" version="3.12.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.ui.workbench" version="3.108.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.core.resources" version="3.11.0" match="greaterOrEqual"/>
<import plugin="org.arakhne.afc.core.util" version="14.0.0" match="greaterOrEqual"/>
</requires>

<plugin
Expand Down Expand Up @@ -288,4 +289,11 @@
version="18.0.0"
unpack="false"/>

<plugin
id="org.arakhne.afc.core.util"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

</feature>
Expand Up @@ -8,6 +8,7 @@ Require-Bundle: io.sarl.core;bundle-version="0.4.0",
io.sarl.util;bundle-version="0.4.0",
io.sarl.eclipse;bundle-version="0.4.0",
org.arakhne.afc.core.vmutils;bundle-version="14.0.0",
org.arakhne.afc.core.util;bundle-version="14.0.0",
com.hazelcast;bundle-version="3.7.0",
com.google.gson;bundle-version="2.4.0",
org.zeromq.jeromq;bundle-version="0.3.5",
Expand Down

0 comments on commit 3b9cfdb

Please sign in to comment.