1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package net.sf.maventaglib;
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.text.MessageFormat;
29 import java.util.HashSet;
30 import java.util.List;
31 import java.util.Locale;
32 import java.util.Set;
33
34 import org.apache.maven.plugin.MojoExecutionException;
35 import org.apache.maven.plugins.annotations.Mojo;
36 import org.apache.maven.plugins.annotations.Parameter;
37 import org.apache.maven.reporting.AbstractMavenReport;
38 import org.apache.maven.reporting.MavenReport;
39 import org.apache.maven.reporting.MavenReportException;
40 import org.codehaus.plexus.util.FileUtils;
41
42 import com.sun.tlddoc.TLDDocGenerator;
43
44
45
46
47
48
49
50 @Mojo(name="taglibdoc")
51 public class TaglibdocMojo extends AbstractMavenReport implements MavenReport
52 {
53
54
55
56
57 @Parameter(defaultValue="${project.name} Tag library documentation")
58 private String title;
59
60
61
62
63 @Parameter(defaultValue="${project.reporting.outputDirectory}/tlddoc")
64 private File tldDocDir;
65
66
67
68
69
70 @Parameter(alias="taglib.src.dir", defaultValue="src/main/resources/META-INF")
71 private File srcDir;
72
73
74
75
76 @Parameter
77 private boolean dontRecurseIntoSubdirs;
78
79
80
81
82 @Parameter
83 private File xsltDir;
84
85
86
87
88 @Override
89 public void execute() throws MojoExecutionException
90 {
91 getLog().debug(MessageFormat.format(Messages.getString("Taglib.generating.tlddoc"),
92 srcDir.getAbsolutePath() ));
93 TLDDocGenerator generator = new TLDDocGenerator();
94 generator.setOutputDirectory(tldDocDir);
95 generator.setQuiet(true);
96 generator.setWindowTitle(this.title);
97 if (xsltDir != null)
98 {
99 generator.setXSLTDirectory(xsltDir);
100 }
101
102 String searchprefix = dontRecurseIntoSubdirs ? "" : "**/";
103
104 if (!srcDir.isDirectory())
105 {
106 throw new MojoExecutionException(MessageFormat.format(
107 Messages.getString("Taglib.notadir"),
108 srcDir.getAbsolutePath() ));
109 }
110
111 try
112 {
113
114 List<File> tlds = FileUtils.getFiles(srcDir, searchprefix + "*.tld", null);
115 for (File tld : tlds)
116 {
117 generator.addTLD(tld);
118 }
119
120
121 List<File> tags = FileUtils.getFiles(srcDir, searchprefix + "*.tag", null);
122 tags.addAll(FileUtils.getFiles(srcDir, searchprefix + "*.tagx", null));
123
124 if (!tags.isEmpty())
125 {
126 Set<File> directories = new HashSet<>();
127 for (File tag : tags)
128 {
129 directories.add(tag.getParentFile());
130 }
131 for (File directory : directories)
132 {
133 generator.addTagDir(directory);
134 }
135 }
136
137 }
138 catch (IOException e)
139 {
140 throw new MojoExecutionException(e.getMessage(), e);
141 }
142
143 try
144 {
145 generator.generate();
146 }
147 catch (Throwable e)
148 {
149 getLog().error(MessageFormat.format(Messages.getString("Taglib.exception"),
150 e.getClass(), e.getMessage() ), e);
151 }
152 }
153
154
155
156
157 @Override
158 protected void executeReport(Locale locale) throws MavenReportException
159 {
160 try
161 {
162 execute();
163 }
164 catch (MojoExecutionException e)
165 {
166 throw new MavenReportException(e.getMessage(), e);
167 }
168
169 }
170
171
172
173
174 public String getOutputName()
175 {
176 return "tlddoc/index";
177 }
178
179
180
181
182 public String getName(Locale locale)
183 {
184 return Messages.getString(locale, "Taglibdoc.name");
185 }
186
187
188
189
190 public String getDescription(Locale locale)
191 {
192 return Messages.getString(locale, "Taglibdoc.description");
193 }
194
195
196
197
198 @Override
199 public boolean isExternalReport()
200 {
201 return true;
202 }
203
204
205
206
207 @Override
208 public boolean canGenerateReport()
209 {
210
211 if (!srcDir.isDirectory())
212 {
213 return false;
214 }
215
216 try
217 {
218 boolean hasTldFiles = FileUtils.getFiles(srcDir, "**/*.tld", null).size() > 0;
219 boolean hasTagFiles = FileUtils.getFiles(srcDir, "**/*.tag", null).size() > 0;
220 return hasTldFiles || hasTagFiles;
221 }
222 catch (IOException e)
223 {
224 getLog().error(e.getMessage(), e);
225 }
226 return false;
227
228 }
229
230 }