Search in sources :

Example 16 with PrettyPrintXMLWriter

use of org.codehaus.plexus.util.xml.PrettyPrintXMLWriter in project maven-plugins by apache.

the class EffectiveSiteMojo method execute.

/**
 * {@inheritDoc}
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    DecorationModel decorationModel = prepareDecorationModel(getLocales().get(0));
    StringWriter w = new StringWriter();
    XMLWriter writer = new PrettyPrintXMLWriter(w, StringUtils.repeat(" ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE), decorationModel.getModelEncoding(), null);
    writeHeader(writer);
    writeEffectiveSite(decorationModel, writer);
    String effectiveSite = w.toString();
    if (output != null) {
        try {
            writeXmlFile(output, effectiveSite);
        } catch (IOException e) {
            throw new MojoExecutionException("Cannot write effective site descriptor to output: " + output, e);
        }
        if (getLog().isInfoEnabled()) {
            getLog().info("Effective site descriptor written to: " + output);
        }
    } else {
        StringBuilder message = new StringBuilder();
        message.append("\nEffective site descriptor, after inheritance and interpolation:\n\n");
        message.append(effectiveSite);
        message.append("\n");
        if (getLog().isInfoEnabled()) {
            getLog().info(message.toString());
        }
    }
}
Also used : DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) StringWriter(java.io.StringWriter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) PrettyPrintXMLWriter(org.codehaus.plexus.util.xml.PrettyPrintXMLWriter) XMLWriter(org.codehaus.plexus.util.xml.XMLWriter) PrettyPrintXMLWriter(org.codehaus.plexus.util.xml.PrettyPrintXMLWriter)

Aggregations

PrettyPrintXMLWriter (org.codehaus.plexus.util.xml.PrettyPrintXMLWriter)16 XMLWriter (org.codehaus.plexus.util.xml.XMLWriter)10 StringWriter (java.io.StringWriter)9 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 IOException (java.io.IOException)5 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 MavenProject (org.apache.maven.project.MavenProject)3 Artifact (org.apache.maven.artifact.Artifact)2 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)2 ProjectBuilder (org.apache.maven.project.ProjectBuilder)2 ProjectBuildingResult (org.apache.maven.project.ProjectBuildingResult)2 BufferedWriter (java.io.BufferedWriter)1 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 StringReader (java.io.StringReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1