use of org.apache.maven.doxia.siterenderer.RendererException in project maven-plugins by apache.
the class PdfMojo method copyResources.
/**
* Parse the decoration model to find the skin artifact and copy its resources to the output dir.
*
* @param locale not null
* @throws MojoExecutionException if any
* @see #getDefaultDecorationModel()
*/
private void copyResources(Locale locale) throws MojoExecutionException {
final DecorationModel decorationModel = getDefaultDecorationModel();
if (decorationModel == null) {
return;
}
File skinFile;
try {
skinFile = siteTool.getSkinArtifactFromRepository(localRepository, project.getRemoteArtifactRepositories(), decorationModel).getFile();
} catch (SiteToolException e) {
throw new MojoExecutionException("SiteToolException: " + e.getMessage(), e);
}
if (skinFile == null) {
return;
}
if (getLog().isDebugEnabled()) {
getLog().debug("Copy resources from skin artifact: '" + skinFile + "'...");
}
try {
final SiteRenderingContext context = siteRenderer.createContextForSkin(skinFile, new HashMap<String, Object>(2), decorationModel, project.getName(), locale);
context.addSiteDirectory(new File(siteDirectory, locale.getLanguage()));
siteRenderer.copyResources(context, workingDirectory);
} catch (IOException e) {
throw new MojoExecutionException("IOException: " + e.getMessage(), e);
} catch (RendererException e) {
throw new MojoExecutionException("RendererException: " + e.getMessage(), e);
}
}
use of org.apache.maven.doxia.siterenderer.RendererException in project maven-plugins by apache.
the class AbstractSiteRenderingMojo method createSiteRenderingContext.
protected SiteRenderingContext createSiteRenderingContext(Locale locale) throws MojoExecutionException, IOException, MojoFailureException {
DecorationModel decorationModel = prepareDecorationModel(locale);
if (attributes == null) {
attributes = new HashMap<String, Object>();
}
if (attributes.get("project") == null) {
attributes.put("project", project);
}
if (attributes.get("inputEncoding") == null) {
attributes.put("inputEncoding", getInputEncoding());
}
if (attributes.get("outputEncoding") == null) {
attributes.put("outputEncoding", getOutputEncoding());
}
// Put any of the properties in directly into the Velocity context
for (Map.Entry<Object, Object> entry : project.getProperties().entrySet()) {
attributes.put((String) entry.getKey(), entry.getValue());
}
SiteRenderingContext context;
if (templateFile != null) {
getLog().info("Rendering site with " + templateFile + " template file.");
if (!templateFile.exists()) {
throw new MojoFailureException("Template file '" + templateFile + "' does not exist");
}
context = siteRenderer.createContextForTemplate(templateFile, attributes, decorationModel, project.getName(), locale);
} else {
try {
Artifact skinArtifact = siteTool.getSkinArtifactFromRepository(localRepository, repositories, decorationModel);
getLog().info("Rendering site with " + skinArtifact.getId() + " skin.");
context = siteRenderer.createContextForSkin(skinArtifact, attributes, decorationModel, project.getName(), locale);
} catch (SiteToolException e) {
throw new MojoExecutionException("SiteToolException while preparing skin: " + e.getMessage(), e);
} catch (RendererException e) {
throw new MojoExecutionException("RendererException while preparing context for skin: " + e.getMessage(), e);
}
}
// Generate static site
if (!locale.getLanguage().equals(Locale.getDefault().getLanguage())) {
context.addSiteDirectory(new File(siteDirectory, locale.getLanguage()));
context.addModuleDirectory(new File(xdocDirectory, locale.getLanguage()), "xdoc");
context.addModuleDirectory(new File(xdocDirectory, locale.getLanguage()), "fml");
} else {
context.addSiteDirectory(siteDirectory);
context.addModuleDirectory(xdocDirectory, "xdoc");
context.addModuleDirectory(xdocDirectory, "fml");
}
if (moduleExcludes != null) {
context.setModuleExcludes(moduleExcludes);
}
if (saveProcessedContent) {
context.setProcessedContentOutput(new File(generatedSiteDirectory, "processed"));
}
return context;
}
use of org.apache.maven.doxia.siterenderer.RendererException in project maven-plugins by apache.
the class ReportDocumentRenderer method renderDocument.
public void renderDocument(Writer writer, Renderer renderer, SiteRenderingContext siteRenderingContext) throws RendererException, FileNotFoundException {
Locale locale = siteRenderingContext.getLocale();
String localReportName = report.getName(locale);
String msg = "Generating \"" + buffer().strong(localReportName) + "\" report";
// CHECKSTYLE_OFF: MagicNumber
log.info(reportMojoInfo == null ? (msg + '.') : (StringUtils.rightPad(msg, 40) + buffer().strong(" --- ").mojo(reportMojoInfo)));
// CHECKSTYLE_ON: MagicNumber
// main sink
SiteRendererSink mainSink = new SiteRendererSink(renderingContext);
// sink factory, for multi-page reports that need sub-sinks
MultiPageSinkFactory multiPageSinkFactory = new MultiPageSinkFactory(renderingContext);
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
if (classLoader != null) {
Thread.currentThread().setContextClassLoader(classLoader);
}
if (report instanceof MavenMultiPageReport) {
// extended multi-page API
((MavenMultiPageReport) report).generate(mainSink, multiPageSinkFactory, locale);
} else if (generateMultiPage(locale, multiPageSinkFactory, mainSink)) {
// extended multi-page API for Maven 2.2, only accessible by reflection API
} else {
// old single-page-only API
report.generate(mainSink, locale);
}
} catch (MavenReportException e) {
String report = (reportMojoInfo == null) ? ('"' + localReportName + "\" report") : reportMojoInfo;
throw new RendererException("Error generating " + report + ": " + e.getMessage(), e);
} catch (LinkageError e) {
String report = (reportMojoInfo == null) ? ('"' + localReportName + "\" report") : reportMojoInfo;
log.warn("An issue has occurred with " + report + ", skipping LinkageError " + e.getMessage() + ", please report an issue to Maven dev team.", e);
} finally {
if (classLoader != null) {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
mainSink.close();
}
if (report.isExternalReport()) {
// external reports are rendered from their own: no Doxia site rendering needed
return;
}
// render main sink
renderer.generateDocument(writer, mainSink, siteRenderingContext);
// render sub-sinks, eventually created by multi-page reports
try {
List<MultiPageSubSink> sinks = multiPageSinkFactory.sinks();
log.debug("Multipage report: " + sinks.size() + " subreports");
for (MultiPageSubSink mySink : sinks) {
mySink.enableLogging(new MojoLogWrapper(log));
log.debug(" Rendering " + mySink.getOutputName());
File outputFile = new File(mySink.getOutputDir(), mySink.getOutputName());
Writer out = null;
try {
out = WriterFactory.newWriter(outputFile, siteRenderingContext.getOutputEncoding());
renderer.generateDocument(out, mySink, siteRenderingContext);
mySink.close();
mySink = null;
out.close();
out = null;
} finally {
IOUtil.close(out);
if (mySink != null) {
mySink.close();
}
}
}
} catch (IOException e) {
throw new RendererException("Cannot create writer", e);
}
}
use of org.apache.maven.doxia.siterenderer.RendererException 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.siterenderer.RendererException in project maven-plugins by apache.
the class SiteMojo method execute.
/**
* {@inheritDoc} Generate the project site
* <p/>
* throws MojoExecutionException if any
*
* @see org.apache.maven.plugin.Mojo#execute()
*/
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
getLog().info("maven.site.skip = true: Skipping site generation");
return;
}
if (getLog().isDebugEnabled()) {
getLog().debug("executing Site Mojo");
}
checkInputEncoding();
List<MavenReportExecution> reports;
if (generateReports) {
reports = getReports();
} else {
reports = Collections.emptyList();
}
try {
List<Locale> localesList = getLocales();
// Default is first in the list
Locale defaultLocale = localesList.get(0);
Locale.setDefault(defaultLocale);
for (Locale locale : localesList) {
renderLocale(locale, reports);
}
} catch (RendererException e) {
throw new MojoExecutionException(e.getMessage(), e);
} catch (IOException e) {
throw new MojoExecutionException("Error during site generation", e);
}
}
Aggregations