1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.site.descriptor;
20
21 import java.io.File;
22 import java.util.List;
23 import java.util.Locale;
24
25 import org.apache.maven.artifact.repository.ArtifactRepository;
26 import org.apache.maven.doxia.site.decoration.DecorationModel;
27 import org.apache.maven.doxia.site.decoration.inheritance.DecorationModelInheritanceAssembler;
28 import org.apache.maven.doxia.tools.SiteToolException;
29 import org.apache.maven.plugin.MojoExecutionException;
30 import org.apache.maven.plugins.annotations.Component;
31 import org.apache.maven.plugins.annotations.Parameter;
32 import org.apache.maven.plugins.site.AbstractSiteMojo;
33
34
35
36
37
38
39 public abstract class AbstractSiteDescriptorMojo extends AbstractSiteMojo {
40
41
42
43 @Component
44 private DecorationModelInheritanceAssembler assembler;
45
46
47
48
49
50
51
52 @Parameter(defaultValue = "${project.remoteArtifactRepositories}", readonly = true)
53 protected List<ArtifactRepository> repositories;
54
55
56
57
58
59
60
61
62 @Parameter(defaultValue = "${basedir}/src/site")
63 protected File siteDirectory;
64
65
66
67
68
69
70
71
72
73
74 @Parameter(property = "relativizeDecorationLinks", defaultValue = "true")
75 private boolean relativizeDecorationLinks;
76
77 protected DecorationModel prepareDecorationModel(Locale locale) throws MojoExecutionException {
78 DecorationModel decorationModel;
79 try {
80 decorationModel = siteTool.getDecorationModel(
81 siteDirectory, locale, project, reactorProjects, localRepository, repositories);
82 } catch (SiteToolException e) {
83 throw new MojoExecutionException("SiteToolException: " + e.getMessage(), e);
84 }
85
86 if (relativizeDecorationLinks) {
87 final String url = project.getUrl();
88
89 if (url == null) {
90 getLog().warn("No project URL defined - decoration links will not be relativized!");
91 } else {
92 List<Locale> localesList = getLocales();
93
94
95 Locale defaultLocale = localesList.get(0);
96
97
98 final String localeUrl = locale.equals(defaultLocale) ? url : append(url, locale.toString());
99
100 getLog().info("Relativizing decoration links with respect to localized project URL: " + localeUrl);
101 assembler.resolvePaths(decorationModel, localeUrl);
102 }
103 }
104 return decorationModel;
105 }
106
107 private String append(String url, String path) {
108 return url.endsWith("/") ? (url + path) : (url + '/' + path);
109 }
110 }