Skip to content

Commit b094c16

Browse files
committed
Reduce re-computation of plugins included in Eclipse/OSGi launches
This ensures consistency and reduces calls of DependencyManager.findRequirementsClosure().
1 parent 23371e1 commit b094c16

File tree

12 files changed

+72
-44
lines changed

12 files changed

+72
-44
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
https://github.com/eclipse-pde/eclipse.pde/pull/1665
1+
https://github.com/eclipse-pde/eclipse.pde/pull/1665
2+
https://github.com/eclipse-pde/eclipse.pde/pull/1724
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<component id="org.eclipse.pde.launching" version="2">
3+
<resource path="META-INF/MANIFEST.MF">
4+
<filter comment="Removal of overriden EquinoxLaunchConfiguration.preLaunchCheck() method is falsely considered a addition." id="924844039">
5+
<message_arguments>
6+
<message_argument value="3.13.400"/>
7+
<message_argument value="3.13.300"/>
8+
</message_arguments>
9+
</filter>
10+
</resource>
11+
</component>

ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/launcher/LaunchArgumentsHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,15 @@ public static File getWorkingDirectory(ILaunchConfiguration configuration) throw
207207
return dir;
208208
}
209209

210-
public static Map<String, Object> getVMSpecificAttributesMap(ILaunchConfiguration config) throws CoreException {
210+
public static Map<String, Object> getVMSpecificAttributesMap(ILaunchConfiguration config, Set<IPluginModelBase> plugins) throws CoreException {
211211
Map<String, Object> map = new HashMap<>(2);
212212
String javaCommand = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_JAVA_COMMAND, (String) null);
213213
map.put(IJavaLaunchConfigurationConstants.ATTR_JAVA_COMMAND, javaCommand);
214214
// Add jdi.jar for macos when java version is less than 1.7
215215
if (TargetPlatform.getOS().equals("macosx")) { //$NON-NLS-1$
216216
ModelEntry entry = PluginRegistry.findEntry("org.eclipse.jdt.debug"); //$NON-NLS-1$
217217
if (entry != null) {
218-
IVMInstall vmInstall = VMHelper.getVMInstall(config);
218+
IVMInstall vmInstall = VMHelper.getVMInstall(config, plugins);
219219
if (vmInstall instanceof AbstractVMInstall) {
220220
String javaVersion = ((AbstractVMInstall) vmInstall).getJavaVersion();
221221
String[] javaVersionSegments = javaVersion.split("\\."); //$NON-NLS-1$

ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/launcher/LaunchValidationOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected Dictionary<String, String>[] getPlatformProperties() throws CoreExcept
8484
}
8585

8686
protected IExecutionEnvironment[] getMatchingEnvironments() throws CoreException {
87-
IVMInstall install = VMHelper.getVMInstall(fLaunchConfiguration);
87+
IVMInstall install = VMHelper.getVMInstall(fLaunchConfiguration, fModels);
8888
return install == null ? new IExecutionEnvironment[0] : getMatchingEEs(install);
8989
}
9090

ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/launcher/VMHelper.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.eclipse.pde.core.plugin.IPluginModelBase;
3737
import org.eclipse.pde.internal.core.util.VMUtil;
3838
import org.eclipse.pde.internal.launching.PDEMessages;
39-
import org.eclipse.pde.launching.EquinoxLaunchConfiguration;
4039

4140
public class VMHelper {
4241

@@ -45,11 +44,11 @@ public class VMHelper {
4544
* BREE supplied by every bundle that will be launched in the given launch configuration or
4645
* <code>null</code> if no valid/bound execution environment could be found.
4746
*
48-
* @param configuration the launch configuration to test the bundle's BREEs of
47+
* @param plugins the set of plug-ins to test for their BREEs
4948
* @return string id of a valid execution environment with a bound JRE or <code>null</code>
5049
* @throws CoreException if there is a problem reading the bundles from the launch configuration
5150
*/
52-
public static String getDefaultEEName(ILaunchConfiguration configuration) throws CoreException {
51+
public static String getDefaultEEName(Set<IPluginModelBase> plugins) throws CoreException {
5352
// List of all valid EEs, removed if they don't match
5453
List<IExecutionEnvironment> validEEs = new LinkedList<>(); // Use a list to keep order
5554
validEEs.addAll(Arrays.asList(JavaRuntime.getExecutionEnvironmentsManager().getExecutionEnvironments()));
@@ -65,8 +64,6 @@ public static String getDefaultEEName(ILaunchConfiguration configuration) throws
6564
}
6665

6766
// Iterate through all launch models
68-
boolean isOSGiLaunch = configuration instanceof EquinoxLaunchConfiguration; // TODO Test this
69-
Set<IPluginModelBase> plugins = BundleLauncherHelper.getMergedBundleMap(configuration, isOSGiLaunch).keySet();
7067
for (IPluginModelBase plugin : plugins) {
7168
if (validEEs.isEmpty()) {
7269
break; // No valid EEs left, short circuit
@@ -161,10 +158,11 @@ public static String getDefaultVMInstallName(ILaunchConfiguration configuration)
161158
* a default setting will be used (but not saved in the launch configuration).
162159
*
163160
* @param configuration the configuration to get a vm install for
161+
* @param plugins all plugins included in the launch
164162
* @return a vm install from {@link JavaRuntime}
165163
* @throws CoreException if a vm install could not be found for the settings in the configuration
166164
*/
167-
public static IVMInstall getVMInstall(ILaunchConfiguration configuration) throws CoreException {
165+
public static IVMInstall getVMInstall(ILaunchConfiguration configuration, Set<IPluginModelBase> plugins) throws CoreException {
168166
String jre = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String) null);
169167

170168
// Launch configuration has a JRE or EE set, throw exception if associated vm not found
@@ -183,7 +181,7 @@ public static IVMInstall getVMInstall(ILaunchConfiguration configuration) throws
183181
}
184182

185183
// Find a default EE
186-
String eeId = VMHelper.getDefaultEEName(configuration);
184+
String eeId = VMHelper.getDefaultEEName(plugins);
187185
if (eeId != null) {
188186
IExecutionEnvironment ee = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(eeId);
189187
String vmName = VMUtil.getVMInstallName(ee);
@@ -207,8 +205,8 @@ public static IVMInstall getVMInstall(ILaunchConfiguration configuration) throws
207205

208206
}
209207

210-
public static IVMInstall createLauncher(ILaunchConfiguration configuration) throws CoreException {
211-
IVMInstall launcher = getVMInstall(configuration);
208+
public static IVMInstall createLauncher(ILaunchConfiguration configuration, Set<IPluginModelBase> plugins) throws CoreException {
209+
IVMInstall launcher = getVMInstall(configuration, plugins);
212210
if (!launcher.getInstallLocation().exists()) {
213211
throw new CoreException(Status.error(PDEMessages.WorkbenchLauncherConfigurationDelegate_jrePathNotFound));
214212
}
@@ -226,7 +224,8 @@ public static IVMInstall createLauncher(ILaunchConfiguration configuration) thro
226224
* or if unable to retrieve the launch configuration attributes
227225
*/
228226
public static IRuntimeClasspathEntry getJREEntry(ILaunchConfiguration configuration) throws CoreException {
229-
IVMInstall jre = createLauncher(configuration);
227+
Set<IPluginModelBase> plugins = BundleLauncherHelper.getMergedBundleMap(configuration, false).keySet();
228+
IVMInstall jre = createLauncher(configuration, plugins);
230229
IPath containerPath = IPath.fromOSString(JavaRuntime.JRE_CONTAINER);
231230
containerPath = containerPath.append(jre.getVMInstallType().getId());
232231
containerPath = containerPath.append(jre.getName());

ui/org.eclipse.pde.launching/src/org/eclipse/pde/launching/AbstractPDELaunchConfiguration.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public abstract class AbstractPDELaunchConfiguration extends LaunchConfiguration
7878

7979
protected File fConfigDir = null;
8080
String launchMode;
81+
private Set<IPluginModelBase> launchedPlugins;
8182

8283
/**
8384
* This field will control the addition of argument --add-modules=ALL-SYSTEM in the VM arguments
@@ -101,8 +102,9 @@ public String showCommandLine(ILaunchConfiguration configuration, String mode, I
101102
String commandLine = ""; //$NON-NLS-1$
102103
launch.setAttribute(PDE_LAUNCH_SHOW_COMMAND, "true"); //$NON-NLS-1$
103104
fConfigDir = null;
104-
SubMonitor subMonitor = SubMonitor.convert(monitor, 4);
105+
SubMonitor subMonitor = SubMonitor.convert(monitor, 5);
105106
try {
107+
launchedPlugins = computeLaunchedPlugins(configuration, subMonitor.split(1));
106108
preLaunchCheck(configuration, launch, subMonitor.split(2));
107109
} catch (CoreException e) {
108110
if (e.getStatus().getSeverity() == IStatus.CANCEL) {
@@ -113,7 +115,7 @@ public String showCommandLine(ILaunchConfiguration configuration, String mode, I
113115
}
114116

115117
VMRunnerConfiguration runnerConfig = new VMRunnerConfiguration(getMainClass(), getClasspath(configuration));
116-
IVMInstall launcher = VMHelper.createLauncher(configuration);
118+
IVMInstall launcher = VMHelper.createLauncher(configuration, launchedPlugins);
117119
runnerConfig.setVMArguments(updateVMArgumentWithAdditionalArguments(getVMArguments(configuration), launcher));
118120
runnerConfig.setProgramArguments(getProgramArguments(configuration));
119121
runnerConfig.setWorkingDirectory(getWorkingDirectory(configuration).getAbsolutePath());
@@ -126,7 +128,7 @@ public String showCommandLine(ILaunchConfiguration configuration, String mode, I
126128
manageLaunch(launch);
127129
IVMRunner runner = getVMRunner(configuration, mode);
128130
if (runner != null) {
129-
commandLine = runner.showCommandLine(runnerConfig, launch, subMonitor);
131+
commandLine = runner.showCommandLine(runnerConfig, launch, subMonitor.split(1));
130132
} else {
131133
subMonitor.setCanceled(true);
132134
}
@@ -139,7 +141,8 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
139141
fConfigDir = null;
140142
SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
141143
try {
142-
preLaunchCheck(configuration, launch, subMonitor.split(50));
144+
launchedPlugins = computeLaunchedPlugins(configuration, subMonitor.split(10));
145+
preLaunchCheck(configuration, launch, subMonitor.split(40));
143146
} catch (CoreException e) {
144147
if (e.getStatus().getSeverity() == IStatus.CANCEL) {
145148
subMonitor.setCanceled(true);
@@ -149,7 +152,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
149152
}
150153

151154
VMRunnerConfiguration runnerConfig = new VMRunnerConfiguration(getMainClass(), getClasspath(configuration));
152-
IVMInstall launcher = VMHelper.createLauncher(configuration);
155+
IVMInstall launcher = VMHelper.createLauncher(configuration, launchedPlugins);
153156
runnerConfig.setVMArguments(updateVMArgumentWithAdditionalArguments(getVMArguments(configuration), launcher));
154157
runnerConfig.setProgramArguments(getProgramArguments(configuration));
155158
runnerConfig.setWorkingDirectory(getWorkingDirectory(configuration).getAbsolutePath());
@@ -166,7 +169,11 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
166169
} else {
167170
subMonitor.setCanceled(true);
168171
}
172+
}
169173

174+
Set<IPluginModelBase> computeLaunchedPlugins(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {
175+
//Sub-classes should overwrite this method and pass the set of to be launched plug-ins they probably have already computed
176+
return BundleLauncherHelper.getMergedBundleMap(configuration, false).keySet();
170177
}
171178

172179
private String[] updateVMArgumentWithAdditionalArguments(String[] args, IVMInstall vmInstall) {
@@ -216,7 +223,7 @@ private boolean isEclipseBundleGreaterThanVersion(int major, int minor) {
216223
* @throws CoreException if a VM runner cannot be determined
217224
*/
218225
public IVMRunner getVMRunner(ILaunchConfiguration configuration, String mode) throws CoreException {
219-
IVMInstall launcher = VMHelper.createLauncher(configuration);
226+
IVMInstall launcher = VMHelper.createLauncher(configuration, launchedPlugins);
220227
return launcher.getVMRunner(mode);
221228
}
222229

@@ -303,7 +310,7 @@ public File getWorkingDirectory(ILaunchConfiguration configuration) throws CoreE
303310
* if unable to retrieve the attribute
304311
*/
305312
public Map<String, Object> getVMSpecificAttributesMap(ILaunchConfiguration configuration) throws CoreException {
306-
return LaunchArgumentsHelper.getVMSpecificAttributesMap(configuration);
313+
return LaunchArgumentsHelper.getVMSpecificAttributesMap(configuration, launchedPlugins);
307314
}
308315

309316
/**

ui/org.eclipse.pde.launching/src/org/eclipse/pde/launching/EclipseApplicationLaunchConfiguration.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.List;
2323
import java.util.Map;
2424
import java.util.Properties;
25+
import java.util.Set;
2526
import java.util.stream.Collectors;
2627
import java.util.stream.Stream;
2728

@@ -206,16 +207,20 @@ protected void clear(ILaunchConfiguration configuration, IProgressMonitor monito
206207
}
207208

208209
@Override
209-
protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor) throws CoreException {
210-
fWorkspaceLocation = null;
210+
Set<IPluginModelBase> computeLaunchedPlugins(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {
211211
if (configuration.getAttribute(IPDELauncherConstants.GENERATE_PROFILE, false)) {
212212
fFeatures = new HashMap<>();
213213
} else {
214214
fFeatures = null;
215215
}
216216
fModels = BundleLauncherHelper.getMergedBundleMap(configuration, false, fFeatures);
217217
fAllBundles = fModels.keySet().stream().collect(Collectors.groupingBy(m -> m.getPluginBase().getId()));
218+
return fModels.keySet();
219+
}
218220

221+
@Override
222+
protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor) throws CoreException {
223+
fWorkspaceLocation = null;
219224
validateConfigIni(configuration);
220225
super.preLaunchCheck(configuration, launch, monitor);
221226
}

ui/org.eclipse.pde.launching/src/org/eclipse/pde/launching/EquinoxLaunchConfiguration.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
import java.util.Map;
2424
import java.util.Map.Entry;
2525
import java.util.Properties;
26+
import java.util.Set;
2627
import java.util.stream.Collectors;
2728

2829
import org.eclipse.core.runtime.CoreException;
2930
import org.eclipse.core.runtime.IPath;
3031
import org.eclipse.core.runtime.IProgressMonitor;
3132
import org.eclipse.core.runtime.Status;
32-
import org.eclipse.debug.core.ILaunch;
3333
import org.eclipse.debug.core.ILaunchConfiguration;
3434
import org.eclipse.pde.core.plugin.IFragmentModel;
3535
import org.eclipse.pde.core.plugin.IPluginModelBase;
@@ -185,15 +185,14 @@ private void appendStartData(StringBuilder buffer, String startData, boolean def
185185
}
186186

187187
@Override
188-
protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor) throws CoreException {
188+
Set<IPluginModelBase> computeLaunchedPlugins(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {
189189
fModels = BundleLauncherHelper.getMergedBundleMap(configuration, true);
190190

191191
if (!RequirementHelper.addApplicationLaunchRequirements(List.of(IPDEBuildConstants.BUNDLE_OSGI), configuration, fModels)) {
192192
throw new CoreException(Status.error(PDEMessages.EquinoxLaunchConfiguration_oldTarget));
193193
}
194194
fAllBundles = fModels.keySet().stream().collect(Collectors.groupingBy(m -> m.getPluginBase().getId(), HashMap::new, Collectors.toCollection(ArrayList::new)));
195-
196-
super.preLaunchCheck(configuration, launch, monitor);
195+
return fModels.keySet();
197196
}
198197

199198
@Override

ui/org.eclipse.pde.launching/src/org/eclipse/pde/launching/JUnitLaunchConfigurationDelegate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public class JUnitLaunchConfigurationDelegate extends org.eclipse.jdt.junit.laun
128128

129129
@Override
130130
public IVMRunner getVMRunner(ILaunchConfiguration configuration, String mode) throws CoreException {
131-
IVMInstall launcher = VMHelper.createLauncher(configuration);
131+
IVMInstall launcher = VMHelper.createLauncher(configuration, fModels.keySet());
132132
return launcher.getVMRunner(mode);
133133
}
134134

@@ -279,7 +279,7 @@ protected void collectExecutionArguments(ILaunchConfiguration configuration, Lis
279279
programArgs.add("-testpluginname"); //$NON-NLS-1$
280280
programArgs.add(testPlugin.getId());
281281

282-
IVMInstall launcher = VMHelper.createLauncher(configuration);
282+
IVMInstall launcher = VMHelper.createLauncher(configuration, fModels.keySet());
283283
boolean isModular = JavaRuntime.isModularJava(launcher);
284284
if (isModular) {
285285
VMHelper.addNewArgument(vmArguments, "--add-modules", "ALL-SYSTEM"); //$NON-NLS-1$//$NON-NLS-2$
@@ -412,7 +412,7 @@ public File getWorkingDirectory(ILaunchConfiguration configuration) throws CoreE
412412

413413
@Override
414414
public Map<String, Object> getVMSpecificAttributesMap(ILaunchConfiguration configuration) throws CoreException {
415-
return LaunchArgumentsHelper.getVMSpecificAttributesMap(configuration);
415+
return LaunchArgumentsHelper.getVMSpecificAttributesMap(configuration, fModels.keySet());
416416
}
417417

418418
@Override

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JREBlock.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.Arrays;
2020
import java.util.Comparator;
21+
import java.util.Set;
2122

2223
import org.eclipse.core.runtime.CoreException;
2324
import org.eclipse.core.runtime.IPath;
@@ -29,7 +30,9 @@
2930
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
3031
import org.eclipse.jface.window.Window;
3132
import org.eclipse.osgi.util.NLS;
33+
import org.eclipse.pde.core.plugin.IPluginModelBase;
3234
import org.eclipse.pde.internal.core.util.VMUtil;
35+
import org.eclipse.pde.internal.launching.launcher.BundleLauncherHelper;
3336
import org.eclipse.pde.internal.launching.launcher.VMHelper;
3437
import org.eclipse.pde.internal.ui.PDEUIMessages;
3538
import org.eclipse.pde.internal.ui.SWTFactory;
@@ -227,7 +230,10 @@ private void initializeJRESection(ILaunchConfiguration config) throws CoreExcept
227230
}
228231
// Try to get a default EE based on the selected plug-ins in the config
229232
if (eeId == null) {
230-
eeId = VMHelper.getDefaultEEName(config);
233+
boolean isOSGiLaunch = config.getType().getIdentifier()
234+
.equals(IPDELauncherConstants.OSGI_CONFIGURATION_TYPE);
235+
Set<IPluginModelBase> plugins = BundleLauncherHelper.getMergedBundleMap(config, isOSGiLaunch).keySet();
236+
eeId = VMHelper.getDefaultEEName(plugins);
231237
}
232238
if (eeId == null) {
233239
vmInstallName = VMHelper.getDefaultVMInstallName(config);

0 commit comments

Comments
 (0)