Skip to content

Commit a675712

Browse files
committed
test
1 parent 4fe820b commit a675712

File tree

4 files changed

+112
-2
lines changed

4 files changed

+112
-2
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@
3131
import org.eclipse.osgi.util.NLS;
3232
import org.eclipse.pde.core.plugin.IPluginModelBase;
3333
import org.eclipse.pde.internal.build.BundleHelper;
34+
import org.osgi.framework.hooks.resolver.ResolverHook;
3435

3536
public class BundleValidationOperation implements IWorkspaceRunnable {
3637

3738
private static StateObjectFactory FACTORY;
3839

3940
private final Set<IPluginModelBase> fModels;
4041
private final Dictionary<String, String>[] fProperties;
42+
private ResolverHook fResolverHook;
4143
private State fState;
4244

4345
@SuppressWarnings("unchecked")
@@ -50,13 +52,20 @@ public BundleValidationOperation(Set<IPluginModelBase> models, Dictionary<String
5052
fProperties = properties;
5153
}
5254

55+
public void setResolverHook(ResolverHook resolverHook) {
56+
fResolverHook = resolverHook;
57+
}
58+
5359
@Override
5460
public void run(IProgressMonitor monitor) throws CoreException {
5561
if (FACTORY == null) {
5662
FACTORY = BundleHelper.getPlatformAdmin().getFactory();
5763
}
5864
SubMonitor subMonitor = SubMonitor.convert(monitor, fModels.size() + 1);
5965
fState = FACTORY.createState(true);
66+
if (fResolverHook != null) {
67+
fState.setResolverHookFactory(c -> fResolverHook);
68+
}
6069
long id = 1;
6170
for (IPluginModelBase fModel : fModels) {
6271
BundleDescription bundle = fModel.getBundleDescription();

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@
3838
import org.eclipse.pde.core.plugin.PluginRegistry;
3939
import org.eclipse.pde.internal.core.BundleValidationOperation;
4040
import org.eclipse.pde.internal.core.TargetPlatformHelper;
41+
import org.osgi.framework.hooks.resolver.ResolverHook;
4142

4243
public class LaunchValidationOperation implements IWorkspaceRunnable {
4344

4445
private BundleValidationOperation fOperation;
4546
public final ILaunchConfiguration fLaunchConfiguration;
4647
public final String fLaunchMode;
4748
protected final Set<IPluginModelBase> fModels;
49+
private ResolverHook fResolverHook;
4850

4951
public LaunchValidationOperation(ILaunchConfiguration configuration, Set<IPluginModelBase> models) {
5052
this(configuration, models, null);
@@ -56,9 +58,16 @@ public LaunchValidationOperation(ILaunchConfiguration configuration, Set<IPlugin
5658
fLaunchMode = launchMode;
5759
}
5860

61+
public void setResolverHook(ResolverHook resolverHook) {
62+
fResolverHook = resolverHook;
63+
}
64+
5965
@Override
6066
public void run(IProgressMonitor monitor) throws CoreException {
6167
fOperation = new BundleValidationOperation(fModels, getPlatformProperties());
68+
if (fResolverHook != null) {
69+
fOperation.setResolverHook(fResolverHook);
70+
}
6271
fOperation.run(monitor);
6372
}
6473

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package org.eclipse.pde.launching;
2+
3+
import java.util.Collection;
4+
import java.util.HashMap;
5+
import java.util.Iterator;
6+
import java.util.Map;
7+
import java.util.Set;
8+
9+
import org.eclipse.debug.core.ILaunchConfiguration;
10+
import org.eclipse.pde.core.plugin.IPluginModelBase;
11+
import org.eclipse.pde.internal.launching.launcher.EclipsePluginValidationOperation;
12+
import org.osgi.framework.Version;
13+
import org.osgi.framework.hooks.resolver.ResolverHook;
14+
import org.osgi.framework.wiring.BundleCapability;
15+
import org.osgi.framework.wiring.BundleRequirement;
16+
import org.osgi.framework.wiring.BundleRevision;
17+
18+
final class JUnitEclipsePluginValidationOperation extends EclipsePluginValidationOperation {
19+
20+
private final JunitValidationHook junitValidationHook;
21+
22+
public JUnitEclipsePluginValidationOperation(ILaunchConfiguration configuration, Set<IPluginModelBase> models) {
23+
super(configuration, models);
24+
junitValidationHook = new JunitValidationHook(configuration);
25+
if (junitValidationHook.junitVersion == 5) {
26+
setResolverHook(junitValidationHook);
27+
}
28+
}
29+
30+
@Override
31+
public boolean hasErrors() {
32+
return super.hasErrors() || !junitValidationHook.errors.isEmpty();
33+
}
34+
35+
@Override
36+
public Map<Object, Object[]> getInput() {
37+
Map<Object, Object[]> map = super.getInput();
38+
map.putAll(junitValidationHook.errors);
39+
return map;
40+
}
41+
42+
private static class JunitValidationHook implements ResolverHook {
43+
44+
private final Map<Object, Object[]> errors;
45+
private final int junitVersion;
46+
47+
@SuppressWarnings("restriction")
48+
private JunitValidationHook(ILaunchConfiguration configuration) {
49+
errors = new HashMap<>(2);
50+
org.eclipse.jdt.internal.junit.launcher.ITestKind testKind = org.eclipse.jdt.internal.junit.launcher.JUnitLaunchConfigurationConstants.getTestRunnerKind(configuration);
51+
if (org.eclipse.jdt.internal.junit.launcher.TestKindRegistry.JUNIT5_TEST_KIND_ID.equals(testKind.getId())) {
52+
junitVersion = 5;
53+
} else {
54+
junitVersion = -1;
55+
}
56+
}
57+
58+
@Override
59+
public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) {
60+
Map<String, String> directives = requirement.getDirectives();
61+
if (!"optional".equals(directives.get("resolution"))) { //$NON-NLS-1$ //$NON-NLS-2$
62+
String requirementName = requirement.getRevision().getSymbolicName();
63+
if (!requirementName.startsWith("junit")) { //$NON-NLS-1$
64+
Iterator<BundleCapability> iterator = candidates.iterator();
65+
while (iterator.hasNext()) {
66+
BundleCapability candidate = iterator.next();
67+
BundleRevision candidateRevision = candidate.getRevision();
68+
String name = candidateRevision.getSymbolicName();
69+
Version version = candidateRevision.getVersion();
70+
if (version.getMajor() > junitVersion && name.startsWith("junit")) { //$NON-NLS-1$
71+
// TODO: externalize
72+
String error = requirementName + " depends on " + name + "_" + version; //$NON-NLS-1$ //$NON-NLS-2$
73+
errors.put(requirement, new Object[] {error});
74+
}
75+
}
76+
}
77+
}
78+
}
79+
80+
@Override
81+
public void filterResolvable(Collection<BundleRevision> candidates) {
82+
}
83+
84+
@Override
85+
public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) {
86+
}
87+
88+
@Override
89+
public void end() {
90+
}
91+
92+
}
93+
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
import org.eclipse.pde.internal.launching.PDELaunchingPlugin;
7575
import org.eclipse.pde.internal.launching.PDEMessages;
7676
import org.eclipse.pde.internal.launching.launcher.BundleLauncherHelper;
77-
import org.eclipse.pde.internal.launching.launcher.EclipsePluginValidationOperation;
7877
import org.eclipse.pde.internal.launching.launcher.LaunchArgumentsHelper;
7978
import org.eclipse.pde.internal.launching.launcher.LaunchConfigurationHelper;
8079
import org.eclipse.pde.internal.launching.launcher.LaunchPluginValidator;
@@ -610,7 +609,7 @@ protected void validateProjectDependencies(ILaunchConfiguration configuration, I
610609
* a progress monitor
611610
*/
612611
protected void validatePluginDependencies(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {
613-
EclipsePluginValidationOperation op = new EclipsePluginValidationOperation(configuration, fModels.keySet(), launchMode);
612+
JUnitEclipsePluginValidationOperation op = new JUnitEclipsePluginValidationOperation(configuration, fModels.keySet());
614613
LaunchPluginValidator.runValidationOperation(op, monitor);
615614
}
616615
}

0 commit comments

Comments
 (0)