Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore check if a BundleComponent has explicitly declared its EE #1395

Merged
merged 4 commits into from
Sep 6, 2024
Merged
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
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.pde.api.tools.tests
Bundle-Version: 1.3.600.qualifier
Bundle-Version: 1.3.700.qualifier
Bundle-Vendor: %Bundle-Vendor
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.pde.api.tools;bundle-version="1.0.600",
Expand Down
2 changes: 1 addition & 1 deletion apitools/org.eclipse.pde.api.tools.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<relativePath>../../</relativePath>
</parent>
<artifactId>org.eclipse.pde.api.tools.tests</artifactId>
<version>1.3.600-SNAPSHOT</version>
<version>1.3.700-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
<defaultSigning-excludeInnerJars>true</defaultSigning-excludeInnerJars>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ protected static void exportApiComponent(IProject project, IApiComponent apiComp
}
// copy over .class files
IFolder output = project.getFolder("bin"); //$NON-NLS-1$
FileUtils.copyFolder(output, componentDir);
if (output.exists()) {
FileUtils.copyFolder(output, componentDir);
}
// copy description
Util.writeDocumentToFile(xml, componentDir.toPath().resolve(".api_description")); //$NON-NLS-1$
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
*******************************************************************************/
package org.eclipse.pde.api.tools.builder.tests.compatibility;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertArrayEquals;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
Expand Down Expand Up @@ -68,18 +69,25 @@ protected int getDefaultProblemId() {
}

