https://bz.apache.org/bugzilla/show_bug.cgi?id=66504

            Bug ID: 66504
           Summary: JUnitLauncher task <testclasses> attribute outputdir
                    is not relative to project's basedir
           Product: Ant
           Version: 1.10.12
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Core tasks
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

Created attachment 38516
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=38516&action=edit
Minimal working example illustrating the issue

Steps to reproduce
------------------

1. Create an Ant project whose basedir attribute is different from the folder
where build.xml resides (for example, a subfolder called `Sub`).

2. In this project, create a target that:
  a) creates a folder with a *relative* path (e.g. <mkdir dir="report"/>)
  b) contains a `junitlauncher` task, with a `testclasses` element with an
`outputdir` attribute that contains that same *relative* path (i.e. `report`)
  c) includes at least one listener (for example legacy-xml)

3. Run Ant by calling the target.

Expected result
---------------

The junitlauncher task writes its report files in the proper path (i.e.
`Sub/report` in this example).

Observed result
---------------

The task ends by throwing an exception, related to the fact that folder
`report` does not exist.

Cause
-----

The junitlauncher task looks for `report` relative to the location of
build.xml, and not relative to the project's basedir parameter. This is
contrary to other Ant tasks, where relative paths are always interpreted with
respect to the project's basedir.

Workaround
----------

A temporary workaround is to prepend ${basedir} to the path given to the
outputdir parameter (i.e. replacing outputdir="report" with
outputdir="${basedir}/report" in the example above). The resulting path is
absolute and thus the task does not need to resolve it.

Suggested fix
-------------

Looking at version 1.10.13 of the source code, one can locate the issue in
method getListenerOutputFile() of class LauncherSupport.

Line 290 is:

   return Paths.get(listener.getOutputDir(), filename);

But this produces a path that is relative to the location build.xml. The same
thing occurs on line 294.

In contrast, on lines 298-299 (which handle the case where no outputdir is
specified), the path is correctly resolved against the project's basedir
attribute.

Documentation
-------------

I attached an archive with a minimal working example (Ant script, a single test
case), and an example of the output produced by Ant in this case (showing the
stack trace for the exception thrown).

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to