Skip to content

Commit f62f151

Browse files
committed
Do not perform launch configuration validation twice in a row #160
1 parent ba5e639 commit f62f151

File tree

8 files changed

+178
-93
lines changed

8 files changed

+178
-93
lines changed

launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/ext/Q7ExternalLaunchDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public boolean preLaunchCheck(ILaunchConfiguration configuration,
238238
Q7ExtLaunchingPlugin.getDefault().info(
239239
Q7_LAUNCHING_AUT + configuration.getName()
240240
+ ": Detected AUT architecture is "
241-
+ architecture.name() + "." + detectMsg.toString());
241+
+ architecture.name() + ". " + detectMsg.toString());
242242

243243
IVMInstall install = VMHelper.getVMInstall(configuration);
244244

launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/ext/Q7LaunchDelegateUtils.java

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import static com.google.common.collect.Iterables.find;
1515
import static com.google.common.collect.Iterables.transform;
1616
import static java.util.Arrays.asList;
17+
import static java.util.stream.Collectors.toSet;
18+
import static org.eclipse.core.runtime.IProgressMonitor.done;
1719
import static org.eclipse.pde.internal.build.IPDEBuildConstants.BUNDLE_SIMPLE_CONFIGURATOR;
1820
import static org.eclipse.pde.internal.launching.launcher.LaunchConfigurationHelper.getBundleURL;
1921

@@ -28,18 +30,29 @@
2830
import java.util.Map.Entry;
2931

3032
import org.eclipse.core.runtime.CoreException;
33+
import org.eclipse.core.runtime.IProgressMonitor;
34+
import org.eclipse.core.runtime.IStatus;
35+
import org.eclipse.core.runtime.OperationCanceledException;
3136
import org.eclipse.core.runtime.Platform;
37+
import org.eclipse.core.runtime.Status;
38+
import org.eclipse.core.runtime.SubMonitor;
3239
import org.eclipse.debug.core.DebugPlugin;
40+
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
41+
import org.eclipse.jdt.launching.JavaRuntime;
42+
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
43+
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
44+
import org.eclipse.osgi.service.resolver.ResolverError;
3345
import org.eclipse.pde.core.plugin.IPluginModelBase;
3446
import org.eclipse.pde.internal.build.IPDEBuildConstants;
3547
import org.eclipse.pde.internal.launching.launcher.LaunchArgumentsHelper;
48+
import org.eclipse.pde.internal.launching.launcher.LaunchValidationOperation;
3649
import org.eclipse.pde.launching.EclipseApplicationLaunchConfiguration;
3750
import org.eclipse.rcptt.internal.core.RcpttPlugin;
38-
import org.eclipse.rcptt.internal.launching.ext.AJConstants;
39-
import org.eclipse.rcptt.internal.launching.ext.PDEUtils;
51+
import org.eclipse.rcptt.internal.launching.ext.OSArchitecture;
4052
import org.eclipse.rcptt.internal.launching.ext.Q7ExtLaunchingPlugin;
4153
import org.eclipse.rcptt.internal.launching.ext.UpdateVMArgs;
4254
import org.eclipse.rcptt.launching.target.ITargetPlatformHelper;
55+
import org.eclipse.rcptt.launching.target.ITargetPlatformHelper.Model;
4356

4457
import com.google.common.base.Function;
4558
import com.google.common.base.Joiner;
@@ -53,6 +66,64 @@
5366

