use of org.codehaus.plexus.util.xml.PrettyPrintXMLWriter in project maven-plugins by apache.
the class AntBuildWriter method writeGeneratedBuildXml.
/**
* Generate an <code>maven-build.xml</code>
*
* @throws IOException
* @see #DEFAULT_MAVEN_BUILD_FILENAME
*/
private void writeGeneratedBuildXml() throws IOException {
// TODO: parameter
File outputFile = new File(project.getBasedir(), DEFAULT_MAVEN_BUILD_FILENAME);
String encoding = "UTF-8";
OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(outputFile), encoding);
XMLWriter writer = new PrettyPrintXMLWriter(w, StringUtils.repeat(" ", DEFAULT_INDENTATION_SIZE), encoding, null);
// ----------------------------------------------------------------------
// <!-- comments -->
// ----------------------------------------------------------------------
AntBuildWriterUtil.writeHeader(writer);
// ----------------------------------------------------------------------
// <project/>
// ----------------------------------------------------------------------
writer.startElement("project");
writer.addAttribute("name", project.getArtifactId() + "-from-maven");
writer.addAttribute("default", "package");
writer.addAttribute("basedir", ".");
XmlWriterUtil.writeLineBreak(writer);
// ----------------------------------------------------------------------
// <property/>
// ----------------------------------------------------------------------
writeProperties(writer);
// ----------------------------------------------------------------------
// <path/>
// ----------------------------------------------------------------------
writeBuildPathDefinition(writer);
// ----------------------------------------------------------------------
// <target name="clean" />
// ----------------------------------------------------------------------
writeCleanTarget(writer);
// ----------------------------------------------------------------------
// <target name="compile" />
// ----------------------------------------------------------------------
List compileSourceRoots = AntBuildWriterUtil.removeEmptyCompileSourceRoots(project.getCompileSourceRoots());
writeCompileTarget(writer, compileSourceRoots);
// ----------------------------------------------------------------------
// <target name="compile-tests" />
// ----------------------------------------------------------------------
List testCompileSourceRoots = AntBuildWriterUtil.removeEmptyCompileSourceRoots(project.getTestCompileSourceRoots());
writeCompileTestsTarget(writer, testCompileSourceRoots);
// ----------------------------------------------------------------------
// <target name="test" />
// ----------------------------------------------------------------------
writeTestTargets(writer, testCompileSourceRoots);
// ----------------------------------------------------------------------
// <target name="javadoc" />
// ----------------------------------------------------------------------
writeJavadocTarget(writer);
// ----------------------------------------------------------------------
// <target name="package" />
// ----------------------------------------------------------------------
writePackageTarget(writer);
// ----------------------------------------------------------------------
// <target name="get-deps" />
// ----------------------------------------------------------------------
writeGetDepsTarget(writer);
XmlWriterUtil.writeLineBreak(writer);
// project
writer.endElement();
XmlWriterUtil.writeLineBreak(writer);
w.close();
}
use of org.codehaus.plexus.util.xml.PrettyPrintXMLWriter in project maven-plugins 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 DoapUtilTest method testWriteElement.
/**
* Test method for {@link DoapUtil#writeElement(XMLWriter, String, String, String)}.
*
* @throws Exception if any
*/
public void testWriteElement() throws Exception {
StringWriter w = new StringWriter();
XMLWriter writer = new PrettyPrintXMLWriter(w);
DoapUtil.writeElement(writer, null, "name", "value");
w.close();
assertEquals(w.toString(), "<name>value</name>");
w = new StringWriter();
writer = new PrettyPrintXMLWriter(w);
try {
DoapUtil.writeElement(writer, null, null, null);
assertTrue("Null not catched", false);
} catch (IllegalArgumentException e) {
assertTrue("IllegalArgumentException catched", true);
} finally {
w.close();
}
}
use of org.codehaus.plexus.util.xml.PrettyPrintXMLWriter in project maven-plugins by apache.
the class EffectiveSettingsMojo method execute.
// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
/**
* {@inheritDoc}
*/
public void execute() throws MojoExecutionException {
Settings copySettings;
if (showPasswords) {
copySettings = settings;
} else {
copySettings = copySettings(settings);
hidePasswords(copySettings);
}
StringWriter w = new StringWriter();
XMLWriter writer = new PrettyPrintXMLWriter(w, StringUtils.repeat(" ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE), copySettings.getModelEncoding(), null);
writeHeader(writer);
writeEffectiveSettings(copySettings, writer);
String effectiveSettings = w.toString();
if (output != null) {
try {
writeXmlFile(output, effectiveSettings, copySettings.getModelEncoding());
} catch (IOException e) {
throw new MojoExecutionException("Cannot write effective-settings to output: " + output, e);
}
getLog().info("Effective-settings written to: " + output);
} else {
StringBuilder message = new StringBuilder();
message.append(LS).append("Effective user-specific configuration settings:").append(LS).append(LS);
message.append(effectiveSettings);
message.append(LS);
getLog().info(message.toString());
}
}
use of org.codehaus.plexus.util.xml.PrettyPrintXMLWriter in project maven-plugins by apache.
the class EffectivePomMojo method execute.
// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
/**
* {@inheritDoc}
*/
public void execute() throws MojoExecutionException {
if (StringUtils.isNotEmpty(artifact)) {
project = getMavenProject(artifact);
}
StringWriter w = new StringWriter();
XMLWriter writer = new PrettyPrintXMLWriter(w, StringUtils.repeat(" ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE), project.getModel().getModelEncoding(), null);
writeHeader(writer);
String effectivePom;
if (shouldWriteAllEffectivePOMsInReactor()) {
// outer root element
writer.startElement("projects");
for (MavenProject subProject : projects) {
writeEffectivePom(subProject, writer);
}
writer.endElement();
effectivePom = w.toString();
effectivePom = prettyFormat(effectivePom);
} else {
writeEffectivePom(project, writer);
effectivePom = w.toString();
}
if (output != null) {
try {
writeXmlFile(output, effectivePom, project.getModel().getModelEncoding());
} catch (IOException e) {
throw new MojoExecutionException("Cannot write effective-POM to output: " + output, e);
}
getLog().info("Effective-POM written to: " + output);
} else {
StringBuilder message = new StringBuilder();
message.append(LS);
message.append("Effective POMs, after inheritance, interpolation, and profiles are applied:");
message.append(LS).append(LS);
message.append(effectivePom);
message.append(LS);
getLog().info(message.toString());
}
}
Aggregations