From 8590e1539af7e5057d02941911c44d887ba3caca Mon Sep 17 00:00:00 2001 From: Jaikiran Pai Date: Mon, 27 Aug 2018 17:46:12 +0530 Subject: [junitlauncher] More fine-grained control over classpath for forked tests in junitlauncher - Allows Ant runtime libraries to be excluded and thus letting the user have control over where those library jars come from - Allows JUnit platform libraries to be excluded and thus letting the user have control over where those library jars come from Plus added testcases to verify this feature --- .../optional/junitlauncher/ForkDefinition.java | 18 +++++++++++++++--- .../optional/junitlauncher/StandaloneLauncher.java | 3 +-- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'src/main/org') diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/ForkDefinition.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/ForkDefinition.java index bda3381db..c5c95cc0d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/ForkDefinition.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/ForkDefinition.java @@ -41,7 +41,7 @@ import java.io.File; public class ForkDefinition { private boolean includeAntRuntimeLibraries = true; - private boolean includeJunitPlatformLibraries = true; + private boolean includeJUnitPlatformLibraries = true; private final CommandlineJava commandLineJava; private final Environment env = new Environment(); @@ -69,6 +69,14 @@ public class ForkDefinition { return this.timeout; } + public void setIncludeJUnitPlatformLibraries(final boolean include) { + this.includeJUnitPlatformLibraries = include; + } + + public void setIncludeAntRuntimeLibraries(final boolean include) { + this.includeAntRuntimeLibraries = include; + } + public Commandline.Argument createJvmArg() { return this.commandLineJava.createVmArgument(); } @@ -121,19 +129,23 @@ public class ForkDefinition { addAntRuntimeResourceSource(antRuntimeResourceSources, task, toResourceName(AntMain.class)); addAntRuntimeResourceSource(antRuntimeResourceSources, task, toResourceName(Task.class)); addAntRuntimeResourceSource(antRuntimeResourceSources, task, toResourceName(JUnitLauncherTask.class)); + } else { + task.log("Excluding Ant runtime libraries from forked JVM classpath", Project.MSG_DEBUG); } - - if (this.includeJunitPlatformLibraries) { + if (this.includeJUnitPlatformLibraries) { // platform-engine addAntRuntimeResourceSource(antRuntimeResourceSources, task, toResourceName(TestEngine.class)); // platform-launcher addAntRuntimeResourceSource(antRuntimeResourceSources, task, toResourceName(LauncherFactory.class)); // platform-commons addAntRuntimeResourceSource(antRuntimeResourceSources, task, toResourceName(Testable.class)); + } else { + task.log("Excluding JUnit platform libraries from forked JVM classpath", Project.MSG_DEBUG); } final Path classPath = cmdLine.createClasspath(project); classPath.createPath().append(antRuntimeResourceSources); + return cmdLine; } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/StandaloneLauncher.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/StandaloneLauncher.java index 8f43da373..69a1556c8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/StandaloneLauncher.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/StandaloneLauncher.java @@ -98,7 +98,6 @@ public class StandaloneLauncher { i = i + numArgsConsumed; } - launchDefinition.setTestExecutionContext(forkedExecution); final LauncherSupport launcherSupport = new LauncherSupport(launchDefinition); try { @@ -106,8 +105,8 @@ public class StandaloneLauncher { } catch (Throwable t) { if (launcherSupport.hasTestFailures()) { System.exit(Constants.FORK_EXIT_CODE_TESTS_FAILED); - throw t; } + throw t; } if (launcherSupport.hasTestFailures()) { System.exit(Constants.FORK_EXIT_CODE_TESTS_FAILED); -- cgit v1.2.1