use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class PdfMojo method generateMavenReport.
/**
* Generate the given Maven report only if it is not an external report and the report could be generated.
*
* @param mojoDescriptor not null, to catch linkage error
* @param report could be null
* @param locale not null
* @throws IOException if any
* @throws MojoExecutionException if any
* @see #isValidGeneratedReport(MojoDescriptor, File, String)
* @since 1.1
*/
private void generateMavenReport(MavenReport report, Artifact pluginArtifact, Locale locale) throws IOException, MojoExecutionException {
if (report == null) {
return;
}
String localReportName = report.getName(locale);
if (!report.canGenerateReport()) {
getLog().info("Skipped \"" + localReportName + "\" report.");
getLog().debug("canGenerateReport() was false.");
return;
}
if (report.isExternalReport()) {
getLog().info("Skipped external \"" + localReportName + "\" report.");
getLog().debug("isExternalReport() was false.");
return;
}
for (final MavenReport generatedReport : getGeneratedMavenReports(locale)) {
if (report.getName(locale).equals(generatedReport.getName(locale))) {
if (getLog().isDebugEnabled()) {
getLog().debug(report.getName(locale) + " was already generated.");
}
return;
}
}
File outDir = new File(getGeneratedSiteDirectoryTmp(), "xdoc");
if (!locale.getLanguage().equals(defaultLocale.getLanguage())) {
outDir = new File(new File(getGeneratedSiteDirectoryTmp(), locale.getLanguage()), "xdoc");
}
outDir.mkdirs();
File generatedReport = new File(outDir, report.getOutputName() + ".xml");
String excludes = getDefaultExcludesWithLocales(getAvailableLocales(), getDefaultLocale());
List<String> files = FileUtils.getFileNames(siteDirectory, "*/" + report.getOutputName() + ".*", excludes, false);
if (!locale.getLanguage().equals(defaultLocale.getLanguage())) {
files = FileUtils.getFileNames(new File(siteDirectory, locale.getLanguage()), "*/" + report.getOutputName() + ".*", excludes, false);
}
if (files.size() != 0) {
String displayLanguage = locale.getDisplayLanguage(Locale.ENGLISH);
if (getLog().isInfoEnabled()) {
getLog().info("Skipped \"" + report.getName(locale) + "\" report, file \"" + report.getOutputName() + "\" already exists for the " + displayLanguage + " version.");
}
return;
}
if (getLog().isInfoEnabled()) {
getLog().info("Generating \"" + localReportName + "\" report.");
}
StringWriter sw = new StringWriter();
PdfSink sink = null;
try {
sink = new PdfSink(sw);
org.codehaus.doxia.sink.Sink proxy = (org.codehaus.doxia.sink.Sink) Proxy.newProxyInstance(org.codehaus.doxia.sink.Sink.class.getClassLoader(), new Class[] { org.codehaus.doxia.sink.Sink.class }, new SinkDelegate(sink));
report.generate(proxy, locale);
} catch (MavenReportException e) {
throw new MojoExecutionException("MavenReportException: " + e.getMessage(), e);
} finally {
if (sink != null) {
sink.close();
}
}
writeGeneratedReport(sw.toString(), generatedReport);
if (isValidGeneratedReport(pluginArtifact, generatedReport, localReportName)) {
getGeneratedMavenReports(locale).add(report);
}
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class LinkcheckReport method executeReport.
// ----------------------------------------------------------------------
// Protected methods
// ----------------------------------------------------------------------
/** {@inheritDoc} */
protected void executeReport(Locale locale) throws MavenReportException {
if (result == null) {
getLog().debug("Calling execute()");
try {
this.execute();
} catch (MojoExecutionException e) {
throw new MavenReportException("MojoExecutionException: " + e.getMessage(), e);
}
}
if (result != null) {
generateReport(locale, result);
// free memory
result = null;
}
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class DefaultCheckstyleRssGenerator method generateRSS.
@Override
public void generateRSS(CheckstyleResults results, CheckstyleRssGeneratorRequest checkstyleRssGeneratorRequest) throws MavenReportException {
VelocityTemplate vtemplate = new VelocityTemplate(velocityComponent, CheckstyleReport.PLUGIN_RESOURCES);
vtemplate.setLog(checkstyleRssGeneratorRequest.getLog());
Context context = new VelocityContext();
context.put("results", results);
context.put("project", checkstyleRssGeneratorRequest.getMavenProject());
context.put("copyright", checkstyleRssGeneratorRequest.getCopyright());
context.put("levelInfo", SeverityLevel.INFO);
context.put("levelWarning", SeverityLevel.WARNING);
context.put("levelError", SeverityLevel.ERROR);
context.put("stringutils", new StringUtils());
try {
vtemplate.generate(checkstyleRssGeneratorRequest.getOutputDirectory().getPath() + "/checkstyle.rss", "checkstyle-rss.vm", context);
} catch (ResourceNotFoundException e) {
throw new MavenReportException("Unable to find checkstyle-rss.vm resource.", e);
} catch (MojoExecutionException | IOException | VelocityException e) {
throw new MavenReportException("Unable to generate checkstyle.rss.", e);
}
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class ReportDocumentRenderer method generateMultiPage.
/**
* Try to generate report with extended multi-page API.
*
* @return <code>true</code> if the report was compatible with the extended API
*/
private boolean generateMultiPage(Locale locale, SinkFactory sf, Sink sink) throws MavenReportException {
try {
// MavenMultiPageReport is not in Maven Core, then the class is different in site plugin and in each report
// plugin: only reflection can let us invoke its method
Method generate = report.getClass().getMethod("generate", Sink.class, SinkFactory.class, Locale.class);
generate.invoke(report, sink, sf, locale);
return true;
} catch (SecurityException se) {
return false;
} catch (NoSuchMethodException nsme) {
return false;
} catch (IllegalArgumentException iae) {
throw new MavenReportException("error while invoking generate", iae);
} catch (IllegalAccessException iae) {
throw new MavenReportException("error while invoking generate", iae);
} catch (InvocationTargetException ite) {
throw new MavenReportException("error while invoking generate", ite);
}
}
use of org.apache.maven.reporting.MavenReportException 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);
}
}
Aggregations