Skip to content

Commit

Permalink
[eclipse] Add SARL application launch configuration.
Browse files Browse the repository at this point in the history
see #745

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Jan 29, 2018
1 parent 73a5684 commit cb52066
Show file tree
Hide file tree
Showing 4 changed files with 336 additions and 0 deletions.
16 changes: 16 additions & 0 deletions main/coreplugins/io.sarl.eclipse/plugin.xml
Expand Up @@ -184,6 +184,13 @@
public="true"
sourcePathComputerId="org.eclipse.jdt.launching.sourceLookup.javaSourcePathComputer">
</launchConfigurationType>
<launchConfigurationType
delegate="io.sarl.eclipse.SARLEclipseExecutableExtensionFactory:io.sarl.eclipse.launching.runner.SARLApplicationLaunchConfigurationDelegate"
delegateDescription="%launch.application.description"
delegateName="%launch.application"
id="io.sarl.eclipse.debug.ApplicationLaunchConfigType"
modes="debug, run"
name="%launch.application"
public="true"
sourcePathComputerId="org.eclipse.jdt.launching.sourceLookup.javaSourcePathComputer">
</launchConfigurationType>
Expand All @@ -194,6 +201,10 @@
configTypeID="io.sarl.eclipse.debug.AgentLaunchConfigType"
icon="icons/sarl_16.png"
id="io.sarl.eclipse.debug.AgentLaunchConfigTypeImage" />
<launchConfigurationTypeImage
configTypeID="io.sarl.eclipse.debug.ApplicationLaunchConfigType"
icon="icons/sarl_application_16.png"
id="io.sarl.eclipse.debug.ApplicationLaunchConfigTypeImage" />
</extension>

<extension point="org.eclipse.debug.ui.launchConfigurationTabGroups">
Expand All @@ -202,6 +213,11 @@
description="%launch.agent.description"
id="io.sarl.eclipse.debug.AgentLaunchConfigTabGroup"
type="io.sarl.eclipse.debug.AgentLaunchConfigType" />
<launchConfigurationTabGroup
class="io.sarl.eclipse.SARLEclipseExecutableExtensionFactory:io.sarl.eclipse.launching.dialog.SARLApplicationLaunchConfigurationTabGroup"
description="%launch.application.description"
id="io.sarl.eclipse.debug.ApplicationLaunchConfigTabGroup"
type="io.sarl.eclipse.debug.ApplicationLaunchConfigType" />
</extension>

<!-- Adapters for the application launchers -->
Expand Down
@@ -0,0 +1,56 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2018 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.dialog;

import org.eclipse.debug.ui.CommonTab;
import org.eclipse.debug.ui.EnvironmentTab;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.debug.ui.sourcelookup.SourceLookupTab;
import org.eclipse.jdt.debug.ui.launchConfigurations.JavaArgumentsTab;

/**
* Tab group object for configuring the run of a Java application embedding SARL.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.7
*/
public class SARLApplicationLaunchConfigurationTabGroup extends AbstractSARLLaunchConfigurationTabGroup {

@Override
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
final ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
new SARLApplicationMainLaunchConfigurationTab(),
new JavaArgumentsTab(),
new SARLRuntimeEnvironmentTab(false),
getClasspathTab(dialog),
new SourceLookupTab(),
new EnvironmentTab(),
new CommonTab(),
};
setTabs(tabs);
}

}
@@ -0,0 +1,187 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2018 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.dialog;

import java.lang.ref.SoftReference;

import javax.inject.Inject;

import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.internal.ui.SWTFactory;
import org.eclipse.jdt.debug.ui.launchConfigurations.JavaMainTab;
import org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;

import io.sarl.eclipse.SARLEclipseConfig;
import io.sarl.eclipse.SARLEclipsePlugin;
import io.sarl.eclipse.launching.config.ILaunchConfigurationAccessor;
import io.sarl.eclipse.launching.config.ILaunchConfigurationConfigurator;

