use of org.apache.maven.doxia.site.decoration.DecorationModel 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());
}
}
}
use of org.apache.maven.doxia.site.decoration.DecorationModel in project maven-plugins by apache.
the class AbstractChangesReport method execute.
public void execute() throws MojoExecutionException {
if (!canGenerateReport()) {
return;
}
// TODO: push to a helper? Could still be improved by taking more of the site information from the site plugin
Writer writer = null;
try {
DecorationModel model = new DecorationModel();
model.setBody(new Body());
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("outputEncoding", getOutputEncoding());
Locale locale = Locale.getDefault();
SiteRenderingContext siteContext = siteRenderer.createContextForSkin(getSkinArtifactFile(), attributes, model, getName(locale), locale);
siteContext.setOutputEncoding(getOutputEncoding());
RenderingContext context = new RenderingContext(outputDirectory, getOutputName() + ".html");
SiteRendererSink sink = new SiteRendererSink(context);
generate(sink, null, locale);
outputDirectory.mkdirs();
File file = new File(outputDirectory, getOutputName() + ".html");
writer = new OutputStreamWriter(new FileOutputStream(file), getOutputEncoding());
siteRenderer.generateDocument(writer, sink, siteContext);
writer.close();
writer = null;
siteRenderer.copyResources(siteContext, new File(project.getBasedir(), "src/site/resources"), outputDirectory);
} catch (RendererException e) {
throw new MojoExecutionException("An error has occurred in " + getName(Locale.ENGLISH) + " report generation.", e);
} catch (IOException e) {
throw new MojoExecutionException("An error has occurred in " + getName(Locale.ENGLISH) + " report generation.", e);
} catch (MavenReportException e) {
throw new MojoExecutionException("An error has occurred in " + getName(Locale.ENGLISH) + " report generation.", e);
} finally {
IOUtils.closeQuietly(writer);
}
}
use of org.apache.maven.doxia.site.decoration.DecorationModel in project maven-plugins by apache.
the class AbstractProjectInfoReport method execute.
@Override
public void execute() throws MojoExecutionException {
if (!canGenerateReport()) {
return;
}
// TODO: push to a helper? Could still be improved by taking more of the site information from the site plugin
Writer writer = null;
try {
String filename = getOutputName() + ".html";
DecorationModel model = new DecorationModel();
model.setBody(new Body());
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("outputEncoding", "UTF-8");
attributes.put("project", project);
Locale locale = Locale.getDefault();
Artifact defaultSkin = siteTool.getDefaultSkinArtifact(localRepository, project.getRemoteArtifactRepositories());
SiteRenderingContext siteContext = siteRenderer.createContextForSkin(defaultSkin.getFile(), attributes, model, getName(locale), locale);
RenderingContext context = new RenderingContext(outputDirectory, filename);
SiteRendererSink sink = new SiteRendererSink(context);
generate(sink, null, locale);
outputDirectory.mkdirs();
writer = new OutputStreamWriter(new FileOutputStream(new File(outputDirectory, filename)), "UTF-8");
siteRenderer.generateDocument(writer, sink, siteContext);
siteRenderer.copyResources(siteContext, new File(project.getBasedir(), "src/site/resources"), outputDirectory);
writer.close();
writer = null;
} catch (RendererException e) {
throw new MojoExecutionException("An error has occurred in " + getName(Locale.ENGLISH) + " report generation.", e);
} catch (IOException e) {
throw new MojoExecutionException("An error has occurred in " + getName(Locale.ENGLISH) + " report generation.", e);
} catch (SiteToolException e) {
throw new MojoExecutionException("An error has occurred in " + getName(Locale.ENGLISH) + " report generation.", e);
} catch (MavenReportException e) {
throw new MojoExecutionException("An error has occurred in " + getName(Locale.ENGLISH) + " report generation.", e);
} finally {
IOUtil.close(writer);
}
}
Aggregations