diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/compatibility/ProjectTypeContainerTests.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/compatibility/ProjectTypeContainerTests.java index 0d21ef95b1d..c91e26b026b 100644 --- a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/compatibility/ProjectTypeContainerTests.java +++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/compatibility/ProjectTypeContainerTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 IBM Corporation and others. + * Copyright (c) 2009, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,7 +13,10 @@ *******************************************************************************/ package org.eclipse.pde.api.tools.builder.tests.compatibility; +import static org.junit.Assert.assertArrayEquals; + import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -66,13 +69,13 @@ protected int getDefaultProblemId() { } /** - * Returns the type container associated with the "bundle.a" project in the + * Returns the type container associated with the given project in the * workspace. */ - protected IApiTypeContainer getTypeContainer() throws CoreException { + protected IApiTypeContainer getTypeContainer(String projectName) throws CoreException { IApiBaseline baseline = ApiBaselineManager.getManager().getWorkspaceBaseline(); assertNotNull("Missing workspace baseline", baseline); //$NON-NLS-1$ - IApiComponent component = baseline.getApiComponent(getEnv().getProject("bundle.a")); //$NON-NLS-1$ + IApiComponent component = baseline.getApiComponent(getEnv().getProject(projectName)); assertNotNull("Missing API component", component); //$NON-NLS-1$ IApiTypeContainer[] containers = component.getApiTypeContainers(); assertEquals("Wrong number of API type containers", 1, containers.length); //$NON-NLS-1$ @@ -154,11 +157,29 @@ protected Set collectAllTypeNames() throws CoreException { return names; } + /** + * Tests whether the execution environment can be extracted from both the + * {@code Bundle-RequiredExecutionEnvironment} and the + * {@code Require-Capability} header. + * + * @throws CoreException + */ + public void testExecutionEnvironment() throws CoreException { + IApiTypeContainer bundleA = getTypeContainer("bundle.a"); //$NON-NLS-1$ + assertArrayEquals("Unable to find BREE for bundle using 'Bundle-RequiredExecutionEvironment'", //$NON-NLS-1$ + new String[] { "J2SE-1.5" }, bundleA.getApiComponent().getExecutionEnvironments()); //$NON-NLS-1$ + + IApiTypeContainer bundleB = getTypeContainer("bundle.b"); //$NON-NLS-1$ + assertArrayEquals("Unable to find BREE for bundle using 'Require-Capability'", //$NON-NLS-1$ + new String[] { "JavaSE-17" }, bundleB.getApiComponent().getExecutionEnvironments()); //$NON-NLS-1$ + } + /** * Tests all packages are returned. */ public void testPackageNames() throws CoreException { - IApiTypeContainer container = getTypeContainer(); + IApiTypeContainer container = getTypeContainer("bundle.a"); //$NON-NLS-1$ + System.out.println(Arrays.asList(container.getApiComponent().getExecutionEnvironments())); assertEquals("Should be a project type container", IApiTypeContainer.FOLDER, container.getContainerType()); //$NON-NLS-1$ // build expected list @@ -184,7 +205,7 @@ public void testPackageNames() throws CoreException { * Test type lookup. */ public void testFindType() throws CoreException { - IApiTypeContainer container = getTypeContainer(); + IApiTypeContainer container = getTypeContainer("bundle.a"); //$NON-NLS-1$ IApiTypeRoot root = container.findTypeRoot("a.classes.fields.AddPrivateField"); //$NON-NLS-1$ assertNotNull("Unable to find type 'a.classes.fields.AddPrivateField'", root); //$NON-NLS-1$ IApiType structure = root.getStructure(); @@ -195,7 +216,7 @@ public void testFindType() throws CoreException { * Test that type lookup fails for a type that is not in the project. */ public void testMissingType() throws CoreException { - IApiTypeContainer container = getTypeContainer(); + IApiTypeContainer container = getTypeContainer("bundle.a"); //$NON-NLS-1$ IApiTypeRoot root = container.findTypeRoot("some.bogus.Type"); //$NON-NLS-1$ assertNull("Should not be able to find type 'some.bogus.Type'", root); //$NON-NLS-1$ } @@ -218,7 +239,7 @@ public void visit(String packageName, IApiTypeRoot typeroot) { typeNames.add(typeroot.getTypeName()); } }; - getTypeContainer().accept(visitor); + getTypeContainer("bundle.a").accept(visitor); //$NON-NLS-1$ // validate type names Set set = collectAllTypeNames(); diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/baseline/bundle.b/META-INF/MANIFEST.MF b/apitools/org.eclipse.pde.api.tools.tests/test-builder/baseline/bundle.b/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..b104eba7601 --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/baseline/bundle.b/META-INF/MANIFEST.MF @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: API Tools Tests Plug-in B +Bundle-SymbolicName: bundle.b +Bundle-Version: 1.0.0 +Require-Capability=osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=17))" \ No newline at end of file diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/baseline/bundle.b/build.properties b/apitools/org.eclipse.pde.api.tools.tests/test-builder/baseline/bundle.b/build.properties new file mode 100644 index 00000000000..ded642cf84e --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/baseline/bundle.b/build.properties @@ -0,0 +1,17 @@ +############################################################################### +# Copyright (c) 2008 IBM Corporation and others. +# +# This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .