Bug 32975

Summary: Make XmlFormatter for junittask (optinally) lighter
Product: Ant Reporter: gui <janssk1>
Component: Optional TasksAssignee: Ant Notifications List <notifications>
Status: NEW ---    
Severity: enhancement Keywords: PatchAvailable
Priority: P2    
Version: 1.6.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows 2000   
Bug Depends on: 32973    
Bug Blocks:    
Attachments: prevents XMLJUnitFormatter from outputting properties unless the verbose flag is set

Description gui 2005-01-06 22:32:10 UTC
The xml formatter (needed for the junitreport task) adds for each testcase all 
ant properties to a xmlfile. In a project with a substantial amount of ant 
properties this can lead to a big file. Combined with a lot of testcases this 
results in megabytes of property information that are all the same. Since i 
don't know anybody who actually uses this information, it might be a good idea 
to make the generation of property information by the xml formatter optional. 

Something like a 'includeProperties' property or a 'verbose' property could be 
nice. It would also make the processing of the junitreport task a lot faster. 

Just a small example: In our project, we added a custom formatter that does the 
same as the default xml formatter but removes the properties. It brings the 
overall size of the test.xml files back from 17 meg to under 1 megabyte. Xslt 
transformtion is ofcourse a lot faste
Comment 1 Kev Jackson 2005-02-18 05:22:29 UTC
Created attachment 14310 [details]
prevents XMLJUnitFormatter from outputting properties unless the verbose flag is set

eg:

<junit printsummary="yes" fork="yes" haltonfailure="no">
  <classpath>
    <pathelement location="${build.dir}" />
    <pathelement location="${lib.dir}/junit/junit.jar" />
  </classpath>
  <formatter type="xml" usefFile="true" verbose="false"/>
			
</junit>


tested on WindowsXP with JDK1.5.0, using HEAD.	tested with fork="yes" and
fork"no".  Under test, brought the file size of the XML generated down by 75%
(from 8Kb -> 2Kb).  Sorry no JUnit tests for this (ironically I suppose)
Comment 2 Peter Reilly 2005-02-18 10:30:33 UTC
On a quick look at the patch, I noticed one problem.
The interface "JUnitResultFormatter" has been extended
with one new method (setVerbose). As JUnitResultFormatter
is a public interface, and is the way for 3'th party formatters
to be added to ant, the change is not backward compatible.
Comment 3 Kev Jackson 2005-02-18 10:42:01 UTC
Damn! Sorry about that.

Can you suggest a way to refactor the code, I'd be willing to do the work, but I
can't see how to make this change right now (brain freeze).
Comment 4 Peter Reilly 2005-02-18 19:08:17 UTC
I can think of using ant-types
  <formatter usefile="yes">
      <junit.xmlformatter verbose="yes"/>
  </formatter>

Change to Formatter.java:
    private JUnitResultFormatter  byReflection;
    public void add(JUnitResultFormatter byReflection) {
        this.byReflection = byReflection;
    }
    
    /**
     * @since Ant 1.6
     */
    JUnitResultFormatter createFormatter(ClassLoader loader)
        throws BuildException {
        JUnitResultFormatter r = byReflection;
        if (byReflection == null) {
         ....
         }
                }

        if (useFile && outFile != null) {
            try {
                out = new FileOutputStream(outFile);
            } catch (java.io.IOException e) {
                throw new BuildException(e);
            }
        }
        r.setOutput(out);
        return r;
}
* not tested completly *