use of org.apache.maven.doxia.tools.SiteToolException 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.tools.SiteToolException 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.tools.SiteToolException in project maven-plugins by apache.
the class AbstractSiteDescriptorMojo method prepareDecorationModel.
protected DecorationModel prepareDecorationModel(Locale locale) throws MojoExecutionException {
DecorationModel decorationModel;
try {
decorationModel = siteTool.getDecorationModel(siteDirectory, locale, project, reactorProjects, localRepository, repositories);
} catch (SiteToolException e) {
throw new MojoExecutionException("SiteToolException: " + e.getMessage(), e);
}
if (relativizeDecorationLinks) {
final String url = project.getUrl();
if (url == null) {
getLog().warn("No project URL defined - decoration links will not be relativized!");
} else {
List<Locale> localesList = getLocales();
// Default is first in the list
Locale defaultLocale = localesList.get(0);
// MSITE-658
final String localeUrl = locale.equals(defaultLocale) ? url : append(url, locale.getLanguage());
getLog().info("Relativizing decoration links with respect to localized project URL: " + localeUrl);
assembler.resolvePaths(decorationModel, localeUrl);
}
}
return decorationModel;
}
use of org.apache.maven.doxia.tools.SiteToolException in project webservices-axiom by apache.
the class PostProcessMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
DecorationModel decorationModel;
try {
decorationModel = siteTool.getDecorationModel(siteDirectory, siteTool.getSiteLocales(locales).get(0), project, reactorProjects, localRepository, repositories);
} catch (SiteToolException ex) {
throw new MojoExecutionException("SiteToolException: " + ex.getMessage(), ex);
}
String head = decorationModel.getBody().getHead();
DirectoryScanner ds = new DirectoryScanner();
ds.setIncludes(new String[] { "**/*.html" });
ds.setBasedir(javadocDirectory);
ds.scan();
for (String relativePath : ds.getIncludedFiles()) {
File file = new File(javadocDirectory, relativePath);
File tmpFile = new File(javadocDirectory, relativePath + ".tmp");
file.renameTo(tmpFile);
try {
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(tmpFile), "UTF-8"));
try {
PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
try {
String line;
while ((line = in.readLine()) != null) {
if (line.equals("</head>")) {
out.println(head);
}
out.println(line);
}
} finally {
out.close();
}
} finally {
in.close();
}
} catch (IOException ex) {
throw new MojoExecutionException("Failed to process " + relativePath + ": " + ex.getMessage(), ex);
}
tmpFile.delete();
}
}
use of org.apache.maven.doxia.tools.SiteToolException 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