[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GitHub] ant pull request #69: Allow more control over JUnit libraries and Ant runtim...

GitHub user jaikiran opened a pull request:


    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.
    Imagine something like:
    <path id="test.classpath">
        <pathelement location="${build.classes.dir}" />
        <!-- JUnit platform and launcher jars -->
        <fileset dir="${basedir}/lib/junit-platform/" includes="*.jar"/>
        <!-- JUnit engine jars -->
        <fileset dir="${basedir}/lib/junit-jupiter/" includes="*.jar"/>
        <fileset dir="${basedir}/lib/junit-vintage/" includes="*.jar"/>
    <target name="test">
            <testclasses outputdir="${output.dir}">
              <fileset dir="${build.classes.dir}"/>
            <classpath refid="test.classpath" />
    and then just run the build as:
    ant test
    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.
    **Backward compatibility**
    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:

    $ git pull https://github.com/jaikiran/ant junit5-fork-classpath

Alternatively you can review and apply these changes as the patch at:


To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #69
commit 2bf001994ce5019a5a3b86e455a54e46b5b60ca3
Author: Jaikiran Pai <jaikiran@...>
Date:   2018-08-29T09:56:38Z

    [junitlauncher] Allow JUnit libraries to be part of the task's classpath instead of mandating it to be part of Ant's runtime classpath

commit 64e38efc22331362625b6fcb7af438973fe83c1c
Author: Jaikiran Pai <jaikiran@...>
Date:   2018-10-11T09:49:55Z

    [junitlauncher] Add a check in the build to ensure that the junitlauncher classes in "confined" package do not depend on classes they aren't meant to



To unsubscribe, e-mail: dev-unsubscribe@xxxxxxxxxxxxxx
For additional commands, e-mail: dev-help@xxxxxxxxxxxxxx