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