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