use of org.apache.maven.doxia.siterenderer.RenderingContext in project camel by apache.
the class DocumentGeneratorMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
RenderingContext context = new RenderingContext(reportOutputDirectory, getOutputName() + ".html");
SiteRendererSink sink = new SiteRendererSink(context);
Locale locale = Locale.getDefault();
try {
generate(sink, locale);
} catch (MavenReportException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
use of org.apache.maven.doxia.siterenderer.RenderingContext in project maven-plugins by apache.
the class AbstractSiteRenderingMojo method locateDocuments.
/**
* Locate every document to be rendered for given locale:<ul>
* <li>handwritten content, ie Doxia files,</li>
* <li>reports,</li>
* <li>"Project Information" and "Project Reports" category summaries.</li>
* </ul>
* @see CategorySummaryDocumentRenderer
*/
protected Map<String, DocumentRenderer> locateDocuments(SiteRenderingContext context, List<MavenReportExecution> reports, Locale locale) throws IOException, RendererException {
Map<String, DocumentRenderer> documents = siteRenderer.locateDocumentFiles(context);
Map<String, MavenReport> reportsByOutputName = locateReports(reports, documents, locale);
// TODO: I want to get rid of categories eventually. There's no way to add your own in a fully i18n manner
Map<String, List<MavenReport>> categories = categoriseReports(reportsByOutputName.values());
siteTool.populateReportsMenu(context.getDecoration(), locale, categories);
populateReportItems(context.getDecoration(), locale, reportsByOutputName);
if (categories.containsKey(MavenReport.CATEGORY_PROJECT_INFORMATION) && generateProjectInfo) {
// add "Project Information" category summary document
List<MavenReport> categoryReports = categories.get(MavenReport.CATEGORY_PROJECT_INFORMATION);
RenderingContext renderingContext = new RenderingContext(siteDirectory, "project-info.html");
String title = i18n.getString("site-plugin", locale, "report.information.title");
String desc1 = i18n.getString("site-plugin", locale, "report.information.description1");
String desc2 = i18n.getString("site-plugin", locale, "report.information.description2");
DocumentRenderer renderer = new CategorySummaryDocumentRenderer(renderingContext, title, desc1, desc2, i18n, categoryReports, getLog());
if (!documents.containsKey(renderer.getOutputName())) {
documents.put(renderer.getOutputName(), renderer);
} else {
getLog().info("Category summary '" + renderer.getOutputName() + "' skipped; already exists");
}
}
if (categories.containsKey(MavenReport.CATEGORY_PROJECT_REPORTS)) {
// add "Project Reports" category summary document
List<MavenReport> categoryReports = categories.get(MavenReport.CATEGORY_PROJECT_REPORTS);
RenderingContext renderingContext = new RenderingContext(siteDirectory, "project-reports.html");
String title = i18n.getString("site-plugin", locale, "report.project.title");
String desc1 = i18n.getString("site-plugin", locale, "report.project.description1");
String desc2 = i18n.getString("site-plugin", locale, "report.project.description2");
DocumentRenderer renderer = new CategorySummaryDocumentRenderer(renderingContext, title, desc1, desc2, i18n, categoryReports, getLog());
if (!documents.containsKey(renderer.getOutputName())) {
documents.put(renderer.getOutputName(), renderer);
} else {
getLog().info("Category summary '" + renderer.getOutputName() + "' skipped; already exists");
}
}
return documents;
}
use of org.apache.maven.doxia.siterenderer.RenderingContext in project maven-plugins by apache.
the class AbstractSiteRenderingMojo method locateReports.
/**
* Go through the list of reports and process each one like this:
* <ul>
* <li>Add the report to a map of reports keyed by filename having the report itself as value
* <li>If the report is not yet in the map of documents, add it together with a suitable renderer
* </ul>
*
* @param reports A List of MavenReports
* @param documents A Map of documents, keyed by filename
* @param locale the Locale the reports are processed for.
* @return A map with all reports keyed by filename having the report itself as value.
* The map will be used to populate a menu.
*/
protected Map<String, MavenReport> locateReports(List<MavenReportExecution> reports, Map<String, DocumentRenderer> documents, Locale locale) {
// copy Collection to prevent ConcurrentModificationException
List<MavenReportExecution> filtered = new ArrayList<MavenReportExecution>(reports);
Map<String, MavenReport> reportsByOutputName = new LinkedHashMap<String, MavenReport>();
for (MavenReportExecution mavenReportExecution : filtered) {
MavenReport report = mavenReportExecution.getMavenReport();
String outputName = report.getOutputName() + ".html";
// Always add the report to the menu, see MSITE-150
reportsByOutputName.put(report.getOutputName(), report);
if (documents.containsKey(outputName)) {
String displayLanguage = locale.getDisplayLanguage(Locale.ENGLISH);
String reportMojoInfo = (mavenReportExecution.getGoal() == null) ? "" : (" (" + mavenReportExecution.getPlugin().getArtifactId() + ':' + mavenReportExecution.getPlugin().getVersion() + ':' + mavenReportExecution.getGoal() + ')');
getLog().info("Skipped \"" + report.getName(locale) + "\" report" + reportMojoInfo + ", file \"" + outputName + "\" already exists for the " + displayLanguage + " version.");
reports.remove(mavenReportExecution);
} else {
RenderingContext renderingContext = new RenderingContext(siteDirectory, outputName);
DocumentRenderer renderer = new ReportDocumentRenderer(mavenReportExecution, renderingContext, getLog());
documents.put(outputName, renderer);
}
}
return reportsByOutputName;
}
use of org.apache.maven.doxia.siterenderer.RenderingContext 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