-
Notifications
You must be signed in to change notification settings - Fork 146
Experiment with the new JUnit-Platform Mojo #2197
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
Draft
laeubi
wants to merge
2
commits into
eclipse-platform:master
Choose a base branch
from
laeubi:junit_platform_experiment
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+437
−2
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?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-21"/> | ||
| <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
| <classpathentry kind="src" path="src"/> | ||
| <classpathentry kind="output" path="bin"/> | ||
| </classpath> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <projectDescription> | ||
| <name>org.eclipse.platform.testing</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> | ||
| <buildCommand> | ||
| <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name> | ||
| <arguments> | ||
| </arguments> | ||
| </buildCommand> | ||
| </buildSpec> | ||
| <natures> | ||
| <nature>org.eclipse.pde.PluginNature</nature> | ||
| <nature>org.eclipse.jdt.core.javanature</nature> | ||
| <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature> | ||
| </natures> | ||
| </projectDescription> |
11 changes: 11 additions & 0 deletions
11
platform/org.eclipse.platform.testing/.settings/.api_filters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
| <component id="org.eclipse.platform.testing" version="2"> | ||
| <resource path="src/org/eclipse/platform/testing/EclipseApplicationLauncher.java" type="org.eclipse.platform.testing.EclipseApplicationLauncher"> | ||
| <filter id="574619656"> | ||
| <message_arguments> | ||
| <message_argument value="ApplicationLauncher"/> | ||
| <message_argument value="EclipseApplicationLauncher"/> | ||
| </message_arguments> | ||
| </filter> | ||
| </resource> | ||
| </component> |
2 changes: 2 additions & 0 deletions
2
platform/org.eclipse.platform.testing/.settings/org.eclipse.core.resources.prefs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| eclipse.preferences.version=1 | ||
| encoding/<project>=UTF-8 |
9 changes: 9 additions & 0 deletions
9
platform/org.eclipse.platform.testing/.settings/org.eclipse.jdt.core.prefs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| eclipse.preferences.version=1 | ||
| org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 | ||
| org.eclipse.jdt.core.compiler.compliance=21 | ||
| org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
| org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | ||
| org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
| org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning | ||
| org.eclipse.jdt.core.compiler.release=enabled | ||
| org.eclipse.jdt.core.compiler.source=21 |
4 changes: 4 additions & 0 deletions
4
platform/org.eclipse.platform.testing/.settings/org.eclipse.pde.core.prefs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| eclipse.preferences.version=1 | ||
| pluginProject.equinox=false | ||
| pluginProject.extensions=false | ||
| resolve.requirebundle=false |
17 changes: 17 additions & 0 deletions
17
platform/org.eclipse.platform.testing/META-INF/MANIFEST.MF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| Manifest-Version: 1.0 | ||
| Bundle-ManifestVersion: 2 | ||
| Bundle-Name: Testing Support for Eclipse Applications | ||
| Bundle-SymbolicName: org.eclipse.platform.testing | ||
| Bundle-Version: 1.0.0.qualifier | ||
| Automatic-Module-Name: org.eclipse.platform.testing | ||
| Bundle-ActivationPolicy: lazy | ||
| Bundle-RequiredExecutionEnvironment: JavaSE-21 | ||
| Import-Package: org.eclipse.osgi.service.runnable;version="[1.1.0,2.0.0)", | ||
| org.junit.jupiter.api.extension;version="[5.14.0,6.0.0)", | ||
| org.junit.platform.launcher;version="[1.14.0,2.0.0)", | ||
| org.osgi.framework;version="[1.10.0,2.0.0)", | ||
| org.osgi.util.tracker;version="[1.5.0,2.0.0)" | ||
| Require-Bundle: org.eclipse.equinox.common;bundle-version="3.20.300", | ||
| org.eclipse.e4.ui.workbench3, | ||
| org.eclipse.equinox.app | ||
| Export-Package: org.eclipse.platform.testing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| source.. = src/ | ||
| output.. = bin/ | ||
| bin.includes = META-INF/,\ | ||
| . | ||
| tycho.pomless.parent = ../../ |
1 change: 1 addition & 0 deletions
1
....eclipse.platform.testing/src/META-INF/services/org.junit.jupiter.api.extension.Extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| org.eclipse.platform.testing.EclipseInvocationInterceptor |
1 change: 1 addition & 0 deletions
1
...latform.testing/src/META-INF/services/org.junit.platform.launcher.LauncherSessionListener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| org.eclipse.platform.testing.EclipseLauncherSessionListener |
31 changes: 31 additions & 0 deletions
31
...eclipse.platform.testing/src/org/eclipse/platform/testing/EclipseApplicationLauncher.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025 Christoph Läubrich and others. | ||
| * | ||
| * 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 org.eclipse.platform.testing; | ||
|
|
||
| import org.eclipse.osgi.service.runnable.ApplicationLauncher; | ||
| import org.eclipse.osgi.service.runnable.ParameterizedRunnable; | ||
|
|
||
| class EclipseApplicationLauncher implements ApplicationLauncher { | ||
|
|
||
| @Override | ||
| public void launch(ParameterizedRunnable runnable, Object context) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void shutdown() { | ||
|
|
||
| } | ||
|
|
||
| } |
81 changes: 81 additions & 0 deletions
81
...lipse.platform.testing/src/org/eclipse/platform/testing/EclipseInvocationInterceptor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025 Christoph Läubrich and others. | ||
| * | ||
| * 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 org.eclipse.platform.testing; | ||
|
|
||
| import java.lang.reflect.Method; | ||
|
|
||
| import org.eclipse.pde.api.tools.annotations.NoInstantiate; | ||
| import org.eclipse.pde.api.tools.annotations.NoReference; | ||
| import org.eclipse.ui.testing.TestableObject; | ||
| import org.junit.jupiter.api.extension.ExtensionContext; | ||
| import org.junit.jupiter.api.extension.InvocationInterceptor; | ||
| import org.junit.jupiter.api.extension.ReflectiveInvocationContext; | ||
| import org.osgi.framework.Bundle; | ||
| import org.osgi.framework.BundleContext; | ||
| import org.osgi.framework.FrameworkUtil; | ||
| import org.osgi.util.tracker.ServiceTracker; | ||
|
|
||
| /** | ||
| * An {@link InvocationInterceptor} that executes all tests inside the | ||
| * {@link TestableObject#runTest(Runnable)} method. | ||
| */ | ||
| @NoInstantiate | ||
| public class EclipseInvocationInterceptor implements InvocationInterceptor { | ||
|
|
||
| private final ServiceTracker<TestableObject, TestableObject> testableObjectTracker; | ||
| private final TestableObject testableObject; | ||
|
|
||
| /** | ||
| * Creates the extension, will be called by JUnit | ||
| */ | ||
| public EclipseInvocationInterceptor() { | ||
| Bundle bundle = FrameworkUtil.getBundle(EclipseLauncherSessionListener.class); | ||
| if (bundle == null) { | ||
| throw new IllegalStateException("Not running inside an OSGi Framework"); | ||
| } | ||
| BundleContext bundleContext = bundle.getBundleContext(); | ||
| if (bundleContext == null) { | ||
| throw new IllegalStateException("Extension Bundle not started"); | ||
| } | ||
| testableObjectTracker = new ServiceTracker<>(bundleContext, TestableObject.class, null); | ||
| testableObjectTracker.open(); | ||
| testableObject = testableObjectTracker.getService(); | ||
| if (testableObject == null) { | ||
| throw new IllegalStateException("Testable Object not found!"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| @NoReference | ||
| public void interceptTestMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, | ||
| ExtensionContext extensionContext) throws Throwable { | ||
| Throwable[] throwable = new Throwable[1]; | ||
| TestableObject service = testableObjectTracker.getService(); | ||
| if (service != null) { | ||
| service.runTest(() -> { | ||
| try { | ||
| invocation.proceed(); | ||
| } catch (Throwable e) { | ||
| throwable[0] = e; | ||
| } | ||
| }); | ||
| Throwable t = throwable[0]; | ||
| if (t == null) { | ||
| return; | ||
| } | ||
| throw t; | ||
| } | ||
| } | ||
|
|
||
| } |
141 changes: 141 additions & 0 deletions
141
...pse.platform.testing/src/org/eclipse/platform/testing/EclipseLauncherSessionListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| package org.eclipse.platform.testing; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import org.eclipse.equinox.app.IApplicationContext; | ||
| import org.eclipse.osgi.service.runnable.ApplicationLauncher; | ||
| import org.eclipse.osgi.service.runnable.ParameterizedRunnable; | ||
| import org.eclipse.pde.api.tools.annotations.NoInstantiate; | ||
| import org.eclipse.pde.api.tools.annotations.NoReference; | ||
| import org.eclipse.ui.testing.ITestHarness; | ||
| import org.eclipse.ui.testing.TestableObject; | ||
| import org.junit.platform.launcher.LauncherSession; | ||
| import org.junit.platform.launcher.LauncherSessionListener; | ||
| import org.osgi.framework.Bundle; | ||
| import org.osgi.framework.BundleContext; | ||
| import org.osgi.framework.FrameworkUtil; | ||
| import org.osgi.framework.ServiceRegistration; | ||
| import org.osgi.service.application.ApplicationDescriptor; | ||
| import org.osgi.service.application.ApplicationException; | ||
| import org.osgi.service.application.ApplicationHandle; | ||
| import org.osgi.util.tracker.ServiceTracker; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| @NoInstantiate | ||
| public class EclipseLauncherSessionListener implements LauncherSessionListener { | ||
|
|
||
| private TestableObject testableObject; | ||
| private ApplicationHandle applicationHandle; | ||
| private ServiceTracker<TestableObject, TestableObject> testableObjectTracker; | ||
| private ServiceTracker<ApplicationDescriptor, ApplicationDescriptor> applicationDescriptorTracker; | ||
| private ServiceRegistration<?> applicationService; | ||
| private Thread applicationThread; | ||
|
|
||
|
|
||
| @Override | ||
| @NoReference | ||
| public void launcherSessionOpened(LauncherSession session) { | ||
| Bundle bundle = FrameworkUtil.getBundle(EclipseLauncherSessionListener.class); | ||
| if (bundle == null) { | ||
| System.err.println("Not running inside OSGi!"); | ||
| return; | ||
| } | ||
| BundleContext bundleContext = bundle.getBundleContext(); | ||
| if (bundleContext == null) { | ||
| System.err.println("Not started/resolved?"); | ||
| return; | ||
| } | ||
| EclipseApplicationLauncher launcher = new EclipseApplicationLauncher(); | ||
| applicationService = bundleContext.registerService(ApplicationLauncher.class, launcher, null); | ||
| testableObjectTracker = new ServiceTracker<>(bundleContext, TestableObject.class, null); | ||
| applicationDescriptorTracker = new ServiceTracker<>(bundleContext, ApplicationDescriptor.class, null); | ||
| applicationDescriptorTracker.open(); | ||
| testableObjectTracker.open(); | ||
| String testApplication = "org.eclipse.ui.ide.workbench"; // TODO how to access the JUnit config of the | ||
| // session?!? | ||
| Map<String, ApplicationDescriptor> tracked = applicationDescriptorTracker.getTracked().entrySet().stream() | ||
| .collect(Collectors.toMap(e -> (String) e.getKey().getProperty(ApplicationDescriptor.APPLICATION_PID), | ||
| e -> e.getValue())); | ||
| ApplicationDescriptor applicationDescriptor = tracked.get(testApplication); | ||
| if (applicationDescriptor == null) { | ||
| System.err.println("Test application '" + testApplication + "' was not found available applications are:"); | ||
| for (String appId : tracked.keySet()) { | ||
| System.err.println("\t- " + appId); | ||
| } | ||
| return; | ||
| } | ||
| testableObject = testableObjectTracker.getService(); | ||
| if (testableObject == null) { | ||
| System.err.println("No TestableObject found!"); | ||
| return; | ||
| } | ||
| CountDownLatch latch = new CountDownLatch(1); | ||
| testableObject.setTestHarness(new ITestHarness() { | ||
|
|
||
| @Override | ||
| public void runTests() { | ||
| latch.countDown(); | ||
| } | ||
| }); | ||
| HashMap<String, Object> launchArgs = new HashMap<>(1); | ||
| String[] args = new String[0]; | ||
| launchArgs.put(IApplicationContext.APPLICATION_ARGS, args); | ||
| try { | ||
| applicationHandle = applicationDescriptor.launch(launchArgs); | ||
| } catch (ApplicationException e) { | ||
| e.printStackTrace(); | ||
| return; | ||
| } | ||
| if (applicationHandle instanceof ParameterizedRunnable runable) { | ||
| applicationThread = new Thread(new Runnable() { | ||
|
|
||
| @Override | ||
| public void run() { | ||
| try { | ||
| runable.run(args); | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
| }); | ||
| applicationThread.setName("Eclipse-Test-Application [" + testApplication + "]"); | ||
| applicationThread.setDaemon(true); | ||
| applicationThread.start(); | ||
| try { | ||
| latch.await(); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| @NoReference | ||
| public void launcherSessionClosed(LauncherSession session) { | ||
| if (testableObject != null) { | ||
| testableObject.testingFinished(); | ||
| } | ||
| if (testableObjectTracker != null) { | ||
| testableObjectTracker.close(); | ||
| } | ||
| if (applicationDescriptorTracker != null) { | ||
| applicationDescriptorTracker.close(); | ||
| } | ||
| if (applicationService != null) { | ||
| applicationService.unregister(); | ||
| } | ||
| if (applicationThread != null) { | ||
| try { | ||
| applicationThread.join(); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are those really necessary? Couldn't they be added as requirements in build.properties or pom.xml instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is currently a bit work in progress and I just wanted it to run, the first is likely not required and the second would better be an additional requirement in the target platform.