Skip to content

Commit

Permalink
[eclipse] Create extension point for launch configuration panels.
Browse files Browse the repository at this point in the history
see #1027

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Nov 4, 2020
1 parent 50a92d8 commit ca8d8d2
Show file tree
Hide file tree
Showing 20 changed files with 306 additions and 105 deletions.
Expand Up @@ -34,6 +34,7 @@ keyword.sarl.runtime = Runtime
classpathContainerPage.name = SARL Libraries
sreInstallations = SRE Installation
sreInstallPages = SRE Installation Page
sarlLaunchConfigurationPanels = Launch Configuration Panel for SARL
projectSREProvider = Project SRE Provider Factory
product.name = SARL IDE
wizard.name.newSarlProject = SARL Project
Expand Down
1 change: 1 addition & 0 deletions main/coreplugins/io.sarl.eclipse/plugin.xml
Expand Up @@ -487,6 +487,7 @@
<extension-point id="sreInstallations" name="%sreInstallations" schema="schema/sreInstallations.exsd"/>
<extension-point id="sreInstallPages" name="%sreInstallPages" schema="schema/sreInstallPages.exsd"/>
<extension-point id="projectSREProviderFactory" name="%projectSREProviderFactory" schema="schema/projectSREProviderFactory.exsd"/>
<extension-point id="sarlLaunchConfigurationPanels" name="%sarlLaunchConfigurationPanels" schema="schema/sarlLaunchConfigurationPanels.exsd"/>

<!-- Project configurators -->
<extension
Expand Down
Expand Up @@ -96,7 +96,7 @@
<meta.section type="copyright"/>
</appInfo>
<documentation>
Copyright 2014-2015 the original authors and authors.
Copyright 2014-2020 the original authors and authors.

Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
you may not use this file except in compliance with the License.
Expand Down
@@ -0,0 +1,115 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="io.sarl.eclipse" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="io.sarl.eclipse" id="sarlLaunchConfigurationPanels" name="%sarlLaunchConfigurationPanels"/>
</appInfo>
<documentation>
Provide a page for the launch configuration wizard.
</documentation>
</annotation>

<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<choice minOccurs="1" maxOccurs="unbounded">
<element ref="panel"/>
</choice>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>

</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>

<element name="panel">
<complexType>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
Fully qualified name of the launch configuration panel factory.
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":io.sarl.eclipse.launching.dialog.ISarlLaunchConfigurationPanelFactory"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>

<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
0.12
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
Following is an example definition of an execution environment and analyzer.
&lt;p&gt;
&lt;pre&gt;
&lt;extension point=&quot;io.sarl.eclipse.sarlLaunchConfigurationPanels&quot;&gt;
&lt;sreInstallPage
id=&quot;120302354&quot;
class=&quot;com.example.MyLaunchConfigurationPage&quot;/&gt;
&lt;/extension&gt;
&lt;/pre&gt;
&lt;/p&gt;
</documentation>
</annotation>



<annotation>
<appInfo>
<meta.section type="copyright"/>
</appInfo>
<documentation>
Copyright 2014-2020 the original authors and authors.

Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
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 &quot;AS IS&quot; 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.
</documentation>
</annotation>

</schema>
4 changes: 2 additions & 2 deletions main/coreplugins/io.sarl.eclipse/schema/sreInstallPages.exsd
Expand Up @@ -6,7 +6,7 @@
<meta.schema plugin="io.sarl.eclipse" id="sreInstallPages" name="%sreInstallPages"/>
</appInfo>
<documentation>
Provide the a page for the configuration wizard of SREs.
Provide a page for the configuration wizard of SREs.
</documentation>
</annotation>

