1 package org.apache.maven.plugins.site;
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.Iterator;
24 import java.util.List;
25 import java.util.Locale;
26 import java.util.Map;
27
28 import org.apache.maven.artifact.repository.ArtifactRepository;
29 import org.apache.maven.doxia.site.decoration.DecorationModel;
30 import org.apache.maven.doxia.site.decoration.Menu;
31 import org.apache.maven.doxia.site.decoration.MenuItem;
32 import org.apache.maven.doxia.tools.SiteTool;
33 import org.apache.maven.plugin.AbstractMojo;
34 import org.apache.maven.project.MavenProject;
35 import org.apache.maven.reporting.MavenReport;
36 import org.codehaus.plexus.i18n.I18N;
37 import org.codehaus.plexus.util.ReaderFactory;
38
39
40
41
42
43
44 public abstract class AbstractSiteMojo
45 extends AbstractMojo
46 {
47
48
49
50
51
52
53 protected String locales;
54
55
56
57
58
59
60 protected SiteTool siteTool;
61
62
63
64
65
66
67 protected I18N i18n;
68
69
70
71
72
73
74 protected File siteDirectory;
75
76
77
78
79
80
81
82
83 protected MavenProject project;
84
85
86
87
88
89
90 protected ArtifactRepository localRepository;
91
92
93
94
95
96
97
98
99 protected List<MavenProject> reactorProjects;
100
101
102
103
104
105
106 private String inputEncoding;
107
108
109
110
111
112
113 private String outputEncoding;
114
115
116
117
118
119
120 protected String getInputEncoding()
121 {
122 return ( inputEncoding == null ) ? ReaderFactory.ISO_8859_1 : inputEncoding;
123 }
124
125
126
127
128
129
130 protected String getOutputEncoding()
131 {
132 return ( outputEncoding == null ) ? ReaderFactory.UTF_8 : outputEncoding;
133 }
134
135 protected void populateReportItems( DecorationModel decorationModel, Locale locale,
136 Map<String, MavenReport> reportsByOutputName )
137 {
138 for ( Iterator<Menu> i = decorationModel.getMenus().iterator(); i.hasNext(); )
139 {
140 Menu menu = i.next();
141
142 populateItemRefs( menu.getItems(), locale, reportsByOutputName );
143 }
144 }
145
146 private void populateItemRefs( List<MenuItem> items, Locale locale, Map<String, MavenReport> reportsByOutputName )
147 {
148 for ( Iterator<MenuItem> i = items.iterator(); i.hasNext(); )
149 {
150 MenuItem item = i.next();
151
152 if ( item.getRef() != null )
153 {
154 MavenReport report = reportsByOutputName.get( item.getRef() );
155
156 if ( report != null )
157 {
158
159 if ( item.getName() == null )
160 {
161 item.setName( report.getName( locale ) );
162 }
163
164 if ( item.getHref() == null || item.getHref().length() == 0 )
165 {
166 item.setHref( report.getOutputName() + ".html" );
167 }
168 }
169 else
170 {
171 getLog().warn( "Unrecognised reference: '" + item.getRef() + "'" );
172 i.remove();
173 }
174 }
175 populateItemRefs( item.getItems(), locale, reportsByOutputName );
176 }
177 }
178
179
180
181
182
183
184
185
186 protected static String toRelative( File basedir, String absolutePath )
187 {
188 String relative;
189
190 absolutePath = absolutePath.replace( '\\', '/' );
191 String basedirPath = basedir.getAbsolutePath().replace( '\\', '/' );
192
193 if ( absolutePath.startsWith( basedirPath ) )
194 {
195 relative = absolutePath.substring( basedirPath.length() + 1 );
196 }
197 else
198 {
199 relative = absolutePath;
200 }
201
202 return relative;
203 }
204 }