Allow more control over JUnit libraries and Ant runtime libraries for users of junitlauncher
I've been sitting on these changes for a while now trying to complete this work and then get some inputs. But I think these changes have now reached a state where I can get some feedback for them.
1.10.3 of Ant introduced support for using JUnit 5 through the new `junitlauncher` task. The support was minimal but had enough features for users to get started with using JUnit 5.
JUnit 5 project divides the JUnit libraries into `platform`, `launcher` and `engine` libraries. Ant's `junitlauncher` task relies only on JUnit `platform` and `launcher` libraries to support launching the tests. The `engine` libraries are allowed to be part of the task's classpath (configured via the `classpath` element). Unlike for the `engine` libraries, the `junitlauncher` task requires the JUnit `platform` and `launcher` libraries to be part of the Ant runtime classpath (either in the Ant installation directories or by using the `-lib` option while launching Ant). Historically, as seen with `junit` task, users prefer more control over the location of these jars while running their tests.
The goal of the commit(s) in this PR is to allow users to configure a classpath for the `junitlauncher` task with the necessary `platform`, `launcher` JUnit libraries and not force them to place these jars in the Ant runtime classpath.
without any explicit `-lib` nor the necessity to place the JUnit libraries in the Ant installation directory.
**Overview of changes**
Changes in this PR borrow ideas from the `junit` task and at the same time try and keep the complexity of this task manageable. This PR has 2 commits. One is solely in the build file and can be discussed/reviewed separately. I'll explain the build changes later in this PR. The main change in this PR is the commit which refactors the existing code. What that commit does is separates out the classes that are part of the `junitlauncher` task into 2 separate packages.
The `org.apache.tools.ant.taskdefs.optional.junitlauncher.confined` package as noted in its `package-info.java` documentation is _not_ allowed to have any _compile_ time dependency on the classes in `org.apache.tools.ant.taskdefs.optional.junitlauncher` or any of the classes in JUnit libraries. This allows the implementation of the task to load the JUnit libraries or any classes that depend on those libraries in a way that those classes don't have to be on the runtime classpath of Ant when the build is launched (see `TaskConfiguredPathClassLoader` in this PR and its usage for details).
On the other hand, the classes in the `org.apache.tools.ant.taskdefs.optional.junitlauncher` are allowed to have compile time dependency on classes in `org.apache.tools.ant.taskdefs.optional.junitlauncher.confined` or any classes that belong to JUnit libraries. Most the "core" logic of launching the tests happens in this package.
The commits in this PR are only refactoring changes to get this working. These do not contain any logic changes to the currently supported features of junitlauncher task. Although these refactoring changes do touch some classes/code that's meant to deal with `fork` mode support, none of these changes have any impact on the current functionality of how `fork` mode is implemented. In fact, the classloading changes that are described and implemented here play no role, if the `junitlauncher` task is configured to use `fork` mode.
One unfortunate but unavoidable change that I had to do was move the `JUnitLauncherTask` class (among some others) from `org.apache.tools.ant.taskdefs.optional.junitlauncher` to `org.apache.tools.ant.taskdefs.optional.junitlauncher.confined` package. This effectively means that if there was anyone out there who were relying on this class (out side of the task usage in the build file itself) will start running into issue. I need input on this part (among other things in this PR) - are we allowed to do such changes and add a backward compatiblity note in our release notes?
**Build file change**
The commit in this PR which deals with the build file, updates the `build` task to add a `verification` check (to be extra careful) to ensure that the classes in the `org.apache.tools.ant.taskdefs.optional.junitlauncher.confined` package have no compile time dependency on JUnit libraries or even classes in `org.apache.tools.ant.taskdefs.optional.junitlauncher` package. I couldn't think of a better approach to add this kind of check. I'm open to suggestions if this doesn't look right.
If these changes look good, I'll go ahead and start working on updating this task's manual.
You can merge this pull request into a Git repository by running:
The build actually caught a genuine issue that this build.xml was meant to catch. I have now added a 3rd commit to this PR which fixes that issue. I'll be squashing these commits before merging, if/when these changes are approved.
To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email]