Skip to content

Commit 86c45d6

Browse files
committed
Allow configure initial values for new JUnit launches with preferences
Currently PDE creates a new JUnit launch with quite broad default settings that often lead to large launches and users has to adjust them after the first run to their own needs. This now adds new preference options to control these values chosen for new launch configurations and defaults to the smallest possible configuration that is only the test-plugin and include all requirements automatically.
1 parent 77439fd commit 86c45d6

7 files changed

Lines changed: 114 additions & 10 deletions

File tree

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEPreferencesManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public void setValueOrRemove(String key, int value) {
350350
* @see #setToDefault(String)
351351
*/
352352
public void setValueOrRemove(String key, String value) {
353-
if (value.equals(getDefaultString(key))) {
353+
if (value == null || value.equals(getDefaultString(key))) {
354354
fInstanceScopePrefs.remove(key);
355355
} else {
356356
fInstanceScopePrefs.put(key, value);

ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/ILaunchingPreferenceConstants.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@
2020
*/
2121
public interface ILaunchingPreferenceConstants {
2222

23+
public static final String VALUE_JUNIT_LAUNCH_WITH_TESTPLUGIN = "testPluginOnly"; //$NON-NLS-1$
24+
public static final String VALUE_JUNIT_LAUNCH_WITH_ALL = "allWorkspacePlugins"; //$NON-NLS-1$
25+
2326
// Main preference page
2427
public static final String PROP_AUTO_MANAGE = "Preferences.MainPage.automanageDependencies"; //$NON-NLS-1$
2528
public static final String PROP_RUNTIME_WORKSPACE_LOCATION = "Preferences.MainPage.runtimeWorkspaceLocation"; //$NON-NLS-1$
2629
public static final String PROP_RUNTIME_WORKSPACE_LOCATION_IS_CONTAINER = "Preferences.MainPage.runtimeWorkspaceLocationIsContainer"; //$NON-NLS-1$
2730
public static final String PROP_JUNIT_WORKSPACE_LOCATION = "Preferences.MainPage.junitWorkspaceLocation"; //$NON-NLS-1$
31+
public static final String PROP_JUNIT_LAUNCH_WITH = "Preferences.MainPage.junitLaunchWith"; //$NON-NLS-1$
32+
public static final String PROP_JUNIT_AUTO_INCLUDE = "Preferences.MainPage.junitAutoInclude"; //$NON-NLS-1$
33+
public static final String PROP_JUNIT_INCLUDE_OPTIONAL = "Preferences.MainPage.junitIncludeOptional"; //$NON-NLS-1$
34+
public static final String PROP_JUNIT_ADD_NEW_WORKSPACE_PLUGINS = "Preferences.MainPage.junitAddNewWorkspacePlugins"; //$NON-NLS-1$
35+
public static final String PROP_JUNIT_VALIDATE_LAUNCH = "Preferences.MainPage.junitValidateLaunch"; //$NON-NLS-1$
2836
public static final String PROP_JUNIT_WORKSPACE_LOCATION_IS_CONTAINER = "Preferences.MainPage.junitWorkspaceLocationIsContainer"; //$NON-NLS-1$
2937

3038
// OSGi Frameworks

ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/PreferenceInitializer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public void initializeDefaultPreferences() {
3030
prefs.putBoolean(ILaunchingPreferenceConstants.PROP_RUNTIME_WORKSPACE_LOCATION_IS_CONTAINER, true);
3131
prefs.put(ILaunchingPreferenceConstants.PROP_JUNIT_WORKSPACE_LOCATION, "${workspace_loc}/../junit-workspace"); //$NON-NLS-1$
3232
prefs.putBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_WORKSPACE_LOCATION_IS_CONTAINER, false);
33+
prefs.put(ILaunchingPreferenceConstants.PROP_JUNIT_LAUNCH_WITH, ILaunchingPreferenceConstants.VALUE_JUNIT_LAUNCH_WITH_TESTPLUGIN);
34+
prefs.putBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_AUTO_INCLUDE, true);
35+
prefs.putBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_INCLUDE_OPTIONAL, true);
36+
prefs.putBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_ADD_NEW_WORKSPACE_PLUGINS, false);
37+
prefs.putBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_VALIDATE_LAUNCH, true);
3338

3439
// copy over instance scope prefs from UI plugin
3540
IEclipsePreferences oldInstancePrefs = InstanceScope.INSTANCE.getNode(IPDEConstants.UI_PLUGIN_ID);

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ public class PDEUIMessages extends NLS {
594594
public static String MainPreferencePage_WorkspacePluginsOverrideTarget;
595595
public static String MainPreferencePage_WorkspacePluginsOverrideTargetTooltip;
596596
public static String MainPreferencePage_DisableAPIAnalysisBuilder;
597+
598+
public static String MainPreferencePage_optionTestPlugin;
597599
public static String MainPreferencePage_RunAPIAnalysisBuilderAsJob;
598600

599601
public static String MainPreferencePage_test_plugin_pattern_group;

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ MainPreferencePage_junitWorkspace_asLocation=Us&e as workspace location
355355
MainPreferencePage_junitWorkspace_fileSystem=File S&ystem...
356356
MainPreferencePage_junitWorkspace_variables=Va&riables...
357357
MainPreferencePage_junitWorkspace_workspace=W&orkspace...
358-
MainPreferencePage_junitWorkspaceGroup=Workspace location for new JUnit Plug-in Test launch configurations
358+
MainPreferencePage_junitWorkspaceGroup=For new JUnit Plug-in Test launch configurations
359359
MainPreferencePage_promptBeforeOverwrite=Prompt &before overwriting build.xml files when exporting
360360
MainPreferencePage_promtBeforeRemove=Prompt before deleting a &target definition file
361361
MainPreferencePage_runtimeWorkspace_asContainer=Append launch &configuration name to this location
@@ -369,6 +369,7 @@ MainPreferencePage_ShowTargetStatus=S&how current target platform in status bar
369369
MainPreferencePage_updateStale=&Update stale manifest files prior to launching
370370
MainPreferencePage_WorkspacePluginsOverrideTarget=Workspace p&lug-ins override target platform plug-ins with the same id
371371
MainPreferencePage_DisableAPIAnalysisBuilder=&Disable API analysis builder
372+
MainPreferencePage_optionTestPlugin=The Plug-in of the Test
372373
MainPreferencePage_RunAPIAnalysisBuilderAsJob=&Run API analysis in the background (experimental)
373374
MainPreferencePage_WorkspacePluginsOverrideTargetTooltip=When disabled, all plug-in versions from workspace and target platform are being used.
374375
MainPreferencePage_test_plugin_pattern_group=Test plug-in detection:

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/MainPreferencePage.java

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.eclipse.swt.layout.GridData;
5656
import org.eclipse.swt.layout.GridLayout;
5757
import org.eclipse.swt.widgets.Button;
58+
import org.eclipse.swt.widgets.Combo;
5859
import org.eclipse.swt.widgets.Composite;
5960
import org.eclipse.swt.widgets.Control;
6061
import org.eclipse.swt.widgets.Group;
@@ -125,6 +126,20 @@ private final class DefaultJUnitWorkspaceBlock extends BaseBlock {
125126
public void createControl(Composite parent) {
126127
Group group = SWTFactory.createGroup(parent, PDEUIMessages.MainPreferencePage_junitWorkspaceGroup, 2, 1,
127128
GridData.FILL_HORIZONTAL);
129+
SWTFactory.createLabel(group, PDEUIMessages.PluginsTab_launchWith, 1);
130+
fJunitLaunchWithCombo = SWTFactory.createCombo(group, SWT.READ_ONLY | SWT.BORDER, 1,
131+
GridData.HORIZONTAL_ALIGN_BEGINNING,
132+
new String[] { PDEUIMessages.MainPreferencePage_optionTestPlugin, PDEUIMessages.PluginsTab_allPlugins });
133+
SWTFactory.createLabel(group, "", 1); //$NON-NLS-1$
134+
Composite options = SWTFactory.createComposite(group, 1, 1, GridData.FILL_HORIZONTAL, 0, 0);
135+
fJunitAutoIncludeRequirementsButton = SWTFactory.createCheckButton(options,
136+
PDEUIMessages.AdvancedLauncherTab_autoIncludeRequirements_plugins, null, true, 1);
137+
fJunitIncludeOptionalButton = SWTFactory.createCheckButton(options,
138+
PDEUIMessages.AdvancedLauncherTab_includeOptional_plugins, null, true, 1);
139+
fJunitAddWorkspaceButton = SWTFactory.createCheckButton(options,
140+
PDEUIMessages.AdvancedLauncherTab_addNew_plugins, null, false, 1);
141+
fJunitAutoValidate = SWTFactory.createCheckButton(options,
142+
PDEUIMessages.PluginsTabToolBar_auto_validate_plugins, null, true, 1);
128143
Composite radios = SWTFactory.createComposite(group, 2, 2, GridData.FILL_HORIZONTAL, 0, 0);
129144

130145
fJUnitWorkspaceLocationRadio = new Button(radios, SWT.RADIO);
@@ -184,6 +199,12 @@ protected boolean isFile() {
184199

185200
private Text fTestPluginPatternText;
186201

202+
private Combo fJunitLaunchWithCombo;
203+
private Button fJunitAutoIncludeRequirementsButton;
204+
private Button fJunitIncludeOptionalButton;
205+
private Button fJunitAddWorkspaceButton;
206+
private Button fJunitAutoValidate;
207+
187208
public MainPreferencePage() {
188209
setPreferenceStore(PDEPlugin.getDefault().getPreferenceStore());
189210
setDescription(PDEUIMessages.Preferences_MainPage_Description);
@@ -328,7 +349,16 @@ protected Control createContents(Composite parent) {
328349
.getBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_WORKSPACE_LOCATION_IS_CONTAINER);
329350
fJUnitWorkspaceLocationRadio.setSelection(!jUnitLocationIsContainer);
330351
fJUnitWorkspacesContainerRadio.setSelection(jUnitLocationIsContainer);
331-
352+
fJunitLaunchWithCombo.select(ILaunchingPreferenceConstants.VALUE_JUNIT_LAUNCH_WITH_TESTPLUGIN
353+
.equals(launchingStore.getString(ILaunchingPreferenceConstants.PROP_JUNIT_LAUNCH_WITH)) ? 0 : 1);
354+
fJunitAutoIncludeRequirementsButton
355+
.setSelection(launchingStore.getBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_AUTO_INCLUDE));
356+
fJunitIncludeOptionalButton
357+
.setSelection(launchingStore.getBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_INCLUDE_OPTIONAL));
358+
fJunitAddWorkspaceButton.setSelection(
359+
launchingStore.getBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_ADD_NEW_WORKSPACE_PLUGINS));
360+
fJunitAutoValidate
361+
.setSelection(launchingStore.getBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_VALIDATE_LAUNCH));
332362
Group bundlePoolGp = SWTFactory.createGroup(composite, PDEUIMessages.MainPreferencePage_BundlePoolPrefsGroup, 2,
333363
1, GridData.FILL_HORIZONTAL);
334364
WidgetFactory.label(SWT.WRAP)
@@ -487,6 +517,18 @@ public boolean performOk() {
487517
fJUnitWorkspaceLocation.getText());
488518
launchingStore.setValueOrRemove(ILaunchingPreferenceConstants.PROP_JUNIT_WORKSPACE_LOCATION_IS_CONTAINER,
489519
fJUnitWorkspacesContainerRadio.getSelection());
520+
launchingStore.setValueOrRemove(ILaunchingPreferenceConstants.PROP_JUNIT_LAUNCH_WITH,
521+
fJunitLaunchWithCombo.getSelectionIndex() == 0
522+
? ILaunchingPreferenceConstants.VALUE_JUNIT_LAUNCH_WITH_TESTPLUGIN
523+
: ILaunchingPreferenceConstants.VALUE_JUNIT_LAUNCH_WITH_ALL);
524+
launchingStore.setValueOrRemove(ILaunchingPreferenceConstants.PROP_JUNIT_ADD_NEW_WORKSPACE_PLUGINS,
525+
fJunitAddWorkspaceButton.getSelection());
526+
launchingStore.setValueOrRemove(ILaunchingPreferenceConstants.PROP_JUNIT_AUTO_INCLUDE,
527+
fJunitAutoIncludeRequirementsButton.getSelection());
528+
launchingStore.setValueOrRemove(ILaunchingPreferenceConstants.PROP_JUNIT_INCLUDE_OPTIONAL,
529+
fJunitIncludeOptionalButton.getSelection());
530+
launchingStore.setValueOrRemove(ILaunchingPreferenceConstants.PROP_JUNIT_VALIDATE_LAUNCH,
531+
fJunitAutoValidate.getSelection());
490532
try {
491533
launchingStore.flush();
492534
} catch (BackingStoreException e) {
@@ -537,6 +579,16 @@ protected void performDefaults() {
537579
fJUnitWorkspacesContainerRadio.setSelection(jUnitLocationIsContainer);
538580
fJUnitWorkspaceLocation
539581
.setText(launchingStore.getDefaultString(ILaunchingPreferenceConstants.PROP_JUNIT_WORKSPACE_LOCATION));
582+
fJunitLaunchWithCombo.select(ILaunchingPreferenceConstants.VALUE_JUNIT_LAUNCH_WITH_TESTPLUGIN
583+
.equals(launchingStore.getDefaultString(ILaunchingPreferenceConstants.PROP_JUNIT_LAUNCH_WITH)) ? 0 : 1);
584+
fJunitAutoIncludeRequirementsButton
585+
.setSelection(launchingStore.getDefaultBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_AUTO_INCLUDE));
586+
fJunitIncludeOptionalButton.setSelection(
587+
launchingStore.getDefaultBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_INCLUDE_OPTIONAL));
588+
fJunitAddWorkspaceButton.setSelection(
589+
launchingStore.getDefaultBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_ADD_NEW_WORKSPACE_PLUGINS));
590+
fJunitAutoValidate.setSelection(
591+
launchingStore.getDefaultBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_VALIDATE_LAUNCH));
540592
}
541593

