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.doxia.site.SiteModel;
26 import org.apache.maven.doxia.site.inheritance.SiteModelInheritanceAssembler;
27 import org.apache.maven.doxia.tools.SiteTool;
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 import org.apache.maven.project.MavenProject;
34 import org.eclipse.aether.RepositorySystemSession;
35 import org.eclipse.aether.repository.RemoteRepository;
36
37
38
39
40
41
42 public abstract class AbstractSiteDescriptorMojo extends AbstractSiteMojo {
43
44
45
46 @Component
47 private SiteModelInheritanceAssembler assembler;
48
49
50
51
52 @Parameter(defaultValue = "${reactorProjects}", required = true, readonly = true)
53 protected List<MavenProject> reactorProjects;
54
55 @Parameter(defaultValue = "${repositorySystemSession}", required = true, readonly = true)
56 protected RepositorySystemSession repoSession;
57
58
59
60
61
62
63
64 @Parameter(defaultValue = "${project.remoteProjectRepositories}", readonly = true)
65 protected List<RemoteRepository> remoteProjectRepositories;
66
67
68
69
70
71
72
73
74 @Parameter(defaultValue = "${basedir}/src/site")
75 protected File siteDirectory;
76
77
78
79
80
81
82
83
84
85
86 @Parameter(property = "relativizeSiteLinks", defaultValue = "true")
87 private boolean relativizeSiteLinks;
88
89 protected SiteModel prepareSiteModel(Locale locale) throws MojoExecutionException {
90 SiteModel siteModel;
91 try {
92 siteModel = siteTool.getSiteModel(
93 siteDirectory, locale, project, reactorProjects, repoSession, remoteProjectRepositories);
94 } catch (SiteToolException e) {
95 throw new MojoExecutionException("Failed to obtain site model", e);
96 }
97
98 if (relativizeSiteLinks) {
99 final String url = project.getUrl();
100
101 if (url == null) {
102 getLog().warn("No project URL defined - site links will not be relativized!");
103 } else {
104
105 final String localeUrl = !locale.equals(SiteTool.DEFAULT_LOCALE) ? append(url, locale.toString()) : url;
106
107 getLog().info("Relativizing site links with respect to localized project URL: " + localeUrl);
108 assembler.resolvePaths(siteModel, localeUrl);
109 }
110 }
111 return siteModel;
112 }
113
114 private String append(String url, String path) {
115 return url.endsWith("/") ? (url + path) : (url + '/' + path);
116 }
117 }