Skip to content

Commit

Permalink
[FIXUP] check for test attribute being forced
Browse files Browse the repository at this point in the history
  • Loading branch information
haubi authored and HannesWell committed Sep 20, 2023
1 parent 9e42a61 commit 89c0491
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.PluginRegistry;
import org.eclipse.pde.internal.core.ClasspathComputer;
import org.eclipse.pde.internal.core.ICoreConstants;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.ui.wizards.tools.UpdateClasspathJob;
import org.eclipse.pde.ui.tests.util.ProjectUtils;
import org.junit.After;
Expand All @@ -32,22 +34,39 @@ public class ClasspathUpdaterTest {
private static IJavaProject jProject;

private static IClasspathEntry[] originalClasspath;
private static String originalTestPluginPattern;
private static Boolean expectIsTest;

@BeforeClass
public static void setUpBeforeClass() throws Exception {
project = ProjectUtils.importTestProject("tests/projects/classpathupdater");
assertTrue("Project was not created", project.exists());
jProject = JavaCore.create(project);
originalClasspath = jProject.getRawClasspath();
originalTestPluginPattern = PDECore.getDefault().getPreferencesManager()
.getString(ICoreConstants.TEST_PLUGIN_PATTERN);
expectIsTest = null;
}

@After
public void restoreOriginalClasspath() throws Exception {
jProject.setRawClasspath(originalClasspath, null);
}

@After
public void restoreOriginalTestPluginPattern() {
PDECore.getDefault().getPreferencesManager().setValue(ICoreConstants.TEST_PLUGIN_PATTERN,
originalTestPluginPattern);
expectIsTest = null;
}

private void setTestPluginPattern() {
PDECore.getDefault().getPreferencesManager().setValue(ICoreConstants.TEST_PLUGIN_PATTERN, project.getName());
expectIsTest = Boolean.TRUE;
}

@Test
public void testUpdateClasspath_PreserveAttributes() throws Exception {
public void test_PreserveAttributes() throws Exception {
runUpdateClasspathJob();
assertClasspathAttribute("JavaSE-17", IClasspathAttribute.MODULE, true, Boolean::valueOf);
assertClasspathAttribute("library.jar", IClasspathAttribute.TEST, true, Boolean::valueOf);
Expand All @@ -59,12 +78,22 @@ public void testUpdateClasspath_PreserveAttributes() throws Exception {
e -> "Asrc.zip".equals(nullOr(e.getSourceAttachmentPath(), IPath::lastSegment)));
assertClasspathProperty("src", "exported=false", e -> !e.isExported());
assertClasspathAttribute("src", IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS, true, Boolean::valueOf);
assertClasspathAttribute("src", IClasspathAttribute.TEST, true, Boolean::valueOf);
assertClasspathProperty("tests", "exported=false", e -> !e.isExported());
assertClasspathAttribute("tests", IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS, null, Boolean::valueOf);
assertClasspathAttribute("tests", IClasspathAttribute.TEST, expectIsTest, Boolean::valueOf);
assertClasspathOrder("A.jar", "src", "org.eclipse.pde.core.requiredPlugins", "JavaSE-17", "SOMEVAR",
"library.jar");
"library.jar", "tests");
}

@Test
public void test_PreserveAttributes_WithTestPluginName() throws Exception {
setTestPluginPattern();
test_PreserveAttributes();
}

@Test
public void testUpdateClasspath_CreateFromScratch() throws Exception {
public void test_CreateFromScratch() throws Exception {
jProject.setRawClasspath(new IClasspathEntry[0], null);

runUpdateClasspathJob();
Expand All @@ -76,11 +105,24 @@ public void testUpdateClasspath_CreateFromScratch() throws Exception {
assertClasspathProperty("A.jar", "exported=true", e -> e.isExported());
assertClasspathProperty("A.jar", "default source",
e -> "Asrc.zip".equals(nullOr(e.getSourceAttachmentPath(), IPath::lastSegment)));
assertClasspathOrder("JavaSE-17", "org.eclipse.pde.core.requiredPlugins", "library.jar", "A.jar");
assertClasspathProperty("src", "exported=false", e -> !e.isExported());
assertClasspathAttribute("src", IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS, null, Boolean::valueOf);
assertClasspathAttribute("src", IClasspathAttribute.TEST, expectIsTest, Boolean::valueOf);
assertClasspathProperty("tests", "exported=false", e -> !e.isExported());
assertClasspathAttribute("tests", IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS, null, Boolean::valueOf);
assertClasspathAttribute("tests", IClasspathAttribute.TEST, expectIsTest, Boolean::valueOf);
assertClasspathOrder("JavaSE-17", "org.eclipse.pde.core.requiredPlugins", "library.jar", "A.jar", "src",
"tests");
}

@Test
public void test_CreateFromScatch_WithTestPluginName() throws Exception {
setTestPluginPattern();
test_CreateFromScratch();
}

@Test
public void testClasspathComputer_ChangeSourceAttachment() throws Exception {
public void test_ChangeSourceAttachment() throws Exception {
Map<String, IPath> sourceMap = Map.of( //
"A.jar", IPath.fromOSString("library.jar"), //
"library.jar", IPath.fromOSString("A.jar"));
Expand All @@ -101,8 +143,18 @@ public void testClasspathComputer_ChangeSourceAttachment() throws Exception {
e -> "library.jar".equals(nullOr(e.getSourceAttachmentPath(), IPath::lastSegment)));
assertClasspathProperty("src", "exported=false", e -> !e.isExported());
assertClasspathAttribute("src", IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS, true, Boolean::valueOf);
assertClasspathAttribute("src", IClasspathAttribute.TEST, true, Boolean::valueOf);
assertClasspathProperty("tests", "exported=false", e -> !e.isExported());
assertClasspathAttribute("tests", IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS, null, Boolean::valueOf);
assertClasspathAttribute("tests", IClasspathAttribute.TEST, expectIsTest, Boolean::valueOf);
assertClasspathOrder("A.jar", "src", "org.eclipse.pde.core.requiredPlugins", "JavaSE-17", "SOMEVAR",
"library.jar");
"library.jar", "tests");
}

@Test
public void test_ChangeSourceAttachment_WithTestPluginName() throws Exception {
setTestPluginPattern();
test_ChangeSourceAttachment();
}

private void runUpdateClasspathJob() throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="lib" path="A.jar"/>
<classpathentry kind="src" path="src">
<classpathentry kind="src" output="testbin" path="src">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
# Contributors:
# IBM Corporation - initial API and implementation
###############################################################################
output.. = bin/
output.. = testbin/,\
bin/
source.. = src/,\
tests/
bin.includes = META-INF/,\
.,\
library.jar, \
Expand Down

0 comments on commit 89c0491

Please sign in to comment.