/**
* Returns the type container associated with the given project in the
* workspace.
* Returns the component associated with the given project in the workspace.
*/
protected IApiTypeContainer getTypeContainer(String projectName) throws CoreException {
private IApiComponent getComponent(String projectName) {
IApiBaseline baseline = ApiBaselineManager.getManager().getWorkspaceBaseline();
assertNotNull("Missing workspace baseline", baseline); //$NON-NLS-1$
IApiComponent component = baseline.getApiComponent(getEnv().getProject(projectName));
assertNotNull("Missing API component", component); //$NON-NLS-1$
return component;
}

/**
* Returns the type container associated with the given project in the
* workspace.
*/
private IApiTypeContainer getTypeContainer(String projectName) throws CoreException {
IApiComponent component = getComponent(projectName);
IApiTypeContainer[] containers = component.getApiTypeContainers();
assertEquals("Wrong number of API type containers", 1, containers.length); //$NON-NLS-1$
IApiTypeContainer container = containers[0];
return container;
return containers[0];
}

protected IPackageFragment[] getAllPackages() throws CoreException {
Expand Down Expand Up @@ -162,13 +170,27 @@ protected Set<String> collectAllTypeNames() throws CoreException {
* {@code Require-Capability} header.
*/
public void testExecutionEnvironment() throws CoreException {
IApiTypeContainer bundleA = getTypeContainer("bundle.a"); //$NON-NLS-1$
IApiComponent bundleA = getComponent("bundle.a"); //$NON-NLS-1$
assertArrayEquals("Unable to find BREE for bundle using 'Bundle-RequiredExecutionEvironment'", //$NON-NLS-1$
new String[] { "JavaSE-1.8" }, bundleA.getApiComponent().getExecutionEnvironments()); //$NON-NLS-1$
new String[] { "JavaSE-1.8" }, bundleA.getExecutionEnvironments()); //$NON-NLS-1$

IApiTypeContainer bundleB = getTypeContainer("bundle.b"); //$NON-NLS-1$
IApiComponent bundleB = getComponent("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$
new String[] { "JavaSE-17" }, bundleB.getExecutionEnvironments()); //$NON-NLS-1$
}

/**
* Tests whether missing execution environments in the manifest are detected
* correctly.
*/
public void testNoExecutionEnvironment() throws CoreException {
// Verify that the test-project is an existing java project in order to
// ensure it gets the EE of the bound JDK injected (because it does not
// declare an EE in its Manifest).
assertTrue(JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getProject("bundle.c")).exists()); //$NON-NLS-1$
IApiComponent bundleC = getComponent("bundle.c"); //$NON-NLS-1$
assertArrayEquals("Expected no EE because none is specified in the Manifest", //$NON-NLS-1$
new String[] {}, bundleC.getExecutionEnvironments());
}

/**
Expand All @@ -178,23 +200,8 @@ public void testPackageNames() throws CoreException {
IApiTypeContainer container = getTypeContainer("bundle.a"); //$NON-NLS-1$
assertEquals("Should be a project type container", IApiTypeContainer.FOLDER, container.getContainerType()); //$NON-NLS-1$

// build expected list
Set<String> set = getAllPackageNames();

// assertEquals("Wrong number of package names", set.size(),
// names.length);
for (String name : container.getPackageNames()) {
set.remove(name);
}
if (!set.isEmpty()) {
System.out.println("LEFTOVERS"); //$NON-NLS-1$
Iterator<String> iterator = set.iterator();
while (iterator.hasNext()) {
String string = iterator.next();
System.out.println(string);
}
}
assertTrue("Missing/wrong packages in type container", set.isEmpty()); //$NON-NLS-1$
assertThat(container.getPackageNames()).withFailMessage("Missing/wrong packages in type container") //$NON-NLS-1$
.containsAll(getAllPackageNames());
}

/**
Expand Down Expand Up @@ -238,38 +245,10 @@ public void visit(String packageName, IApiTypeRoot typeroot) {
getTypeContainer("bundle.a").accept(visitor); //$NON-NLS-1$

// validate type names
Set<String> set = collectAllTypeNames();
Iterator<String> iterator = typeNames.iterator();
while (iterator.hasNext()) {
set.remove(iterator.next());
}
if (!set.isEmpty()) {
System.out.println("LEFTOVER TYPES"); //$NON-NLS-1$
Iterator<String> iterator2 = set.iterator();
while (iterator2.hasNext()) {
String string = iterator2.next();
System.out.println(string);
}
}
assertTrue("Missing/wrong types in type container", set.isEmpty()); //$NON-NLS-1$
assertThat(typeNames).containsAll(collectAllTypeNames());

// validate package names
// build expected list
set = getAllPackageNames();
iterator = pkgNames.iterator();
while (iterator.hasNext()) {
set.remove(iterator.next());
}
if (!set.isEmpty()) {
System.out.println("LEFTOVER PACKAGES"); //$NON-NLS-1$
Iterator<String> iterator2 = set.iterator();
while (iterator2.hasNext()) {
String string = iterator2.next();
System.out.println(string);
}
}
assertTrue("Missing/wrong packages in type container", set.isEmpty()); //$NON-NLS-1$

assertThat(pkgNames).containsAll(getAllPackageNames());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
Expand All @@ -23,6 +18,5 @@
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>bundle.b</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: API Tools Tests Plug-in C
Bundle-SymbolicName: bundle.c
Bundle-Version: 1.0.0
Export-Package: test
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeContainer;
import org.eclipse.pde.api.tools.internal.util.SourceDefaultHandler;
import org.eclipse.pde.api.tools.internal.util.Util;
import org.eclipse.pde.internal.core.MinimalState;
import org.eclipse.pde.internal.core.TargetWeaver;
import org.eclipse.pde.internal.core.util.ManifestUtils;
import org.osgi.framework.Bundle;
Expand Down Expand Up @@ -310,7 +311,9 @@ protected void init() throws CoreException {
BundleDescription bundleDescription = getBundleDescription(manifest, fLocation, fBundleId);
fSymbolicName = bundleDescription.getSymbolicName();
fVersion = bundleDescription.getVersion();
fdeclaredRequiredEE = ManifestUtils.getRequiredExecutionEnvironments(bundleDescription).toArray(String[]::new);
fdeclaredRequiredEE = MinimalState.hasDeclaredRequiredEE(manifest)
? ManifestUtils.getRequiredExecutionEnvironments(bundleDescription).toArray(String[]::new)
: new String[0];
setName(manifest.get(Constants.BUNDLE_NAME));
fBundleDescription = bundleDescription;
} catch (BundleException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private Map<String, String> loadWorkspaceBundleManifest(File bundleLocation, IRe
}

@SuppressWarnings("deprecation")
private boolean hasDeclaredRequiredEE(Map<String, String> manifest) {
public static boolean hasDeclaredRequiredEE(Map<String, String> manifest) {
if (manifest.containsKey(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT)) {
return true;
}
Expand Down
Loading