Search in sources :

Example 1 with PrettyPrintXMLWriter

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

the class AntrunXmlPlexusConfigurationWriter method write.

/**
     * @param configuration {@link PlexusConfiguration}
     * @param writer {@link Writer}
     * @throws IOException In case of problems.
     */
public void write(PlexusConfiguration configuration, Writer writer) throws IOException {
    final int depth = 0;
    PrettyPrintXMLWriter xmlWriter = new PrettyPrintXMLWriter(writer);
    write(configuration, xmlWriter, depth);
}
Also used : PrettyPrintXMLWriter(org.codehaus.plexus.util.xml.PrettyPrintXMLWriter)

Example 2 with PrettyPrintXMLWriter

use of org.codehaus.plexus.util.xml.PrettyPrintXMLWriter in project felix by apache.

the class XMLReport method generateReport.

/**
 * Generates the XML reports.
 * @param test the test
 * @param tr the test result
 * @param reportsDirectory the directory in which reports are created.
 * @param bc the bundle context (to get installed bundles)
 * @param configuration the Felix configuration
 * @throws Exception when the XML report cannot be generated correctly
 */
public void generateReport(Test test, TestResult tr, File reportsDirectory, BundleContext bc, Map configuration) throws Exception {
    long runTime = this.m_endTime - this.m_startTime;
    Xpp3Dom testSuite = createTestSuiteElement(test, runTime);
    showProperties(testSuite, bc, configuration);
    testSuite.setAttribute("tests", String.valueOf(tr.runCount()));
    testSuite.setAttribute("errors", String.valueOf(tr.errorCount()));
    testSuite.setAttribute("failures", String.valueOf(tr.failureCount()));
    for (Iterator i = m_results.iterator(); i.hasNext(); ) {
        Xpp3Dom testcase = (Xpp3Dom) i.next();
        testSuite.addChild(testcase);
    }
    File reportFile = new File(reportsDirectory, "TEST-" + getReportName(test).replace(' ', '_') + ".xml");
    File reportDir = reportFile.getParentFile();
    reportDir.mkdirs();
    PrintWriter writer = null;
    try {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(reportFile), "UTF-8")));
        writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + NL);
        Xpp3DomWriter.write(new PrettyPrintXMLWriter(writer), testSuite);
    } catch (UnsupportedEncodingException e) {
        throw new Exception("Unable to use UTF-8 encoding", e);
    } catch (FileNotFoundException e) {
        throw new Exception("Unable to create file: " + e.getMessage(), e);
    } finally {
        IOUtil.close(writer);
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) FileOutputStream(java.io.FileOutputStream) Iterator(java.util.Iterator) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OutputStreamWriter(java.io.OutputStreamWriter) PrettyPrintXMLWriter(org.codehaus.plexus.util.xml.PrettyPrintXMLWriter) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 3 with PrettyPrintXMLWriter

use of org.codehaus.plexus.util.xml.PrettyPrintXMLWriter in project felix by apache.

the class BaselinePlugin method init.

@Override
protected Object init(final Object noContext) {
    if (xmlOutputFile != null) {
        xmlOutputFile.getParentFile().mkdirs();
        try {
            final Context ctx = new Context();
            ctx.writer = new FileWriter(xmlOutputFile);
            ctx.xmlWriter = new PrettyPrintXMLWriter(ctx.writer);
            return ctx;
        } catch (IOException e) {
            getLog().warn("No XML report will be produced, cannot write data to " + xmlOutputFile, e);
        }
    }
    return null;
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) PrettyPrintXMLWriter(org.codehaus.plexus.util.xml.PrettyPrintXMLWriter)

Example 4 with PrettyPrintXMLWriter

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

the class AbstractAnalyzeMojo method writeDependencyXML.

private void writeDependencyXML(Set<Artifact> artifacts) {
    if (!artifacts.isEmpty()) {
        getLog().info("Add the following to your pom to correct the missing dependencies: ");
        StringWriter out = new StringWriter();
        PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter(out);
        for (Artifact artifact : artifacts) {
            // called because artifact will set the version to -SNAPSHOT only if I do this. MNG-2961
            artifact.isSnapshot();
            writer.startElement("dependency");
            writer.startElement("groupId");
            writer.writeText(artifact.getGroupId());
            writer.endElement();
            writer.startElement("artifactId");
            writer.writeText(artifact.getArtifactId());
            writer.endElement();
            writer.startElement("version");
            writer.writeText(artifact.getBaseVersion());
            if (!StringUtils.isBlank(artifact.getClassifier())) {
                writer.startElement("classifier");
                writer.writeText(artifact.getClassifier());
                writer.endElement();
            }
            writer.endElement();
            if (!Artifact.SCOPE_COMPILE.equals(artifact.getScope())) {
                writer.startElement("scope");
                writer.writeText(artifact.getScope());
                writer.endElement();
            }
            writer.endElement();
        }
        getLog().info("\n" + out.getBuffer());
    }
}
Also used : StringWriter(java.io.StringWriter) PrettyPrintXMLWriter(org.codehaus.plexus.util.xml.PrettyPrintXMLWriter) Artifact(org.apache.maven.artifact.Artifact)

Example 5 with PrettyPrintXMLWriter

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

the class ComponentsXmlArchiverFileFilterTest method writeComponentsXml.

private Reader writeComponentsXml(final List<ComponentDef> componentDefs) throws IOException {
    final StringWriter writer = new StringWriter();
    final PrettyPrintXMLWriter xmlWriter = new PrettyPrintXMLWriter(writer);
    xmlWriter.startElement("component-set");
    xmlWriter.startElement("components");
    for (final ComponentDef def : componentDefs) {
        xmlWriter.startElement("component");
        xmlWriter.startElement("role");
        xmlWriter.writeText(def.role);
        xmlWriter.endElement();
        final String roleHint = def.roleHint;
        if (roleHint != null) {
            xmlWriter.startElement("role-hint");
            xmlWriter.writeText(roleHint);
            xmlWriter.endElement();
        }
        xmlWriter.startElement("implementation");
        xmlWriter.writeText(def.implementation);
        xmlWriter.endElement();
        xmlWriter.endElement();
    }
    xmlWriter.endElement();
    xmlWriter.endElement();
    return new StringReader(writer.toString());
}
Also used : StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) 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