Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Läubrich2021-04-02 13:28:50 +0000
committerVikas Chandra2021-04-27 08:32:12 +0000
commitb5ca52322cdb7c91b49fca35800a2f3e21705a18 (patch)
tree6767b68effca54be6834ae92284a57adc0b92e90
parentdb1eda565488b8138f1c375eac844185677402f5 (diff)
downloadeclipse.pde.ui-b5ca52322cdb7c91b49fca35800a2f3e21705a18.tar.gz
eclipse.pde.ui-b5ca52322cdb7c91b49fca35800a2f3e21705a18.tar.xz
eclipse.pde.ui-b5ca52322cdb7c91b49fca35800a2f3e21705a18.zip
Bug 572520 - Run As > JUnit Plugin Test fails if the test is in aI20210428-0040I20210427-1800
source-folder marked as 'includes test sources' Change-Id: I55a3b8be13cb4e51f71f1b72251686808fd51a1e Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de> Reviewed-on: https://git.eclipse.org/r/c/pde/eclipse.pde.ui/+/178783 Reviewed-by: Vikas Chandra <Vikas.Chandra@in.ibm.com> Tested-by: Vikas Chandra <Vikas.Chandra@in.ibm.com>
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathHelper.java31
-rw-r--r--ui/org.eclipse.pde.junit.runtime.tests/META-INF/MANIFEST.MF2
-rw-r--r--ui/org.eclipse.pde.junit.runtime.tests/pom.xml2
-rw-r--r--ui/org.eclipse.pde.junit.runtime.tests/src/org/eclipse/pde/junit/runtime/tests/JUnitExecutionTest.java3
-rw-r--r--ui/org.eclipse.pde.junit.runtime.tests/test-bundles/.gitignore1
-rw-r--r--ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/.classpath16
-rw-r--r--ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/.project28
-rw-r--r--ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/META-INF/MANIFEST.MF8
-rw-r--r--ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/build.properties4
-rw-r--r--ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/src/verification/tests/testfolder/PlainClass.java19
-rw-r--r--ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/src_test/verification/tests/testfolder/Test1.java36
-rw-r--r--ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/src_test/verification/tests/testfolder/Test2.java25
-rw-r--r--ui/org.eclipse.pde.launching/src/org/eclipse/pde/launching/JUnitLaunchConfigurationDelegate.java26
14 files changed, 192 insertions, 16 deletions
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathHelper.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathHelper.java
index d68aef8430..db366e13c6 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathHelper.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathHelper.java
@@ -104,6 +104,12 @@ public class ClasspathHelper {
}
public static String getDevEntriesProperties(String fileName, Map<?, ?> map) {
+ @SuppressWarnings("unchecked")
+ Properties properties = getDevEntriesProperties((Map<?, IPluginModelBase>) map);
+ return writeDevEntries(fileName, properties);
+ }
+
+ public static String writeDevEntries(String fileName, Properties properties) {
File file = new File(fileName);
if (!file.exists()) {
File directory = file.getParentFile();
@@ -111,14 +117,25 @@ public class ClasspathHelper {
directory.mkdirs();
}
}
+ try (FileOutputStream stream = new FileOutputStream(fileName)) {
+ properties.store(stream, ""); //$NON-NLS-1$
+ stream.flush();
+ return new URL("file:" + fileName).toString(); //$NON-NLS-1$
+ } catch (IOException e) {
+ PDECore.logException(e);
+ }
+ return getDevEntries(true);
+ }
+
+ public static Properties getDevEntriesProperties(Map<?, IPluginModelBase> bundlesMap) {
Properties properties = new Properties();
// account for cascading workspaces
TargetWeaver.weaveDevProperties(properties);
- Iterator<?> iter = map.values().iterator();
+ Iterator<?> iter = bundlesMap.values().iterator();
while (iter.hasNext()) {
IPluginModelBase model = (IPluginModelBase) iter.next();
if (model.getUnderlyingResource() != null) {
- String entry = writeEntry(getDevPaths(model, true, map));
+ String entry = writeEntry(getDevPaths(model, true, bundlesMap));
if (entry.length() > 0) {
String id = model.getPluginBase().getId();
String currentValue = (String) properties.get(id);
@@ -132,15 +149,7 @@ public class ClasspathHelper {
}
}
properties.put("@ignoredot@", "true"); //$NON-NLS-1$ //$NON-NLS-2$
-
- try (FileOutputStream stream = new FileOutputStream(fileName)) {
- properties.store(stream, ""); //$NON-NLS-1$
- stream.flush();
- return new URL("file:" + fileName).toString(); //$NON-NLS-1$
- } catch (IOException e) {
- PDECore.logException(e);
- }
- return getDevEntries(true);
+ return properties;
}
private static String getDevEntries(boolean checkExcluded) {
diff --git a/ui/org.eclipse.pde.junit.runtime.tests/META-INF/MANIFEST.MF b/ui/org.eclipse.pde.junit.runtime.tests/META-INF/MANIFEST.MF
index bd2e84a871..ae4b24a620 100644
--- a/ui/org.eclipse.pde.junit.runtime.tests/META-INF/MANIFEST.MF
+++ b/ui/org.eclipse.pde.junit.runtime.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: PDE JUnit Runtime Tests
Bundle-SymbolicName: org.eclipse.pde.junit.runtime.tests;singleton:=true
-Bundle-Version: 3.6.200.qualifier
+Bundle-Version: 3.6.300.qualifier
Automatic-Module-Name: org.eclipse.pde.junit.runtime.tests
Bundle-RequiredExecutionEnvironment: JavaSE-11
Bundle-Vendor: Eclipse.org
diff --git a/ui/org.eclipse.pde.junit.runtime.tests/pom.xml b/ui/org.eclipse.pde.junit.runtime.tests/pom.xml
index c28ebe04fe..e988246ee4 100644
--- a/ui/org.eclipse.pde.junit.runtime.tests/pom.xml
+++ b/ui/org.eclipse.pde.junit.runtime.tests/pom.xml
@@ -25,7 +25,7 @@
</parent>
<groupId>org.eclipse.pde</groupId>
<artifactId>org.eclipse.pde.junit.runtime.tests</artifactId>
- <version>3.6.200-SNAPSHOT</version>
+ <version>3.6.300-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<build>
diff --git a/ui/org.eclipse.pde.junit.runtime.tests/src/org/eclipse/pde/junit/runtime/tests/JUnitExecutionTest.java b/ui/org.eclipse.pde.junit.runtime.tests/src/org/eclipse/pde/junit/runtime/tests/JUnitExecutionTest.java
index 8c13bd8542..6ba6059247 100644
--- a/ui/org.eclipse.pde.junit.runtime.tests/src/org/eclipse/pde/junit/runtime/tests/JUnitExecutionTest.java
+++ b/ui/org.eclipse.pde.junit.runtime.tests/src/org/eclipse/pde/junit/runtime/tests/JUnitExecutionTest.java
@@ -86,7 +86,8 @@ public class JUnitExecutionTest {
new TestInput("JUnit4 Fragment", "verification.tests.junit4.fragment"),
new TestInput("JUnit4 (JUnitPlatform)", "verification.tests.junit4.platform"),
new TestInput("JUnit4 (JUnitPlatform) Fragment", "verification.tests.junit4.platform.fragment"),
- new TestInput("Java 11 bundle with module limit", "verification.tests.limitmodules")
+ new TestInput("Java 11 bundle with module limit", "verification.tests.limitmodules"),
+ new TestInput("Using a 'test' source folder", "verification.tests.testfolder")
);
}
diff --git a/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/.gitignore b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/.gitignore
index e660fd93d3..ac0730160c 100644
--- a/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/.gitignore
+++ b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/.gitignore
@@ -1 +1,2 @@
bin/
+testbin/ \ No newline at end of file
diff --git a/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/.classpath b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/.classpath
new file mode 100644
index 0000000000..bb121dedb0
--- /dev/null
+++ b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/.classpath
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
+ <attributes>
+ <attribute name="module" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" output="testbin" path="src_test">
+ <attributes>
+ <attribute name="test" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/.project b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/.project
new file mode 100644
index 0000000000..ab18859afc
--- /dev/null
+++ b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>verification.tests.testfolder</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>
diff --git a/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/.settings/org.eclipse.jdt.core.prefs b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..0c68a61dca
--- /dev/null
+++ b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/META-INF/MANIFEST.MF b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..4463ad23aa
--- /dev/null
+++ b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/META-INF/MANIFEST.MF
@@ -0,0 +1,8 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Tests
+Bundle-SymbolicName: verification.tests.testfolder
+Bundle-Version: 1.0.0.qualifier
+Automatic-Module-Name: verification.tests
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Require-Bundle: org.junit;bundle-version="4.12.0"
diff --git a/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/build.properties b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/build.properties
new file mode 100644
index 0000000000..34d2e4d2da
--- /dev/null
+++ b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/src/verification/tests/testfolder/PlainClass.java b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/src/verification/tests/testfolder/PlainClass.java
new file mode 100644
index 0000000000..384c506c96
--- /dev/null
+++ b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/src/verification/tests/testfolder/PlainClass.java
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * Copyright (c) Christoph Läubrich
+ *
+ * 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:
+ * Christoph Läubrich - initial API and implementation
+ *******************************************************************************/
+
+package verification.tests.testfolder;
+
+public class PlainClass {
+
+}
diff --git a/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/src_test/verification/tests/testfolder/Test1.java b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/src_test/verification/tests/testfolder/Test1.java
new file mode 100644
index 0000000000..e5f8200c37
--- /dev/null
+++ b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/src_test/verification/tests/testfolder/Test1.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Julian Honnen
+ *
+ * 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:
+ * Julian Honnen <julian.honnen@vector.com> - initial API and implementation
+ *******************************************************************************/
+package verification.tests.testfolder;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class Test1 {
+
+ @Test
+ public void test1() {
+ try {
+ Thread.currentThread().getContextClassLoader().loadClass("doesnt.exist");
+ Assert.fail("ClassNotFoundException expected");
+ } catch (ClassNotFoundException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void test2() {
+ new PlainClass();
+ }
+
+}
diff --git a/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/src_test/verification/tests/testfolder/Test2.java b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/src_test/verification/tests/testfolder/Test2.java
new file mode 100644
index 0000000000..0c8f56512d
--- /dev/null
+++ b/ui/org.eclipse.pde.junit.runtime.tests/test-bundles/verification.tests.testfolder/src_test/verification/tests/testfolder/Test2.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Julian Honnen
+ *
+ * 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:
+ * Julian Honnen <julian.honnen@vector.com> - initial API and implementation
+ *******************************************************************************/
+package verification.tests.testfolder;
+
+import org.junit.Test;
+
+public class Test2 {
+
+ @Test
+ public void test() {
+
+ }
+
+}
diff --git a/ui/org.eclipse.pde.launching/src/org/eclipse/pde/launching/JUnitLaunchConfigurationDelegate.java b/ui/org.eclipse.pde.launching/src/org/eclipse/pde/launching/JUnitLaunchConfigurationDelegate.java
index a27beef085..1cd0d3a6f7 100644
--- a/ui/org.eclipse.pde.launching/src/org/eclipse/pde/launching/JUnitLaunchConfigurationDelegate.java
+++ b/ui/org.eclipse.pde.launching/src/org/eclipse/pde/launching/JUnitLaunchConfigurationDelegate.java
@@ -13,6 +13,7 @@
* EclipseSource Corporation - ongoing enhancements
* David Saff <saff@mit.edu> - bug 102632
* Ketan Padegaonkar <KetanPadegaonkar@gmail.com> - bug 250340
+ * Christoph Läubrich - Bug 572520 - Run As > JUnit Plugin Test fails if the test is in a source-folder marked as 'includes test sources'
*******************************************************************************/
package org.eclipse.pde.launching;
@@ -21,6 +22,7 @@ import java.util.*;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.*;
import org.eclipse.debug.core.*;
+import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.internal.junit.launcher.*;
import org.eclipse.jdt.launching.*;
@@ -141,6 +143,7 @@ public class JUnitLaunchConfigurationDelegate extends org.eclipse.jdt.junit.laun
// Create the platform configuration for the runtime workbench
String productID = LaunchConfigurationHelper.getProductID(configuration);
+ String testPluginId = getTestPluginId(configuration);
LaunchConfigurationHelper.createConfigIniFile(configuration, productID, fAllBundles, fModels, getConfigurationDirectory(configuration));
TargetPlatformHelper.checkPluginPropertiesConsistency(fAllBundles, getConfigurationDirectory(configuration));
@@ -149,7 +152,25 @@ public class JUnitLaunchConfigurationDelegate extends org.eclipse.jdt.junit.laun
// Specify the output folder names
programArgs.add("-dev"); //$NON-NLS-1$
- programArgs.add(ClasspathHelper.getDevEntriesProperties(getConfigurationDirectory(configuration).toString() + "/dev.properties", fAllBundles)); //$NON-NLS-1$
+
+ IJavaProject javaProject = getJavaProject(configuration);
+ Properties devProperties = ClasspathHelper.getDevEntriesProperties(fAllBundles);
+ if (javaProject != null) {
+ // source-folders of type "test" are omitted in the previous search so the need to be added here as they are part of the test but not part of the build.properties
+ Arrays.stream(javaProject.getRawClasspath())//
+ .filter(entry -> entry.getEntryKind() == IClasspathEntry.CPE_SOURCE)//
+ .filter(IClasspathEntry::isTest)//
+ .filter(entry -> entry.getOutputLocation() != null).forEach(entry -> {
+ IPath relativePath = entry.getOutputLocation().removeFirstSegments(1).makeRelative();
+ String currentProperty = devProperties.getProperty(testPluginId);
+ if (currentProperty == null) {
+ devProperties.setProperty(testPluginId, relativePath.toString());
+ } else {
+ devProperties.setProperty(testPluginId, currentProperty + "," + relativePath.toString()); //$NON-NLS-1$
+ }
+ });
+ }
+ programArgs.add(ClasspathHelper.writeDevEntries(getConfigurationDirectory(configuration).toString() + "/dev.properties", devProperties)); //$NON-NLS-1$
// Create the .options file if tracing is turned on
if (configuration.getAttribute(IPDELauncherConstants.TRACING, false) && !IPDELauncherConstants.TRACING_NONE.equals(configuration.getAttribute(IPDELauncherConstants.TRACING_CHECKED, (String) null))) {
@@ -184,7 +205,8 @@ public class JUnitLaunchConfigurationDelegate extends org.eclipse.jdt.junit.laun
}
programArgs.add("-testpluginname"); //$NON-NLS-1$
- programArgs.add(getTestPluginId(configuration));
+ programArgs.add(testPluginId);
+
IVMInstall launcher = VMHelper.createLauncher(configuration);
boolean isModular = JavaRuntime.isModularJava(launcher);
if (isModular) {

Back to the top