Skip to content

Commit 6be28fc

Browse files
committed
Add reproducer for cyclic bundle dependencies caused by #2218
1 parent 368feba commit 6be28fc

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/core/tests/internal/classpath/ClasspathResolutionTest.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2020, 2023 Red Hat Inc. and others.
2+
* Copyright (c) 2020, 2026 Red Hat Inc. and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -17,12 +17,19 @@
1717
import static org.assertj.core.api.Assertions.assertThat;
1818
import static org.junit.Assert.fail;
1919

20+
import java.io.ByteArrayOutputStream;
21+
import java.io.IOException;
22+
import java.io.InputStream;
2023
import java.util.Arrays;
2124
import java.util.List;
25+
import java.util.Map;
2226
import java.util.Properties;
2327
import java.util.Set;
2428
import java.util.function.Predicate;
29+
import java.util.jar.Attributes;
30+
import java.util.jar.Manifest;
2531

32+
import org.eclipse.core.resources.IFile;
2633
import org.eclipse.core.resources.IMarker;
2734
import org.eclipse.core.resources.IProject;
2835
import org.eclipse.core.resources.IResource;
@@ -49,6 +56,7 @@
4956
import org.junit.rules.TestRule;
5057
import org.mockito.Mockito;
5158
import org.osgi.framework.Bundle;
59+
import org.osgi.framework.Constants;
5260
import org.osgi.framework.FrameworkUtil;
5361

5462
public class ClasspathResolutionTest {
@@ -146,6 +154,22 @@ public void testImportSystemPackageDoesntAddExtraBundleJava8_osgiEERequirement()
146154
}
147155
}
148156

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+
149173
// --- utilitiy methods ---
150174

151175
private List<String> getRequiredPluginContainerEntries(IProject project) throws CoreException {
@@ -186,4 +210,22 @@ private AutoCloseable mockExtraExtraJRESystemPackages(String eeId, List<String>
186210
MinimalState.reloadSystemPackagesIntoState();
187211
};
188212
}
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+
}
189231
}

0 commit comments

Comments
 (0)