542594
@Override

ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/launcher/JUnitWorkbenchLaunchShortcut.java

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,24 @@
1313
*******************************************************************************/
1414
package org.eclipse.pde.ui.launcher;
1515

16+
import java.util.HashSet;
17+
import java.util.Set;
18+
19+
import org.eclipse.core.resources.IProject;
1620
import org.eclipse.core.runtime.CoreException;
1721
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
1822
import org.eclipse.jdt.core.IJavaElement;
1923
import org.eclipse.jdt.junit.launcher.JUnitLaunchShortcut;
2024
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
25+
import org.eclipse.pde.core.plugin.IPluginModelBase;
2126
import org.eclipse.pde.core.plugin.TargetPlatform;
27+
import org.eclipse.pde.internal.core.PDECore;
28+
import org.eclipse.pde.internal.core.PDEPreferencesManager;
2229
import org.eclipse.pde.internal.core.TargetPlatformHelper;
30+
import org.eclipse.pde.internal.launching.ILaunchingPreferenceConstants;
2331
import org.eclipse.pde.internal.launching.IPDEConstants;
32+
import org.eclipse.pde.internal.launching.PDELaunchingPlugin;
33+
import org.eclipse.pde.internal.launching.launcher.BundleLauncherHelper;
2434
import org.eclipse.pde.internal.launching.launcher.LaunchArgumentsHelper;
2535
import org.eclipse.pde.internal.launching.launcher.LauncherUtils;
2636
import org.eclipse.pde.launching.IPDELauncherConstants;
@@ -68,13 +78,31 @@ protected ILaunchConfigurationWorkingCopy createLaunchConfiguration(IJavaElement
6878
} else {
6979
configuration.setAttribute(IPDELauncherConstants.APPLICATION, IPDEConstants.CORE_TEST_APPLICATION);
7080
}
71-
72-
// Plug-ins to launch
73-
configuration.setAttribute(IPDELauncherConstants.USE_DEFAULT, true);
74-
configuration.setAttribute(IPDELauncherConstants.AUTOMATIC_VALIDATE, false);
75-
configuration.setAttribute(IPDELauncherConstants.USE_CUSTOM_FEATURES, false); // ignored
76-
configuration.setAttribute(IPDELauncherConstants.AUTOMATIC_ADD, true); // ignored
77-
configuration.setAttribute(IPDELauncherConstants.INCLUDE_OPTIONAL, true); // ignored
81+
PDEPreferencesManager launchingStore = PDELaunchingPlugin.getDefault().getPreferenceManager();
82+
if (ILaunchingPreferenceConstants.VALUE_JUNIT_LAUNCH_WITH_TESTPLUGIN
83+
.equals(launchingStore.getString(ILaunchingPreferenceConstants.PROP_JUNIT_LAUNCH_WITH))) {
84+
configuration.setAttribute(IPDELauncherConstants.USE_CUSTOM_FEATURES, false);
85+
IProject project = element.getJavaProject().getProject();
86+
IPluginModelBase model = PDECore.getDefault().getModelManager()
87+
.findModel(project);
88+
configuration.setAttribute(IPDELauncherConstants.USE_DEFAULT, model == null);
89+
if (model != null) {
90+
Set<String> wsplugins = new HashSet<>();
91+
appendPlugin(wsplugins, model);
92+
configuration.setAttribute(IPDELauncherConstants.SELECTED_WORKSPACE_BUNDLES, wsplugins);
93+
}
94+
} else {
95+
configuration.setAttribute(IPDELauncherConstants.USE_DEFAULT, true);
96+
configuration.setAttribute(IPDELauncherConstants.USE_CUSTOM_FEATURES, false); // ignored
97+
}
98+
configuration.setAttribute(IPDELauncherConstants.AUTOMATIC_INCLUDE_REQUIREMENTS,
99+
launchingStore.getBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_AUTO_INCLUDE));
100+
configuration.setAttribute(IPDELauncherConstants.INCLUDE_OPTIONAL,
101+
launchingStore.getBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_INCLUDE_OPTIONAL));
102+
configuration.setAttribute(IPDELauncherConstants.AUTOMATIC_ADD,
103+
launchingStore.getBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_ADD_NEW_WORKSPACE_PLUGINS));
104+
configuration.setAttribute(IPDELauncherConstants.AUTOMATIC_VALIDATE,
105+
launchingStore.getBoolean(ILaunchingPreferenceConstants.PROP_JUNIT_VALIDATE_LAUNCH));
78106

79107
// Program arguments
80108
String programArgs = LaunchArgumentsHelper.getInitialProgramArguments();
@@ -108,4 +136,12 @@ protected ILaunchConfigurationWorkingCopy createLaunchConfiguration(IJavaElement
108136
return configuration;
109137
}
110138

139+
private void appendPlugin(Set<String> plugins, IPluginModelBase model) {
140+
final StringBuilder builder = new StringBuilder();
141+
builder.append(model.getPluginBase().getId());
142+
builder.append(BundleLauncherHelper.VERSION_SEPARATOR);
143+
builder.append(model.getPluginBase().getVersion());
144+
plugins.add(builder.toString());
145+
}
146+
111147
}

0 commit comments

Comments
 (0)