Skip to content

Commit 1121eb8

Browse files
committed
Support 'Require-Bundle' header in ProjectUtils.createPluginProject()
1 parent 633b9ac commit 1121eb8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/util/ProjectUtils.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.eclipse.pde.core.project.IBundleProjectService;
4949
import org.eclipse.pde.core.project.IPackageExportDescription;
5050
import org.eclipse.pde.core.project.IPackageImportDescription;
51+
import org.eclipse.pde.core.project.IRequiredBundleDescription;
5152
import org.eclipse.pde.core.target.NameVersionDescriptor;
5253
import org.eclipse.pde.internal.core.FeatureModelManager;
5354
import org.eclipse.pde.internal.core.PDECore;
@@ -215,6 +216,7 @@ public static IProject createPluginProject(String bundleSymbolicName, String ver
215216
switch (header) {
216217
case Constants.EXPORT_PACKAGE -> setPackageExports(description, projectService, value);
217218
case Constants.IMPORT_PACKAGE -> setPackageImports(description, projectService, value);
219+
case Constants.REQUIRE_BUNDLE -> setRequiredBundles(description, projectService, value);
218220
default -> throw new IllegalArgumentException("Unsupported header: " + header);
219221
}
220222
});
@@ -242,6 +244,18 @@ private static void setPackageImports(IBundleProjectDescription project, IBundle
242244
project.setPackageImports(imports);
243245
}
244246

247+
private static void setRequiredBundles(IBundleProjectDescription project, IBundleProjectService projectService,
248+
String value) {
249+
var imports = parseHeader(Constants.REQUIRE_BUNDLE, value, h -> {
250+
VersionRange bundleVersion = Optional.ofNullable(h.getAttribute(Constants.BUNDLE_VERSION))
251+
.map(VersionRange::valueOf).orElse(null);
252+
boolean optional = Constants.RESOLUTION_OPTIONAL.equals(h.getDirective(Constants.RESOLUTION_DIRECTIVE));
253+
boolean reexport = Constants.VISIBILITY_REEXPORT.equals(h.getDirective(Constants.VISIBILITY_DIRECTIVE));
254+
return projectService.newRequiredBundle(h.getValue(), bundleVersion, optional, reexport);
255+
}).toArray(IRequiredBundleDescription[]::new);
256+
project.setRequiredBundles(imports);
257+
}
258+
245259
private static <T> Stream<T> parseHeader(String header, String value, Function<ManifestElement, T> parser) {
246260
try {
247261
return Arrays.stream(ManifestElement.parseHeader(header, value)).map(parser);

0 commit comments

Comments
 (0)