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
75 protected File siteDirectory;
76
77
78
79
80
81
82
83
84 protected MavenProject project;
85
86
87
88
89
90
91 protected ArtifactRepository localRepository;
92
93
94
95
96
97
98
99
100 protected List reactorProjects;
101
102
103
104
105
106
107 private String inputEncoding;
108
109
110
111
112
113
114 private String outputEncoding;
115
116
117
118
119
120
121 protected String getInputEncoding()
122 {
123 return ( inputEncoding == null ) ? ReaderFactory.ISO_8859_1 : inputEncoding;
124 }
125
126
127
128
129
130
131 protected String getOutputEncoding()
132 {
133 return ( outputEncoding == null ) ? ReaderFactory.UTF_8 : outputEncoding;
134 }
135
136 protected void populateReportItems( DecorationModel decorationModel, Locale locale, Map reportsByOutputName )
137 {
138 for ( Iterator i = decorationModel.getMenus().iterator(); i.hasNext(); )
139 {
140 Menu menu = (Menu) i.next();
141
142 populateItemRefs( menu.getItems(), locale, reportsByOutputName );
143 }
144 }
145
146 private void populateItemRefs( List items, Locale locale, Map reportsByOutputName )
147 {
148 for ( Iterator i = items.iterator(); i.hasNext(); )
149 {
150 MenuItem item = (MenuItem) i.next();
151
152 if ( item.getRef() != null )
153 {
154 if ( reportsByOutputName.containsKey( item.getRef() ) )
155 {
156 MavenReport report = (MavenReport) reportsByOutputName.get( item.getRef() );
157
158 if ( item.getName() == null )
159 {
160 item.setName( report.getName( locale ) );
161 }
162
163 if ( item.getHref() == null || item.getHref().length() == 0 )
164 {
165 item.setHref( report.getOutputName() + ".html" );
166 }
167 }
168 else
169 {
170 getLog().warn( "Unrecognised reference: '" + item.getRef() + "'" );
171 i.remove();
172 }
173 }
174 populateItemRefs( item.getItems(), locale, reportsByOutputName );
175 }
176 }
177
178
179
180
181
182
183
184
185 protected static String toRelative( File basedir, String absolutePath )
186 {
187 String relative;
188
189 absolutePath = absolutePath.replace( '\\', '/' );
190 String basedirPath = basedir.getAbsolutePath().replace( '\\', '/' );
191
192 if ( absolutePath.startsWith( basedirPath ) )
193 {
194 relative = absolutePath.substring( basedirPath.length() + 1 );
195 }
196 else
197 {
198 relative = absolutePath;
199 }
200
201 return relative;
202 }
203 }