in src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java [93:144]
public void execute() throws MojoExecutionException {
if (artifact != null && !artifact.isEmpty()) {
project = getMavenProject(artifact);
projects = Collections.singletonList(project);
}
StringWriter w = new StringWriter();
String encoding = output != null ? project.getModel().getModelEncoding() : System.getProperty("file.encoding");
XMLWriter writer = new PrettyPrintXMLWriter(
w, StringUtils.repeat(" ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE), encoding, null);
writeHeader(writer);
if (shouldWriteAllEffectivePOMsInReactor()) {
// outer root element
writer.startElement("projects");
for (MavenProject subProject : projects) {
writeEffectivePom(subProject, writer);
}
writer.endElement();
} else {
writeEffectivePom(project, writer);
}
String effectivePom = prettyFormat(w.toString(), encoding, false);
if (verbose) {
// tweak location tracking comment, that are put on a separate line by pretty print
effectivePom = effectivePom.replaceAll("(?m)>\\s+<!--}", "> <!-- ");
}
if (output != null) {
try {
writeXmlFile(output, effectivePom);
} catch (IOException e) {
throw new MojoExecutionException("Cannot write effective-POM to output: " + output, e);
}
getLog().info("Effective-POM written to: " + output);
} else {
if (MessageUtils.isColorEnabled()) {
// add color to comments
String comment = MessageUtils.buffer().project("<!--.-->").toString();
int dotIndex = comment.indexOf(".");
String commentStart = comment.substring(0, dotIndex);
String commentEnd = comment.substring(dotIndex + 1);
effectivePom = effectivePom.replace("<!--", commentStart).replace("-->", commentEnd);
}
getLog().info(LS + "Effective POMs, after inheritance, interpolation, and profiles are applied:" + LS + LS
+ effectivePom + LS);
}
}