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);
}
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);
}
}
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;
}
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());
}
}
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());
}
Aggregations