|
1 | 1 | /******************************************************************************* |
2 | | - * Copyright (c) 2020, 2023 Red Hat Inc. and others. |
| 2 | + * Copyright (c) 2020, 2026 Red Hat Inc. and others. |
3 | 3 | * |
4 | 4 | * This program and the accompanying materials |
5 | 5 | * are made available under the terms of the Eclipse Public License 2.0 |
|
17 | 17 | import static org.assertj.core.api.Assertions.assertThat; |
18 | 18 | import static org.junit.Assert.fail; |
19 | 19 |
|
| 20 | +import java.io.ByteArrayOutputStream; |
| 21 | +import java.io.IOException; |
| 22 | +import java.io.InputStream; |
20 | 23 | import java.util.Arrays; |
21 | 24 | import java.util.List; |
| 25 | +import java.util.Map; |
22 | 26 | import java.util.Properties; |
23 | 27 | import java.util.Set; |
24 | 28 | import java.util.function.Predicate; |
| 29 | +import java.util.jar.Attributes; |
| 30 | +import java.util.jar.Manifest; |
25 | 31 |
|
| 32 | +import org.eclipse.core.resources.IFile; |
26 | 33 | import org.eclipse.core.resources.IMarker; |
27 | 34 | import org.eclipse.core.resources.IProject; |
28 | 35 | import org.eclipse.core.resources.IResource; |
|
49 | 56 | import org.junit.rules.TestRule; |
50 | 57 | import org.mockito.Mockito; |
51 | 58 | import org.osgi.framework.Bundle; |
| 59 | +import org.osgi.framework.Constants; |
52 | 60 | import org.osgi.framework.FrameworkUtil; |
53 | 61 |
|
54 | 62 | public class ClasspathResolutionTest { |
@@ -146,6 +154,22 @@ public void testImportSystemPackageDoesntAddExtraBundleJava8_osgiEERequirement() |
146 | 154 | } |
147 | 155 | } |
148 | 156 |
|
| 157 | + @Test |
| 158 | + public void testRequiredPluginsForFragment() throws IOException, CoreException { |
| 159 | + IProject projectA = ProjectUtils.createPluginProject("A", "1.0.0"); |
| 160 | + IProject projectConsumer = ProjectUtils.createPluginProject("capabilities.consumer", "1.0.0"); |
| 161 | + IProject projectProvider = ProjectUtils.createPluginProject("capabilities.provider", "1.0.0"); |
| 162 | + |
| 163 | + updateManifest(projectConsumer, |
| 164 | + Map.of(Constants.REQUIRE_CAPABILITY, "some.test.capability", Constants.FRAGMENT_HOST, "A")); |
| 165 | + updateManifest(projectProvider, |
| 166 | + Map.of(Constants.PROVIDE_CAPABILITY, "some.test.capability", Constants.REQUIRE_BUNDLE, "A")); |
| 167 | + |
| 168 | + assertThat(getRequiredPluginContainerEntries(projectA)).isEmpty(); |
| 169 | + assertThat(getRequiredPluginContainerEntries(projectConsumer)).containsExactlyInAnyOrder("A1_0_0"); |
| 170 | + assertThat(getRequiredPluginContainerEntries(projectProvider)).containsExactlyInAnyOrder("A1_0_0"); |
| 171 | + } |
| 172 | + |
149 | 173 | // --- utilitiy methods --- |
150 | 174 |
|
151 | 175 | private List<String> getRequiredPluginContainerEntries(IProject project) throws CoreException { |
@@ -186,4 +210,22 @@ private AutoCloseable mockExtraExtraJRESystemPackages(String eeId, List<String> |
186 | 210 | MinimalState.reloadSystemPackagesIntoState(); |
187 | 211 | }; |
188 | 212 | } |
| 213 | + |
| 214 | + private void updateManifest(IProject project, Map<String, String> headers) throws IOException, CoreException { |
| 215 | + IFile manifestFile = project.getFile("META-INF/MANIFEST.MF"); |
| 216 | + |
| 217 | + Manifest manifest; |
| 218 | + try (InputStream is = manifestFile.getContents()) { |
| 219 | + manifest = new Manifest(is); |
| 220 | + } |
| 221 | + |
| 222 | + Attributes attributes = new Attributes(); |
| 223 | + headers.forEach(attributes::putValue); |
| 224 | + manifest.getMainAttributes().putAll(attributes); |
| 225 | + |
| 226 | + try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { |
| 227 | + manifest.write(os); |
| 228 | + manifestFile.setContents(os.toByteArray(), IResource.FORCE, null); |
| 229 | + } |
| 230 | + } |
189 | 231 | } |
0 commit comments