Expand Down Expand Up @@ -113,7 +113,7 @@
<meta.section type="copyright"/>
</appInfo>
<documentation>
Copyright 2014-2015 the original authors and authors.
Copyright 2014-2020 the original authors and authors.

Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
you may not use this file except in compliance with the License.
Expand Down
Expand Up @@ -154,6 +154,12 @@ public final class SARLEclipseConfig {
*/
public static final String SUBMIT_ISSUE_WIZARD_DIALOG_IMAGE = "icons/sarl_submit_issue_dialog.png"; //$NON-NLS-1$

/**
* Name of the extension points for the factory of launch configuration panels.
* (value <code>"sarlLaunchConfigurationPanels"</code>).
*/
public static final String EXTENSION_POINT_LAUNCH_CONFIGURATION_PANEL_FACTORY = "sarlLaunchConfigurationPanels"; //$NON-NLS-1$

private SARLEclipseConfig() {
//
}
Expand Down
Expand Up @@ -86,13 +86,6 @@ public interface ILaunchConfigurationAccessor {
*/
boolean getShowLogInfoFlag(ILaunchConfiguration configuration);

/** Replies if the SRE should be run offline.
*
* @param configuration the configuration.
* @return <code>true</code> if the SRE should be run offline.
*/
boolean getOfflineFlag(ILaunchConfiguration configuration);

/** Replies the name of the project attached to the configuration.
*
* @param configuration the configuration.
Expand Down
Expand Up @@ -156,10 +156,8 @@ void detachResources(ILaunchConfigurationWorkingCopy configuration, IResource...
*
* @param configuration the configuration to change.
* @param showLogInfo indicates if informations are logged or only errors. If null, the default is used.
* @param offline indicates if the SRE is supposed to be run offline. If null, the default is used.
*/
void setLaunchingFlags(ILaunchConfigurationWorkingCopy configuration, Boolean showLogInfo,
Boolean offline);
void setLaunchingFlags(ILaunchConfigurationWorkingCopy configuration, Boolean showLogInfo);

/** Change the name of the project associated to the launch configuration.
*
Expand Down
Expand Up @@ -70,12 +70,6 @@ public class LaunchConfigurationConfigurator implements ILaunchConfigurationConf
*/
public static final String ATTR_SHOW_LOG_INFO = SARLEclipsePlugin.PLUGIN_ID + ".SHOW_LOG_INFO"; //$NON-NLS-1$

/**
* Launch configuration attribute key. The value indicates if the SRE should be
* launched offline.
*/
public static final String ATTR_SRE_OFFLINE = SARLEclipsePlugin.PLUGIN_ID + ".SRE_OFFLINE"; //$NON-NLS-1$

/**
* Launch configuration attribute key. The value is the identifier of the SRE;
*/
Expand Down Expand Up @@ -130,8 +124,6 @@ public class LaunchConfigurationConfigurator implements ILaunchConfigurationConf

private static final boolean DEFAULT_SHOW_LOG_INFO = true;

private static final boolean DEFAULT_OFFLINE = true;

private static final boolean DEFAULT_USE_SYSTEM_SRE = true;

private static final boolean DEFAULT_USE_PROJECT_SRE = false;
Expand Down Expand Up @@ -216,7 +208,7 @@ protected ILaunchConfigurationWorkingCopy initLaunchConfiguration(String configu
final ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, launchManager.generateLaunchConfigurationName(id));
setProjectName(wc, projectName);
setDefaultContextIdentifier(wc, null);
setLaunchingFlags(wc, DEFAULT_SHOW_LOG_INFO, DEFAULT_OFFLINE);
setLaunchingFlags(wc, DEFAULT_SHOW_LOG_INFO);
setRuntimeConfiguration(wc, SARLRuntime.getDefaultSREInstall(), DEFAULT_USE_SYSTEM_SRE, DEFAULT_USE_PROJECT_SRE, resetJavaMainClass);
JavaMigrationDelegate.updateResourceMapping(wc);
return wc;
Expand Down Expand Up @@ -285,12 +277,9 @@ public void setRuntimeConfiguration(ILaunchConfigurationWorkingCopy configuratio
}

@Override
public void setLaunchingFlags(ILaunchConfigurationWorkingCopy configuration, Boolean showLogInfo,
Boolean offline) {
public void setLaunchingFlags(ILaunchConfigurationWorkingCopy configuration, Boolean showLogInfo) {
configuration.setAttribute(ATTR_SHOW_LOG_INFO,
showLogInfo == null ? DEFAULT_SHOW_LOG_INFO : showLogInfo.booleanValue());
configuration.setAttribute(ATTR_SRE_OFFLINE,
offline == null ? DEFAULT_OFFLINE : offline.booleanValue());
}

@Override
Expand Down Expand Up @@ -387,15 +376,6 @@ public boolean getShowLogInfoFlag(ILaunchConfiguration configuration) {
}
}

@Override
public boolean getOfflineFlag(ILaunchConfiguration configuration) {
try {
return configuration.getAttribute(ATTR_SRE_OFFLINE, DEFAULT_OFFLINE);
} catch (CoreException e) {
return DEFAULT_OFFLINE;
}
}

@Override
public String getProjectName(ILaunchConfiguration configuration) {
try {
Expand Down
Expand Up @@ -21,18 +21,32 @@

package io.sarl.eclipse.launching.dialog;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;

import com.google.inject.Injector;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
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.JavaClasspathTab;
import org.eclipse.jdt.debug.ui.launchConfigurations.JavaDependenciesTab;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.xtext.xbase.lib.Functions.Function1;

import io.sarl.eclipse.SARLEclipseConfig;
import io.sarl.eclipse.SARLEclipsePlugin;

/**
* Abstract tab group for run configurations of a SARL element.
Expand All @@ -56,6 +70,12 @@ public AbstractSARLLaunchConfigurationTabGroup() {
//
}

/** {@inheritDoc}
*
* <p>This function is overridden in order to inject the members of the tabs.
*
* @param tabs the tabs to add into the panel.
*/
@Override
protected void setTabs(ILaunchConfigurationTab... tabs) {
//Override the function for automatic injection within the tabs.
Expand All @@ -68,6 +88,83 @@ protected void setTabs(ILaunchConfigurationTab... tabs) {
super.setTabs(tabs);
}

/** Build the list of the tabs to be inserted into the launch configuration panel.
*
* <p>This function adds the panels that are provided by the given {@code builder}, and
* the panels that are provided by the plugin contributions.
*
* <p>The {@code builder} is invoked with an empty list of panels.
* The panels that are given by extension points are added after.
* If the boolean value replied by {@code builder} is evaluated to {@code true}, the following standard panels
* are automatically added to the launch configuration after the ones provided by the extension points:<ul>
* <li>the class-path tab,</li>
* <li>the source look-up tab,</li>
* <li>the environment variable tab,</li>
* <li>the common tab.</li>
* </ul>
*
* @param dialog is the reference to the launch configuration dialog box.
* @param mode the running mode.
* @param builder the builder that is able to fill out the list of panels. The parameter of the procedure
* is the list to fill with the panels.
* @return the list of tabs to be added into the panel, before they are injected.
* @see #setTabs(ILaunchConfigurationTab...)
*/
protected ILaunchConfigurationTab[] buildTabList(
ILaunchConfigurationDialog dialog,
String mode,
Function1<List<ILaunchConfigurationTab>, Boolean> builder) {
assert builder != null;
final List<ILaunchConfigurationTab> list = new ArrayList<>();

final Boolean addStandardPanels = builder.apply(list);

final List<ISarlLaunchConfigurationPanelFactory> factories = getFactoriesFromExtension();
for (final ISarlLaunchConfigurationPanelFactory factory : factories) {
if (factory.canCreatePanel(dialog, mode, list)) {
final ILaunchConfigurationTab panel = factory.newLaunchConfigurationPanel();
if (panel != null) {
list.add(panel);
}
}
}

if (addStandardPanels == null || addStandardPanels.booleanValue()) {
list.add(getClasspathTab(dialog));
list.add(new SourceLookupTab());
list.add(new EnvironmentTab());
list.add(new CommonTab());
}

final ILaunchConfigurationTab[] array = new ILaunchConfigurationTab[list.size()];
list.toArray(array);
return array;
}

private static List<ISarlLaunchConfigurationPanelFactory> getFactoriesFromExtension() {
final IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(
SARLEclipsePlugin.PLUGIN_ID,
SARLEclipseConfig.EXTENSION_POINT_LAUNCH_CONFIGURATION_PANEL_FACTORY);
if (extensionPoint != null) {
final List<ISarlLaunchConfigurationPanelFactory> factories = new ArrayList<>();
for (final IConfigurationElement element : extensionPoint.getConfigurationElements()) {
try {
final Object obj = element.createExecutableExtension("class"); //$NON-NLS-1$
if (obj instanceof ISarlLaunchConfigurationPanelFactory) {
factories.add((ISarlLaunchConfigurationPanelFactory) obj);
} else {
SARLEclipsePlugin.getDefault().logErrorMessage(
"Cannot instance extension point: " + element.getName()); //$NON-NLS-1$
}
} catch (CoreException e) {
SARLEclipsePlugin.getDefault().log(e);
}
}
return factories;
}
return Collections.emptyList();
}

/** Replies the preferred tab for configuring the classpath.
* The tab may be the standard {@link JavaClasspathTab} or its specialization
* {@link JavaDependenciesTab}.
Expand Down

0 comments on commit ca8d8d2

Please sign in to comment.