001    /*
002     * Created on Jul 12, 2007
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
005     * the License. You may obtain a copy of the License at
006     *
007     * http://www.apache.org/licenses/LICENSE-2.0
008     *
009     * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
010     * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
011     * specific language governing permissions and limitations under the License.
012     *
013     * Copyright @2007-2009 the original author or authors.
014     */
015    package org.fest.swing.junit.ant;
016    
017    import org.apache.tools.ant.taskdefs.optional.junit.AggregateTransformer;
018    import org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator;
019    import org.apache.tools.ant.types.Path;
020    import org.apache.tools.ant.types.Reference;
021    
022    /**
023     * Aggregates all <junit> XML formatter test suite data under a specific directory and transforms the results via
024     * XSLT.
025     *
026     * @author Alex Ruiz
027     */
028    public class JUnitReportTask extends XMLResultAggregator {
029    
030      private Path classpath;
031    
032      /**
033       * Generate a report based on the document created by the merge.
034       * @return the generated report.
035       */
036      @SuppressWarnings("unchecked")
037      @Override public AggregateTransformer createReport() {
038        ReportTransformer transformer = new ReportTransformer(this);
039        transformer.setClasspath(classpath);
040        transformers.addElement(transformer);
041        return transformer;
042      }
043    
044      /**
045       * Sets an additional classpath.
046       * @param classpath the additional classpath to append to the current one.
047       */
048      public void setClasspath(Path classpath) {
049        createClasspath().append(classpath);
050      }
051    
052      /**
053       * Sets a reference to a classpath.
054       * @param r the reference to set.
055       */
056      public void setClasspathRef(Reference r) {
057        createClasspath().setRefid(r);
058      }
059    
060      /**
061       * Creates the current classpath.
062       * @return the created classpath.
063       */
064      public Path createClasspath() {
065        if (classpath == null) classpath = new Path(getProject());
066        return classpath.createPath();
067      }
068    }