/**
* The main launch configuration tab for SARL applications.
*
* <p>This configuration tab enables to enter the name of the main class to launch,
* the launching parameters.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.7
*/
public class SARLApplicationMainLaunchConfigurationTab extends JavaMainTab {

private volatile SoftReference<Image> image;

private Button runInEclipseButton;

private Button enableAssertionsInDebugModeButton;

private Button enableAssertionsInRunModeButton;

private final WidgetListener defaultListener = new WidgetListener();

@Inject
private ILaunchConfigurationConfigurator configurator;

@Inject
private ILaunchConfigurationAccessor accessor;

/** Construct a main configuration tab for SARL application.
*/
public SARLApplicationMainLaunchConfigurationTab() {
//
}

@Override
public Image getImage() {
Image img = (this.image == null) ? null : this.image.get();
if (img == null) {
img = SARLEclipsePlugin.getDefault().getImage(SARLEclipseConfig.SARL_APPLICATION_IMAGE);
this.image = new SoftReference<>(img);
}
return img;
}

@Override
public String getId() {
return "io.sarl.eclipse.debug.ui.sarlApplicationMainTab"; //$NON-NLS-1$
}

@Override
public String getName() {
return Messages.MainLaunchConfigurationTab_7;
}

@Override
public void createControl(Composite parent) {
super.createControl(parent);
final Composite comp = SWTFactory.createComposite(parent, parent.getFont(), 1, 1, GridData.FILL_BOTH);
((GridLayout) comp.getLayout()).verticalSpacing = 0;
createProjectEditor(comp);
createVerticalSpacer(comp, 1);
createMainTypeEditor(comp, LauncherMessages.JavaMainTab_Main_cla_ss__4);
createVerticalSpacer(comp, 1);
createLaunchOptionEditor(comp, Messages.MainLaunchConfigurationTab_10);
setControl(comp);
}

/**
* Creates the widgets for configuring the launch options.
*
* @param parent the parent composite.
* @param text the label of the group.
*/
protected void createLaunchOptionEditor(Composite parent, String text) {
final Group group = SWTFactory.createGroup(parent, text, 1, 1, GridData.FILL_HORIZONTAL);
this.enableAssertionsInRunModeButton = createCheckButton(group, Messages.SARLMainLaunchConfigurationTab_2);
this.enableAssertionsInRunModeButton.addSelectionListener(this.defaultListener);
this.enableAssertionsInDebugModeButton = createCheckButton(group, Messages.SARLMainLaunchConfigurationTab_1);
this.enableAssertionsInDebugModeButton.addSelectionListener(this.defaultListener);
this.runInEclipseButton = createCheckButton(group, Messages.SARLMainLaunchConfigurationTab_0);
this.runInEclipseButton.addSelectionListener(this.defaultListener);
}

/**
* Loads the launch options from the launch configuration's preference store.
*
* @param config the config to load the agent name from
*/
protected void updateLaunchOptionsFromConfig(ILaunchConfiguration config) {
final boolean runInEclipse = this.accessor.isEmbeddedSRE(config);
final boolean enableAssertionsRun = this.accessor.isAssertionEnabledInRunMode(config);
final boolean enableAssertionsDebug = this.accessor.isAssertionEnabledInDebugMode(config);
this.enableAssertionsInRunModeButton.setSelection(enableAssertionsRun);
this.enableAssertionsInDebugModeButton.setSelection(enableAssertionsDebug);
this.runInEclipseButton.setSelection(runInEclipse);
}

@Override
public void initializeFrom(ILaunchConfiguration config) {
super.initializeFrom(config);
updateLaunchOptionsFromConfig(config);
}

@Override
public void performApply(ILaunchConfigurationWorkingCopy config) {
this.configurator.setAssertionEnabledInRunMode(config, this.enableAssertionsInRunModeButton.getSelection());
this.configurator.setAssertionEnabledInDebugMode(config, this.enableAssertionsInDebugModeButton.getSelection());
this.configurator.setEmbeddedSRE(config, this.runInEclipseButton.getSelection());
super.performApply(config);
}

/** Listener of events in internal components for refreshing the tab.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.7
*/
private class WidgetListener implements SelectionListener {

WidgetListener() {
//
}

@Override
public void widgetDefaultSelected(SelectionEvent event) {
//
}

@SuppressWarnings("synthetic-access")
@Override
public void widgetSelected(SelectionEvent event) {
updateLaunchConfigurationDialog();
}

}

}
@@ -0,0 +1,77 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2018 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 org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;

import io.sarl.eclipse.runtime.ISREInstall;

/**
* Implementation of an eclipse LauncConfigurationDelegate to launch SARL application.
*
* <p>This delegate is in charge of running a SARL application with the specific
* SRE.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.7
*/
public class SARLApplicationLaunchConfigurationDelegate extends AbstractSARLLaunchConfigurationDelegate {

@Override
protected ILaunchProcess createLaunchingProcess(ILaunchConfiguration configuration, String mode, ILaunch launch) {
return new LaunchProcess(configuration, mode, launch);
}

@Override
protected String getProgramArguments(ILaunchConfiguration configuration, ISREInstall sre,
String standardProgramArguments) throws CoreException {
return standardProgramArguments;
}

/** Definition of the launching process, split in separated steps for
* making easier the cancellation.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @sincec 0.7
*/
private class LaunchProcess extends AbstractLaunchProcess {

/** Constructor.
* @param configuration the launch configuration.
* @param mode the launching mode.
* @param launch the launching
*/
LaunchProcess(ILaunchConfiguration configuration, String mode, ILaunch launch) {
super(configuration, mode, launch);
}

}

}

0 comments on commit cb52066

Please sign in to comment.