Skip to content

Commit

Permalink
[eclipse] Automatic addition of -ea in SARL launch config.
Browse files Browse the repository at this point in the history
close #529

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Oct 28, 2016
1 parent 10da3d0 commit f6e035c
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 6 deletions.
Expand Up @@ -140,4 +140,24 @@ public interface ILaunchConfigurationAccessor {
*/
boolean isEmbeddedSRE(ILaunchConfiguration configuration);

/** Replies if the assertions are automatically enabled in debug mode.
*
* <p>When assertions are enabled, the <code>-ea</code> command line option will be given to the virtual machine.
*
* @param configuration the configuration.
* @return <code>true</code> if the assertions are enabled.
* @since 0.5
*/
boolean isAssertionEnabledInDebugMode(ILaunchConfiguration configuration);

/** Replies if the assertions are automatically enabled in run mode.
*
* <p>When assertions are enabled, the <code>-ea</code> command line option will be given to the virtual machine.
*
* @param configuration the configuration.
* @return <code>true</code> if the assertions are enabled.
* @since 0.5
*/
boolean isAssertionEnabledInRunMode(ILaunchConfiguration configuration);

}
Expand Up @@ -150,4 +150,24 @@ void setLaunchingFlags(ILaunchConfigurationWorkingCopy configuration, Boolean sh
*/
void setEmbeddedSRE(ILaunchConfigurationWorkingCopy configuration, boolean embedded);

/** Set if the assertions are automatically enabled in debug mode.
*
* <p>When assertions are enabled, the <code>-ea</code> command line option will be given to the virtual machine.
*
* @param configuration the configuration.
* @param enable <code>true</code> if the assertions are enabled.
* @since 0.5
*/
void setAssertionEnabledInDebugMode(ILaunchConfigurationWorkingCopy configuration, boolean enable);

/** Set if the assertions are automatically enabled in run mode.
*
* <p>When assertions are enabled, the <code>-ea</code> command line option will be given to the virtual machine.
*
* @param configuration the configuration.
* @param enable <code>true</code> if the assertions are enabled.
* @since 0.5
*/
void setAssertionEnabledInRunMode(ILaunchConfigurationWorkingCopy configuration, boolean enable);

}
Expand Up @@ -112,6 +112,18 @@ public class LaunchConfigurationConfigurator implements ILaunchConfigurationConf
*/
public static final String ATTR_EMBEDDED_SRE = SARLEclipsePlugin.PLUGIN_ID + ".EMBEDDED_SRE"; //$NON-NLS-1$

/**
* Launch configuration attribute key. The value indicates if the assertions are enabled in the virtual machine
* when it is launched in debug mode.
*/
public static final String ATTR_ENABLE_ASSERTIONS_IN_DEBUG_MODE = SARLEclipsePlugin.PLUGIN_ID + ".ENABLE_ASSERTIONS_DEBUG"; //$NON-NLS-1$

/**
* Launch configuration attribute key. The value indicates if the assertions are enabled in the virtual machine
* when it is launched in run mode.
*/
public static final String ATTR_ENABLE_ASSERTIONS_IN_RUN_MODE = SARLEclipsePlugin.PLUGIN_ID + ".ENABLE_ASSERTIONS_RUN"; //$NON-NLS-1$

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

private static final boolean DEFAULT_EMBEDDED_SRE = false;

private static final boolean DEFAULT_ENABLE_ASSERTIONS_IN_DEBUG_MODE = true;

private static final boolean DEFAULT_ENABLE_ASSERTIONS_IN_RUN_MODE = false;

@Override
public String getLaunchConfigurationType() {
return SARL_LAUNCH_CONFIG_TYPE;
Expand Down Expand Up @@ -398,8 +414,6 @@ public String getJRELaunchingArguments(ILaunchConfiguration configuration) {
}
}

