diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/classpathupdater/ClasspathUpdaterTest.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/classpathupdater/ClasspathUpdaterTest.java index 05faf376344..1166d6a93df 100644 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/classpathupdater/ClasspathUpdaterTest.java +++ b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/classpathupdater/ClasspathUpdaterTest.java @@ -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; @@ -32,6 +34,8 @@ 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 { @@ -39,6 +43,9 @@ public static void setUpBeforeClass() throws Exception { 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 @@ -46,8 +53,20 @@ 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); @@ -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(); @@ -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 sourceMap = Map.of( // "A.jar", IPath.fromOSString("library.jar"), // "library.jar", IPath.fromOSString("A.jar")); @@ -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 { diff --git a/ui/org.eclipse.pde.ui.tests/tests/projects/classpathupdater/.classpath b/ui/org.eclipse.pde.ui.tests/tests/projects/classpathupdater/.classpath index 5bccae7fc10..668576bd954 100644 --- a/ui/org.eclipse.pde.ui.tests/tests/projects/classpathupdater/.classpath +++ b/ui/org.eclipse.pde.ui.tests/tests/projects/classpathupdater/.classpath @@ -1,9 +1,10 @@ - + + diff --git a/ui/org.eclipse.pde.ui.tests/tests/projects/classpathupdater/build.properties b/ui/org.eclipse.pde.ui.tests/tests/projects/classpathupdater/build.properties index e7b9dc306f7..d5066b38263 100644 --- a/ui/org.eclipse.pde.ui.tests/tests/projects/classpathupdater/build.properties +++ b/ui/org.eclipse.pde.ui.tests/tests/projects/classpathupdater/build.properties @@ -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, \