Skip to content

Commit 04e1f4c

Browse files
committed
TestSuiteHelper: Include felix.scr if osgi.component is required
Some test cases use 'org.eclipse.core.runtime' as dependency. One of the runtime's dependencies (org.eclipse.core.contenttype) uses declarative services to provide a service component, but was missing the Require-Capability: header to require the osgi.extender=osgi.component. In eclipse-platform/eclipse.platform#2162 this was corrected. But as a result, for the resolution of org.eclipse.core.runtime to succeed, a OSGI extender provider must now strictly be present. This cannot be auto-resolved by the PDE API tooling tests, as these tests are quite special and the bundles available in the resolver state are hand-picked by TestSuiteHelper.addAllRequired(IApiBaseline, Set<String>, IApiComponent, List<IApiComponent>) which currently does not support this kind of dependency. To work around that, we check if we find a dependency on SCR and if so, add an implementation for it to the baseline fixture: org.apache.felix.scr and its dependencies.
1 parent 1f31fb9 commit 04e1f4c

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

  • apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/model/tests

apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/model/tests/TestSuiteHelper.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.eclipse.osgi.service.resolver.ResolverError;
3636
import org.eclipse.pde.api.tools.internal.model.ApiModelFactory;
3737
import org.eclipse.pde.api.tools.internal.model.ApiType;
38+
import org.eclipse.pde.api.tools.internal.model.BundleComponent;
3839
import org.eclipse.pde.api.tools.internal.provisional.IApiDescription;
3940
import org.eclipse.pde.api.tools.internal.provisional.IApiFilterStore;
4041
import org.eclipse.pde.api.tools.internal.provisional.IRequiredComponentDescription;
@@ -51,6 +52,8 @@
5152
import org.eclipse.pde.api.tools.internal.util.Util;
5253
import org.junit.Assert;
5354
import org.osgi.framework.Bundle;
55+
import org.osgi.framework.wiring.BundleCapability;
56+
import org.osgi.framework.wiring.BundleRequirement;
5457

5558
/**
5659
* Helper methods to set up baselines, etc.
@@ -411,6 +414,7 @@ public static File getBundle(String bundleName) {
411414
* @param collection collection to add prerequisites to.
412415
*/
413416
public static void addAllRequired(IApiBaseline baseline, Set<String> done, IApiComponent component, List<IApiComponent> collection) throws CoreException {
417+
addScrBundlesIfNecessary(baseline, done, component, collection);
414418
IRequiredComponentDescription[] descriptions = component.getRequiredComponents();
415419
boolean error = false;
416420
StringBuilder buffer = null;
@@ -438,6 +442,55 @@ public static void addAllRequired(IApiBaseline baseline, Set<String> done, IApiC
438442
}
439443
}
440444

445+
/**
446+
* If one of the components depend on declarative services, we also need to
447+
* add an implementation for that (if available).
448+
*/
449+
private static void addScrBundlesIfNecessary(IApiBaseline baseline, Set<String> done, IApiComponent component,
450+
List<IApiComponent> collection) throws CoreException {
451+
if (!done.contains("org.apache.felix.scr")) { //$NON-NLS-1$
452+
if (component instanceof BundleComponent bc) {
453+
for (BundleRequirement extenderRequirements : bc.getBundleDescription()
454+
.getDeclaredRequirements("osgi.extender")) { //$NON-NLS-1$
455+
456+
// Parsing the filter by hand is fragile, so just check
457+
// whether this a requirement that felix.scr can provide...
458+
File felixScrBundle = getBundle("org.apache.felix.scr"); //$NON-NLS-1$
459+
if (felixScrBundle != null) {
460+
IApiComponent felixScrComponent = ApiModelFactory.newApiComponent(baseline,
461+
felixScrBundle.getAbsolutePath());
462+
if (felixScrComponent instanceof BundleComponent felixBundleComponent) {
463+
for (BundleCapability capability : felixBundleComponent.getBundleDescription()
464+
.getDeclaredCapabilities("osgi.extender")) { //$NON-NLS-1$
465+
if (extenderRequirements.matches(capability)) {
466+
467+
// ... and if so, add felix.scr itself ...
468+
collection.add(felixScrComponent);
469+
done.add(felixScrComponent.getSymbolicName());
470+
471+
// ... and its depdencies.
472+
for (String bundleId : List.of("org.osgi.service.event", //$NON-NLS-1$
473+
"org.osgi.service.component", "org.osgi.util.promise", //$NON-NLS-1$ //$NON-NLS-2$
474+
"org.osgi.util.function")) { //$NON-NLS-1$
475+
File bundle = getBundle(bundleId);
476+
if (bundle != null) {
477+
IApiComponent scrComponent = ApiModelFactory.newApiComponent(baseline,
478+
bundle.getAbsolutePath());
479+
if (done.add(scrComponent.getSymbolicName())) {
480+
collection.add(scrComponent);
481+
}
482+
}
483+
}
484+
break;
485+
}
486+
}
487+
}
488+
}
489+
}
490+
}
491+
}
492+
}
493+
441494
/**
442495
* Compiles a single source file
443496
*

0 commit comments

Comments
 (0)