/** {@inheritDoc}
*/
@Override
public boolean isEmbeddedSRE(ILaunchConfiguration configuration) {
try {
Expand All @@ -409,11 +423,37 @@ public boolean isEmbeddedSRE(ILaunchConfiguration configuration) {
}
}

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

@Override
public boolean isAssertionEnabledInDebugMode(ILaunchConfiguration configuration) {
try {
return configuration.getAttribute(ATTR_ENABLE_ASSERTIONS_IN_DEBUG_MODE, DEFAULT_ENABLE_ASSERTIONS_IN_DEBUG_MODE);
} catch (CoreException e) {
return DEFAULT_ENABLE_ASSERTIONS_IN_DEBUG_MODE;
}
}

@Override
public void setAssertionEnabledInDebugMode(ILaunchConfigurationWorkingCopy configuration, boolean enable) {
configuration.setAttribute(ATTR_ENABLE_ASSERTIONS_IN_DEBUG_MODE, enable);
}

@Override
public boolean isAssertionEnabledInRunMode(ILaunchConfiguration configuration) {
try {
return configuration.getAttribute(ATTR_ENABLE_ASSERTIONS_IN_RUN_MODE, DEFAULT_ENABLE_ASSERTIONS_IN_RUN_MODE);
} catch (CoreException e) {
return DEFAULT_ENABLE_ASSERTIONS_IN_RUN_MODE;
}
}

@Override
public void setAssertionEnabledInRunMode(ILaunchConfigurationWorkingCopy configuration, boolean enable) {
configuration.setAttribute(ATTR_ENABLE_ASSERTIONS_IN_RUN_MODE, enable);
}

}
Expand Up @@ -64,6 +64,8 @@ public class Messages extends NLS {
public static String SARLArgumentsTab_3;
public static String SARLArgumentsTab_4;
public static String SARLMainLaunchConfigurationTab_0;
public static String SARLMainLaunchConfigurationTab_1;
public static String SARLMainLaunchConfigurationTab_2;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Expand Down
Expand Up @@ -97,6 +97,10 @@ public class SARLMainLaunchConfigurationTab extends AbstractJavaMainTab {

private Button runInEclipseButton;

private Button enableAssertionsInDebugModeButton;

private Button enableAssertionsInRunModeButton;

private Button defaultContextIdentifierButton;

private Button randomContextIdentifierButton;
Expand Down Expand Up @@ -227,6 +231,10 @@ 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.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);
}
Expand Down Expand Up @@ -271,9 +279,13 @@ protected void updateLaunchOptionsFromConfig(ILaunchConfiguration config) {
final boolean showLogInfo = this.accessor.getShowLogInfoFlag(config);
final boolean offline = this.accessor.getOfflineFlag(config);
final boolean runInEclipse = this.accessor.isEmbeddedSRE(config);
final boolean enableAssertionsRun = this.accessor.isAssertionEnabledInRunMode(config);
final boolean enableAssertionsDebug = this.accessor.isAssertionEnabledInDebugMode(config);
this.showLogoOptionButton.setSelection(showLogo);
this.showLogInfoButton.setSelection(showLogInfo);
this.offlineButton.setSelection(offline);
this.enableAssertionsInRunModeButton.setSelection(enableAssertionsRun);
this.enableAssertionsInDebugModeButton.setSelection(enableAssertionsDebug);
this.runInEclipseButton.setSelection(runInEclipse);
}

Expand Down Expand Up @@ -383,6 +395,8 @@ public void performApply(ILaunchConfigurationWorkingCopy config) {
this.showLogoOptionButton.getSelection(),
this.showLogInfoButton.getSelection(),
this.offlineButton.getSelection());
this.configurator.setAssertionEnabledInRunMode(config, this.enableAssertionsInRunModeButton.getSelection());
this.configurator.setAssertionEnabledInDebugMode(config, this.enableAssertionsInDebugModeButton.getSelection());
this.configurator.setEmbeddedSRE(config, this.runInEclipseButton.getSelection());
mapResources(config);
}
Expand Down
Expand Up @@ -29,3 +29,5 @@ 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)
SARLMainLaunchConfigurationTab_1=Enable assertions in debug mode
SARLMainLaunchConfigurationTab_2=Enable assertions in run mode
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;

Expand All @@ -45,6 +46,7 @@
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.internal.launching.JRERuntimeClasspathEntryResolver;
import org.eclipse.jdt.internal.launching.LaunchingMessages;
Expand Down Expand Up @@ -83,6 +85,8 @@
*/
public class SARLLaunchConfigurationDelegate extends AbstractJavaLaunchConfigurationDelegate {

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

private SoftReference<IRuntimeClasspathEntry[]> unresolvedClasspathEntries;

private SoftReference<String[]> classpathEntries;
Expand Down Expand Up @@ -742,14 +746,27 @@ private void readConfigurationParameters(IProgressMonitor monitor) throws CoreEx
this.envp = getEnvironment(this.configuration);
}

@SuppressWarnings("synthetic-access")
private void readLaunchingArguments(IProgressMonitor monitor) throws CoreException {
monitor.subTask(
Messages.SARLLaunchConfigurationDelegate_2);

// Program & VM arguments
final String pgmArgs = getProgramArguments(this.configuration);
final String vmArgs = getVMArguments(this.configuration);
this.execArgs = new ExecutionArguments(vmArgs, pgmArgs);
final StringBuilder vmArgs = new StringBuilder(getVMArguments(this.configuration));

// Add -ea option if in debug mode
if ((Objects.equals(this.mode, ILaunchManager.RUN_MODE)
&& SARLLaunchConfigurationDelegate.this.accessor.isAssertionEnabledInRunMode(this.configuration))
|| (Objects.equals(this.mode, ILaunchManager.DEBUG_MODE)
&& SARLLaunchConfigurationDelegate.this.accessor.isAssertionEnabledInDebugMode(this.configuration))) {
if (vmArgs.length() > 0) {
vmArgs.append(" "); //$NON-NLS-1$
}
vmArgs.append(OPTION_ENABLEASSERTIONS);
}

this.execArgs = new ExecutionArguments(vmArgs.toString(), pgmArgs);

// VM-specific attributes
this.vmAttributesMap = getVMSpecificAttributesMap(this.configuration);
Expand Down

0 comments on commit f6e035c

Please sign in to comment.