5467
@SuppressWarnings("restriction")
5568
public class Q7LaunchDelegateUtils {
69+
70+
public static IStatus validateForLaunch(ITargetPlatformHelper target, IProgressMonitor monitor) {
71+
SubMonitor sm = SubMonitor.convert(monitor, "Validating bundles", 2);
72+
ILaunchConfigurationWorkingCopy wc = null;
73+
try {
74+
wc = Q7LaunchingUtil.createLaunchConfiguration(target);
75+
StringBuilder message = new StringBuilder();
76+
OSArchitecture architecture = target.detectArchitecture(message);
77+
if (architecture == null || architecture == OSArchitecture.Unknown) {
78+
return Status.error(message.toString());
79+
}
80+
if (!Q7ExternalLaunchDelegate.updateJVM(wc, architecture, target)) {
81+
return Status.error(String.format(
82+
"No compatible JRE is configured. Architecture: %s, incompatible environments: %s",
83+
architecture, target.getIncompatibleExecutionEnvironments()));
84+
}
85+
} catch (CoreException e) {
86+
return e.getStatus();
87+
}
88+
89+
LaunchValidationOperation validation = new LaunchValidationOperation(wc, target.getModels().map(Model::model).collect(toSet())) {
90+
@Override
91+
protected IExecutionEnvironment[] getMatchingEnvironments()
92+
throws CoreException {
93+
IExecutionEnvironmentsManager manager = JavaRuntime
94+
.getExecutionEnvironmentsManager();
95+
IExecutionEnvironment[] envs = manager
96+
.getExecutionEnvironments();
97+
return envs;
98+
}
99+
};
100+
try {
101+
wc.delete();
102+
} catch (CoreException e1) {
103+
return e1.getStatus();
104+
}
105+
try {
106+
StringBuilder b = new StringBuilder();
107+
validation.run(sm.split(1));
108+
Map<Object, Object[]> input = validation.getInput();
109+
for (Map.Entry<Object, Object[]> e : input.entrySet()) {
110+
Object value = e.getKey();
111+
if (value instanceof ResolverError) {
112+
b.append(value.toString()).append("\n");
113+
}
114+
}
115+
if (b.length() > 0) {
116+
return Status.error("Bundle validation failed: " + b.toString());
117+
}
118+
done(monitor);
119+
} catch (CoreException e) {
120+
return e.getStatus();
121+
} catch (OperationCanceledException e) {
122+
return Status.CANCEL_STATUS;
123+
}
124+
return Status.OK_STATUS;
125+
}
126+
56127
private static String getEntry(IPluginModelBase bundle, String startLevel) {
57128
StringBuilder result = new StringBuilder("reference:");
58129
result.append(getBundleURL(bundle, false));

launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/internal/target/TargetPlatformHelper.java

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,9 @@
6363
import org.eclipse.core.runtime.IProgressMonitor;
6464
import org.eclipse.core.runtime.IStatus;
6565
import org.eclipse.core.runtime.MultiStatus;
66-
import org.eclipse.core.runtime.OperationCanceledException;
6766
import org.eclipse.core.runtime.Platform;
6867
import org.eclipse.core.runtime.Status;
6968
import org.eclipse.core.runtime.SubMonitor;
70-
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
7169
import org.eclipse.emf.common.util.EList;
7270
import org.eclipse.equinox.frameworkadmin.BundleInfo;
7371
import org.eclipse.equinox.internal.simpleconfigurator.utils.SimpleConfiguratorUtils;
@@ -77,10 +75,6 @@
7775
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
7876
import org.eclipse.equinox.p2.repository.artifact.IFileArtifactRepository;
7977
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
80-
import org.eclipse.jdt.launching.JavaRuntime;
81-
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
82-
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
83-
import org.eclipse.osgi.service.resolver.ResolverError;
8478
import org.eclipse.pde.core.plugin.IPluginModelBase;
8579
import org.eclipse.pde.core.target.ITargetDefinition;
8680
import org.eclipse.pde.core.target.ITargetLocation;
@@ -92,16 +86,13 @@
9286
import org.eclipse.pde.internal.core.target.IUBundleContainer;
9387
import org.eclipse.pde.internal.core.target.P2TargetUtils;
9488
import org.eclipse.pde.internal.core.target.ProfileBundleContainer;
95-
import org.eclipse.pde.internal.launching.launcher.LaunchValidationOperation;
9689
import org.eclipse.rcptt.internal.launching.ext.AJConstants;
9790
import org.eclipse.rcptt.internal.launching.ext.OSArchitecture;
9891
import org.eclipse.rcptt.internal.launching.ext.Q7ExtLaunchingPlugin;
9992
import org.eclipse.rcptt.launching.ext.AUTInformation;
10093
import org.eclipse.rcptt.launching.ext.BundleStart;
10194
import org.eclipse.rcptt.launching.ext.OriginalOrderProperties;
102-
import org.eclipse.rcptt.launching.ext.Q7ExternalLaunchDelegate;
10395
import org.eclipse.rcptt.launching.ext.Q7LaunchDelegateUtils;
104-
import org.eclipse.rcptt.launching.ext.Q7LaunchingUtil;
10596
import org.eclipse.rcptt.launching.ext.StartLevelSupport;
10697
import org.eclipse.rcptt.launching.injection.Directory;
10798
import org.eclipse.rcptt.launching.injection.Entry;
@@ -385,63 +376,6 @@ private void filterHooks() {
385376

386377
private IPluginModelBase weavingHook;
387378

388-
private IStatus validateBundles(IProgressMonitor monitor) {
389-
SubMonitor sm = SubMonitor.convert(monitor, "Validating bundles", 2);
390-
ILaunchConfigurationWorkingCopy wc = null;
391-
try {
392-
wc = Q7LaunchingUtil.createLaunchConfiguration(this);
393-
StringBuilder message = new StringBuilder();
394-
OSArchitecture architecture = detectArchitecture(message);
395-
if (architecture == null || architecture == OSArchitecture.Unknown) {
396-
return error(message.toString());
397-
}
398-
if (!Q7ExternalLaunchDelegate.updateJVM(wc, architecture, this)) {
399-
return Status.error(String.format(
400-
"No compatible JRE is configured. Architecture: %s, incompatible environments: %s",
401-
architecture, getIncompatibleExecutionEnvironments()));
402-
}
403-
} catch (CoreException e) {
404-
return e.getStatus();
405-
}
406-
407-
LaunchValidationOperation validation = new LaunchValidationOperation(wc,
408-
new HashSet<>(modelIndex.values())) {
409-
@Override
410-
protected IExecutionEnvironment[] getMatchingEnvironments()
411-
throws CoreException {
412-
IExecutionEnvironmentsManager manager = JavaRuntime
413-
.getExecutionEnvironmentsManager();
414-
IExecutionEnvironment[] envs = manager
415-
.getExecutionEnvironments();
416-
return envs;
417-
}
418-
};
419-
try {
420-
wc.delete();
421-
} catch (CoreException e1) {
422-
return e1.getStatus();
423-
}
424-
try {
425-
StringBuilder b = new StringBuilder();
426-
validation.run(sm.split(1));
427-
Map<Object, Object[]> input = validation.getInput();
428-
for (Map.Entry<Object, Object[]> e : input.entrySet()) {
429-
Object value = e.getKey();
430-
if (value instanceof ResolverError) {
431-
b.append(value.toString()).append("\n");
432-
}
433-
}
434-
if (b.length() > 0) {
435-
return error("Bundle validation failed: " + b.toString());
436-
}
437-
done(monitor);
438-
} catch (CoreException e) {
439-
return e.getStatus();
440-
} catch (OperationCanceledException e) {
441-
return Status.CANCEL_STATUS;
442-
}
443-
return Status.OK_STATUS;
444-
}
445379

446380
private Status error(String message) {
447381
return new Status(IStatus.ERROR, PLUGIN_ID, message);
@@ -506,7 +440,7 @@ private PDEExtensionRegistry getRegistry() {
506440
public IStatus resolve(IProgressMonitor monitor) {
507441
resetIndex();
508442
ITargetDefinition target = getTarget();
509-
SubMonitor m = SubMonitor.convert(monitor, "Resolving " + getName(), 4);
443+
SubMonitor m = SubMonitor.convert(monitor, "Resolving " + getName(), 3);
510444
try {
511445
status.add(target.resolve(m.split(1, SubMonitor.SUPPRESS_NONE)));
512446
if (isBad(status))
@@ -517,7 +451,6 @@ public IStatus resolve(IProgressMonitor monitor) {
517451
index();
518452
filterHooks();
519453
resolved = target.isResolved();
520-
status.add(validateBundles(m.split(1, SubMonitor.SUPPRESS_NONE)));
521454
if (isBad(status))
522455
return status;
523456
if (status.isOK()) {

launching/tests/org.eclipse.rcptt.launching.ext.tests/src/org/eclipse/rcptt/launching/internal/target/macosx_x86_64.target

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@
1010
</location>
1111
</locations>
1212
<targetJRE path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
13+
<environment>
14+
<arch>x86_64</arch>
15+
</environment>
1316
</target>

rcp/org.eclipse.rcptt.launching.ext.ui/src/org/eclipse/rcptt/internal/launching/ext/ui/AUTLocationBlock.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*******************************************************************************/
1111
package org.eclipse.rcptt.internal.launching.ext.ui;
1212

13+
import static org.eclipse.core.runtime.IProgressMonitor.done;
1314
import static org.eclipse.rcptt.internal.launching.ext.Q7ExtLaunchingPlugin.PLUGIN_ID;
1415

1516
import java.lang.reflect.InvocationTargetException;
@@ -19,16 +20,17 @@
1920
import org.eclipse.core.runtime.IProgressMonitor;
2021
import org.eclipse.core.runtime.IStatus;
2122
import org.eclipse.core.runtime.Status;
23+
import org.eclipse.core.runtime.SubMonitor;
2224
import org.eclipse.debug.core.ILaunchConfiguration;
2325
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
24-
import org.eclipse.debug.core.Launch;
2526
import org.eclipse.jdt.internal.debug.ui.actions.ControlAccessibleListener;
2627
import org.eclipse.jface.dialogs.IDialogConstants;
2728
import org.eclipse.jface.operation.IRunnableWithProgress;
2829
import org.eclipse.pde.internal.ui.SWTFactory;
2930
import org.eclipse.rcptt.internal.launching.ext.PDELocationUtils;
3031
import org.eclipse.rcptt.internal.launching.ext.Q7TargetPlatformManager;
3132
import org.eclipse.rcptt.launching.IQ7Launch;
33+
import org.eclipse.rcptt.launching.ext.Q7LaunchDelegateUtils;
3234
import org.eclipse.rcptt.launching.target.ITargetPlatformHelper;
3335
import org.eclipse.swt.SWT;
3436
import org.eclipse.swt.events.ModifyEvent;
@@ -105,11 +107,20 @@ public void updateInfo() {
105107
public void run(IProgressMonitor monitor)
106108
throws InvocationTargetException, InterruptedException {
107109
try {
108-
info = Q7TargetPlatformManager.getTarget(original, monitor);
109-
assert info.getStatus().isOK();
110+
SubMonitor sm = SubMonitor.convert(monitor, 2);
111+
ITargetPlatformHelper temp = Q7TargetPlatformManager.getTarget(original, sm.split(1));
112+
if (!temp.getStatus().matches(IStatus.ERROR|IStatus.CANCEL)) {
113+
IStatus result = Q7LaunchDelegateUtils.validateForLaunch(temp, sm.split(1));
114+
if (result.matches(IStatus.ERROR|IStatus.CANCEL)) {
115+
temp.delete();
116+
throw new CoreException(result);
117+
}
118+
info = temp;
119+
}
110120
} catch (CoreException e) {
111121
setStatus(e.getStatus());
112122
}
123+
done(monitor);
113124
}
114125
});
115126
}
@@ -211,11 +222,20 @@ public void initializeFrom(final ILaunchConfiguration config) {
211222
public void run(IProgressMonitor monitor)
212223
throws InvocationTargetException, InterruptedException {
213224
try {
214-
info = Q7TargetPlatformManager.getTarget(original, monitor);
225+
SubMonitor sm = SubMonitor.convert(monitor, 2);
226+
ITargetPlatformHelper temp = Q7TargetPlatformManager.getTarget(original, sm.split(1));
227+
if (!temp.getStatus().matches(IStatus.ERROR|IStatus.CANCEL)) {
228+
IStatus result = Q7LaunchDelegateUtils.validateForLaunch(temp, sm.split(1));
229+
if (result.matches(IStatus.ERROR|IStatus.CANCEL)) {
230+
temp.delete();
231+
throw new CoreException(result);
232+
}
233+
info = temp;
234+
}
215235
} catch (CoreException e) {
216-
Activator.log(e);
236+
setStatus(e.getStatus());
217237
}
218-
238+
done(monitor);
219239
}
220240
});
221241
locationField.setText(location);

0 commit comments

Comments
 (0)