1 package org.apache.maven.jxr;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.jxr.ant.DirectoryScanner;
23 import org.apache.maven.jxr.log.Log;
24 import org.apache.maven.jxr.pacman.FileManager;
25 import org.apache.maven.jxr.pacman.PackageManager;
26
27 import java.io.IOException;
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
30 import java.util.List;
31 import java.util.Locale;
32
33
34
35
36
37
38
39 public class JXR
40 {
41
42
43
44 private Log log;
45
46
47
48
49 private static final String[] DEFAULT_INCLUDES = { "**/*.java" };
50
51
52
53
54 private Path destDir;
55
56 private Locale locale;
57
58 private String inputEncoding;
59
60 private String outputEncoding;
61
62
63
64
65 private Path javadocLinkDir;
66
67
68
69
70
71 private JavaCodeTransform transformer;
72
73
74
75
76 private String revision;
77
78
79
80
81 private String[] excludes = null;
82
83
84
85
86 private String[] includes = DEFAULT_INCLUDES;
87
88
89
90
91
92
93
94
95
96 public void processPath( PackageManager packageManager, Path sourceDir, String bottom )
97 throws IOException
98 {
99 this.transformer = new JavaCodeTransform( packageManager );
100
101 DirectoryScannerScanner.html#DirectoryScanner">DirectoryScanner ds = new DirectoryScanner();
102
103
104 ds.setExcludes( excludes );
105 ds.setIncludes( includes );
106 ds.addDefaultExcludes();
107
108 ds.setBasedir( sourceDir.toString() );
109 ds.scan();
110
111
112
113 String[] files = ds.getIncludedFiles();
114
115 for ( String file : files )
116 {
117 Path sourceFile = sourceDir.resolve( file );
118
119 if ( isJavaFile( sourceFile.toString() ) )
120 {
121 String newFileName = file.replaceFirst( ".java$", ".html" );
122
123 transform( sourceFile, this.destDir.resolve( newFileName ), bottom );
124 }
125 }
126 }
127
128
129
130
131
132
133
134 public static boolean isJavaFile( String filename )
135 {
136 return filename.endsWith( ".java" );
137 }
138
139
140
141
142
143
144
145 public static boolean isHtmlFile( String filename )
146 {
147 return filename.endsWith( ".html" );
148 }
149
150
151
152
153 public void setDest( Path dest )
154 {
155 this.destDir = dest;
156 }
157
158
159
160
161 public void setLocale( Locale locale )
162 {
163 this.locale = locale;
164 }
165
166
167
168
169 public void setInputEncoding( String inputEncoding )
170 {
171 this.inputEncoding = inputEncoding;
172 }
173
174
175
176
177 public void setOutputEncoding( String outputEncoding )
178 {
179 this.outputEncoding = outputEncoding;
180 }
181
182
183
184
185 public void setJavadocLinkDir( Path javadocLinkDir )
186 {
187
188 this.javadocLinkDir = javadocLinkDir;
189 }
190
191
192
193
194 public void setTransformer( JavaCodeTransform transformer )
195 {
196 this.transformer = transformer;
197 }
198
199
200
201
202 public void setRevision( String revision )
203 {
204 this.revision = revision;
205 }
206
207
208
209
210 public void setLog( Log log )
211 {
212 this.log = log;
213 }
214
215
216
217
218
219
220
221
222
223
224 public void xref( List<String> sourceDirs, String templateDir, String windowTitle, String docTitle, String bottom )
225 throws IOException, JxrException
226 {
227
228 FileManagerr.html#FileManager">FileManager fileManager = new FileManager();
229 fileManager.setEncoding( inputEncoding );
230
231 PackageManageranager.html#PackageManager">PackageManager pkgmgr = new PackageManager( log, fileManager );
232 pkgmgr.setExcludes( excludes );
233 pkgmgr.setIncludes( includes );
234
235
236 for ( String dir : sourceDirs )
237 {
238 Path path = Paths.get( dir ).toRealPath();
239
240 pkgmgr.process( path );
241
242 processPath( pkgmgr, path, bottom );
243 }
244
245
246 DirectoryIndexertml#DirectoryIndexer">DirectoryIndexer indexer = new DirectoryIndexer( pkgmgr, destDir.toString() );
247 indexer.setOutputEncoding( outputEncoding );
248 indexer.setTemplateDir( templateDir );
249 indexer.setWindowTitle( windowTitle );
250 indexer.setDocTitle( docTitle );
251 indexer.setBottom( bottom );
252 indexer.process( log );
253 }
254
255
256
257
258
259
260
261
262
263
264
265
266
267 private void transform( Path sourceFile, Path destFile, String bottom )
268 throws IOException
269 {
270 log.debug( sourceFile + " -> " + destFile );
271
272
273 Path javadoc = javadocLinkDir != null ? getRelativeLink( destFile.getParent(), javadocLinkDir ) : null;
274 transformer.transform( sourceFile, destFile, locale, inputEncoding, outputEncoding, javadoc,
275 this.revision, bottom );
276 }
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291 private static Path getRelativeLink( Path fromDir, Path toDir )
292 {
293 return fromDir.relativize( toDir );
294 }
295
296 public void setExcludes( String[] excludes )
297 {
298 this.excludes = excludes;
299 }
300
301
302 public void setIncludes( String[] includes )
303 {
304 if ( includes == null )
305 {
306
307 this.includes = DEFAULT_INCLUDES;
308 }
309 else
310 {
311 this.includes = includes;
312 }
313 }
314 }