|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2020, 2026 Red Hat Inc. and others. |
| 3 | + * |
| 4 | + * This program and the accompanying materials |
| 5 | + * are made available under the terms of the Eclipse Public License 2.0 |
| 6 | + * which accompanies this distribution, and is available at |
| 7 | + * https://www.eclipse.org/legal/epl-2.0/ |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: EPL-2.0 |
| 10 | + * |
| 11 | + * Contributors: |
| 12 | + * Mickael Istria - initial API and implementation |
| 13 | + * Hannes Wellmann - Bug 577116: Improve test utility method reusability |
| 14 | + *******************************************************************************/ |
| 15 | +package org.eclipse.pde.core.tests.internal.classpath; |
| 16 | + |
| 17 | +import static org.assertj.core.api.Assertions.assertThat; |
| 18 | + |
| 19 | +import java.util.Arrays; |
| 20 | +import java.util.List; |
| 21 | +import java.util.Map; |
| 22 | + |
| 23 | +import org.eclipse.core.resources.IProject; |
| 24 | +import org.eclipse.core.resources.IncrementalProjectBuilder; |
| 25 | +import org.eclipse.core.runtime.CoreException; |
| 26 | +import org.eclipse.core.runtime.IPath; |
| 27 | +import org.eclipse.core.runtime.NullProgressMonitor; |
| 28 | +import org.eclipse.jdt.core.IClasspathEntry; |
| 29 | +import org.eclipse.pde.core.plugin.IPluginModelBase; |
| 30 | +import org.eclipse.pde.internal.core.ClasspathComputer; |
| 31 | +import org.eclipse.pde.internal.core.PDECore; |
| 32 | +import org.eclipse.pde.ui.tests.runtime.TestUtils; |
| 33 | +import org.eclipse.pde.ui.tests.util.ProjectUtils; |
| 34 | +import org.junit.ClassRule; |
| 35 | +import org.junit.Rule; |
| 36 | +import org.junit.Test; |
| 37 | +import org.junit.rules.TestRule; |
| 38 | +import org.osgi.framework.Constants; |
| 39 | + |
| 40 | +public class ClasspathResolutionTest3 { |
| 41 | + |
| 42 | + @ClassRule |
| 43 | + public static final TestRule CLEAR_WORKSPACE = ProjectUtils.DELETE_ALL_WORKSPACE_PROJECTS_BEFORE_AND_AFTER; |
| 44 | + @Rule |
| 45 | + public final TestRule deleteCreatedTestProjectsAfter = ProjectUtils.DELETE_CREATED_WORKSPACE_PROJECTS_AFTER; |
| 46 | + |
| 47 | + @Test |
| 48 | + public void testRequiredPluginsViaCapabilityForFragment() throws CoreException { |
| 49 | + ProjectUtils.createPluginProject("A", "1.0.0"); |
| 50 | + ProjectUtils.createPluginProject("capabilities.provider", "1.0.0", |
| 51 | + Map.of(Constants.PROVIDE_CAPABILITY, "some.test.capability", Constants.REQUIRE_BUNDLE, "A")); |
| 52 | + IProject projectConsumer = ProjectUtils.createPluginProject("capabilities.consumer", "1.0.0", |
| 53 | + Map.of(Constants.REQUIRE_CAPABILITY, "some.test.capability", Constants.FRAGMENT_HOST, "A")); |
| 54 | + |
| 55 | + TestUtils.waitForJobs("ClasspathResolutionTest.testRequiredPluginsViaCapabilityForFragment", 200, 30_000); |
| 56 | + |
| 57 | + List<String> requiredPluginContainers = getRequiredPluginContainerEntries(projectConsumer); |
| 58 | + assertThat(requiredPluginContainers).contains("A1_0_0"); |
| 59 | + assertThat(requiredPluginContainers).noneMatch(containerName -> containerName.contains("capabilities.provider")); |
| 60 | + } |
| 61 | + |
| 62 | + // --- utilitiy methods --- |
| 63 | + |
| 64 | + private List<String> getRequiredPluginContainerEntries(IProject project) throws CoreException { |
| 65 | + project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); |
| 66 | + IPluginModelBase model = PDECore.getDefault().getModelManager().findModel(project); |
| 67 | + return Arrays.stream(ClasspathComputer.computeClasspathEntries(model, project)).map(IClasspathEntry::getPath) |
| 68 | + .map(IPath::lastSegment).toList(); |
| 69 | + } |
| 70 | + |
| 71 | +} |
0 commit comments