Search in sources :

Example 1 with BuildJobXpp3Writer

use of org.apache.maven.plugins.invoker.model.io.xpp3.BuildJobXpp3Writer in project maven-plugins by apache.

the class AbstractInvokerMojo method writeBuildReport.

/**
 * Writes the XML report for the specified build job unless report generation has been disabled.
 *
 * @param buildJob The build job whose report should be written, must not be <code>null</code>.
 * @throws org.apache.maven.plugin.MojoExecutionException If the report could not be written.
 */
private void writeBuildReport(BuildJob buildJob) throws MojoExecutionException {
    if (disableReports) {
        return;
    }
    String safeFileName = buildJob.getProject().replace('/', '_').replace('\\', '_').replace(' ', '_');
    if (safeFileName.endsWith("_pom.xml")) {
        safeFileName = safeFileName.substring(0, safeFileName.length() - "_pom.xml".length());
    }
    File reportFile = new File(reportsDirectory, "BUILD-" + safeFileName + ".xml");
    try {
        FileOutputStream fos = new FileOutputStream(reportFile);
        try {
            Writer osw = new OutputStreamWriter(fos, buildJob.getModelEncoding());
            BuildJobXpp3Writer writer = new BuildJobXpp3Writer();
            writer.write(osw, buildJob);
            osw.close();
        } finally {
            fos.close();
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to write build report " + reportFile, e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BuildJobXpp3Writer(org.apache.maven.plugins.invoker.model.io.xpp3.BuildJobXpp3Writer) IOException(java.io.IOException) File(java.io.File) Writer(java.io.Writer) BuildJobXpp3Writer(org.apache.maven.plugins.invoker.model.io.xpp3.BuildJobXpp3Writer) SettingsXpp3Writer(org.apache.maven.settings.io.xpp3.SettingsXpp3Writer) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter)

Aggregations

BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 BuildJobXpp3Writer (org.apache.maven.plugins.invoker.model.io.xpp3.BuildJobXpp3Writer)1 SettingsXpp3Writer (org.apache.maven.settings.io.xpp3.SettingsXpp3Writer)1