Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2023 Red Hat Inc. and others.
* Copyright (c) 2020, 2026 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -19,6 +19,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.function.Predicate;
Expand All @@ -40,6 +41,7 @@
import org.eclipse.pde.internal.core.MinimalState;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.TargetPlatformHelper;
import org.eclipse.pde.ui.tests.runtime.TestUtils;
import org.eclipse.pde.ui.tests.util.ProjectUtils;
import org.eclipse.pde.ui.tests.util.TargetPlatformUtil;
import org.junit.BeforeClass;
Expand All @@ -49,6 +51,7 @@
import org.junit.rules.TestRule;
import org.mockito.Mockito;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.FrameworkUtil;

public class ClasspathResolutionTest {
Expand Down Expand Up @@ -146,6 +149,21 @@ public void testImportSystemPackageDoesntAddExtraBundleJava8_osgiEERequirement()
}
}

@Test
public void testRequiredPluginsViaCapabilityForFragment() throws CoreException {
ProjectUtils.createPluginProject("A", "1.0.0");
ProjectUtils.createPluginProject("capabilities.provider", "1.0.0",
Map.of(Constants.PROVIDE_CAPABILITY, "some.test.capability", Constants.REQUIRE_BUNDLE, "A"));
IProject projectConsumer = ProjectUtils.createPluginProject("capabilities.consumer", "1.0.0",
Map.of(Constants.REQUIRE_CAPABILITY, "some.test.capability", Constants.FRAGMENT_HOST, "A"));

TestUtils.waitForJobs("ClasspathResolutionTest.testRequiredPluginsViaCapabilityForFragment", 200, 30_000);

List<String> requiredPluginContainers = getRequiredPluginContainerEntries(projectConsumer);
assertThat(requiredPluginContainers).contains("A1_0_0");
assertThat(requiredPluginContainers).noneMatch(containerName -> containerName.contains("capabilities.provider"));
}

// --- utilitiy methods ---

private List<String> getRequiredPluginContainerEntries(IProject project) throws CoreException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2022 IBM Corporation and others.
* Copyright (c) 2008, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -217,6 +217,9 @@ public static IProject createPluginProject(String bundleSymbolicName, String ver
case Constants.EXPORT_PACKAGE -> setPackageExports(description, projectService, value);
case Constants.IMPORT_PACKAGE -> setPackageImports(description, projectService, value);
case Constants.REQUIRE_BUNDLE -> setRequiredBundles(description, projectService, value);
case Constants.FRAGMENT_HOST -> setFragmentHost(description, projectService, value);
case Constants.REQUIRE_CAPABILITY -> setRequiredCapability(description, projectService, value);
case Constants.PROVIDE_CAPABILITY -> setProvidedCapability(description, projectService, value);
default -> throw new IllegalArgumentException("Unsupported header: " + header);
}
});
Expand Down Expand Up @@ -256,6 +259,26 @@ private static void setRequiredBundles(IBundleProjectDescription project, IBundl
project.setRequiredBundles(imports);
}

private static void setFragmentHost(IBundleProjectDescription project, IBundleProjectService projectService,
String value) {
var host = parseHeader(Constants.REQUIRE_BUNDLE, value, h -> {
VersionRange bundleVersion = Optional.ofNullable(h.getAttribute(Constants.BUNDLE_VERSION))
.map(VersionRange::valueOf).orElse(null);
return projectService.newHost(h.getValue(), bundleVersion);
}).findFirst().orElse(null);
project.setHost(host);
}

private static void setRequiredCapability(IBundleProjectDescription project, IBundleProjectService projectService,
String value) {
project.setHeader(Constants.REQUIRE_CAPABILITY, value);
}

private static void setProvidedCapability(IBundleProjectDescription project, IBundleProjectService projectService,
String value) {
project.setHeader(Constants.PROVIDE_CAPABILITY, value);
}

private static <T> Stream<T> parseHeader(String header, String value, Function<ManifestElement, T> parser) {
try {
return Arrays.stream(ManifestElement.parseHeader(header, value)).map(parser);
Expand Down
Loading