Skip to content

Commit

Permalink
Clean-up ProjectTypeContainerTests and simplify its resources
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Sep 6, 2024
1 parent 0953a33 commit 1b87cbf
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 77 deletions.
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,11 +13,11 @@
*******************************************************************************/
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;

Expand Down Expand Up @@ -68,18 +68,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 +169,13 @@ 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$
}

/**
Expand All @@ -178,23 +185,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 +230,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());
}

}

This file was deleted.

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.

This file was deleted.

0 comments on commit 1b87cbf

Please sign in to comment.