Search in sources :

Example 1 with TempFile

use of org.apache.tools.ant.taskdefs.TempFile in project ant by apache.

the class AggregateTransformer method transform.

/**
 * transformation
 * @throws BuildException exception if something goes wrong with the transformation.
 */
public void transform() throws BuildException {
    checkOptions();
    Project project = task.getProject();
    TempFile tempFileTask = new TempFile();
    tempFileTask.bindToOwner(task);
    xsltTask.setXslResource(getStylesheet());
    // acrobatic cast.
    xsltTask.setIn(((XMLResultAggregator) task).getDestinationFile());
    File outputFile;
    if (FRAMES.equals(format)) {
        // NOSONAR
        String tempFileProperty = getClass().getName() + String.valueOf(counter++);
        File tmp = FILE_UTILS.resolveFile(project.getBaseDir(), project.getProperty("java.io.tmpdir"));
        tempFileTask.setDestDir(tmp);
        tempFileTask.setProperty(tempFileProperty);
        tempFileTask.execute();
        outputFile = new File(project.getProperty(tempFileProperty));
    } else {
        outputFile = new File(toDir, "junit-noframes.html");
    }
    xsltTask.setOut(outputFile);
    XSLTProcess.Param paramx = xsltTask.createParam();
    paramx.setProject(task.getProject());
    paramx.setName("output.dir");
    paramx.setExpression(toDir.getAbsolutePath());
    configureForRedirectExtension();
    final long t0 = System.currentTimeMillis();
    try {
        xsltTask.execute();
    } catch (Exception e) {
        throw new BuildException("Errors while applying transformations: " + e.getMessage(), e);
    }
    final long dt = System.currentTimeMillis() - t0;
    task.log("Transform time: " + dt + "ms");
    if (format.equals(FRAMES)) {
        Delete delete = new Delete();
        delete.bindToOwner(task);
        delete.setFile(outputFile);
        delete.execute();
    }
}
Also used : Delete(org.apache.tools.ant.taskdefs.Delete) Project(org.apache.tools.ant.Project) TempFile(org.apache.tools.ant.taskdefs.TempFile) XSLTProcess(org.apache.tools.ant.taskdefs.XSLTProcess) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) TempFile(org.apache.tools.ant.taskdefs.TempFile) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 BuildException (org.apache.tools.ant.BuildException)1 Project (org.apache.tools.ant.Project)1 Delete (org.apache.tools.ant.taskdefs.Delete)1 TempFile (org.apache.tools.ant.taskdefs.TempFile)1 XSLTProcess (org.apache.tools.ant.taskdefs.XSLTProcess)1