View Javadoc

1   /*
2    * @(#)$Id: JavafxdocReport.java 38 2010-03-20 02:40:25Z nderwin $
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   * under the License.
16   */
17  
18  package net.sf.jfxdplugin;
19  
20  import java.io.File;
21  import java.util.List;
22  import java.util.Locale;
23  import org.apache.maven.plugin.MojoExecutionException;
24  import org.apache.maven.plugin.MojoFailureException;
25  import org.apache.maven.reporting.MavenReport;
26  import org.apache.maven.reporting.MavenReportException;
27  import org.codehaus.doxia.sink.Sink;
28  import org.codehaus.plexus.util.StringUtils;
29  
30  /**
31   * Generates documentation for the <code>JavaFX code</code> in a
32   * <b>NON aggregator</b> project using the standard Javafxdoc Tool.
33   * <p>
34   * Based on the Maven Javadoc Plugin version 2.6.
35   *
36   * @author Nathan Erwin
37   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
38   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
39   * @version $Revision: 38 $ $Date: 2010-03-19 22:40:25 -0400 (Fri, 19 Mar 2010) $
40   * @see <a href="http://maven.apache.org/plugins/maven-javadoc-plugin">
41   * http://maven.apache.org/plugins/maven-javadoc-plugin</a>
42   * @since 1.0
43   * @goal javafxdoc
44   * @execute phase="generate-sources"
45   */
46  public class JavafxdocReport extends AbstractJavafxdocMojo implements
47          MavenReport {
48  
49      /**
50       * The description of the Javafxdoc report.
51       *
52       * @parameter expression="${description}"
53       */
54      private String description;
55      /**
56       * The name of the destination directory (used by the site plugin).
57       *
58       * @parameter expression="${destDir}" default-value="apidocs"
59       */
60      private String destDir = "apidocs";
61      /**
62       * The name of the Javafxdoc report.
63       *
64       * @parameter expression="${name}"
65       */
66      private String name;
67      /**
68       * Specifies the destination directory where javafxdoc saves the generated
69       * HTML files.
70       *
71       * @parameter expression="${project.reporting.outputDirectory}/apidocs"
72       * @required
73       */
74      private File reportOutputDirectory;
75  
76      /**
77       * Entry point for the javafxdoc goal.
78       *
79       * @throws MojoExecutionException if an exception occurred during the
80       * execution of the plugin
81       * @throws MojoFailureException not thrown
82       */
83      public void execute() throws MojoExecutionException, MojoFailureException {
84          try {
85              executeReport();
86          } catch (MavenReportException ex) {
87              String message = formatMessage("report.javafxdoc.error", ex.
88                      getMessage());
89              if (isFailOnError()) {
90                  throw new MojoExecutionException(message, ex);
91              }
92              getLog().error(message, ex);
93          } catch (RuntimeException ex) {
94              if (isFailOnError()) {
95                  throw ex;
96              }
97              getLog().error(formatMessage("report.javafxdoc.error",
98                      ex.getMessage()), ex);
99          }
100     }
101 
102     /**
103      * {@inheritDoc}
104      */
105     public void generate(Sink sink, Locale locale) throws MavenReportException {
106         setOutputDirectory(getReportOutputDirectory());
107         executeReport();
108     }
109 
110     /**
111      * {@inheritDoc}
112      */
113     public String getOutputName() {
114         return getDestDir() + "/index";
115     }
116 
117     /**
118      * {@inheritDoc}
119      */
120     public String getCategoryName() {
121         return MavenReport.CATEGORY_PROJECT_REPORTS;
122     }
123 
124     /**
125      * {@inheritDoc}
126      */
127     public String getName(Locale locale) {
128         if (StringUtils.isEmpty(name)) {
129             name = getBundle(locale).getString("report.javafxdoc.name");
130         }
131 
132         return name;
133     }
134 
135     /**
136      * {@inheritDoc}
137      */
138     public String getDescription(Locale locale) {
139         if (StringUtils.isEmpty(description)) {
140             description = getBundle(locale).getString(
141                     "report.javafxdoc.description");
142         }
143 
144         return description;
145     }
146 
147     /**
148      * {@inheritDoc}
149      */
150     public void setReportOutputDirectory(File outputDirectory) {
151         if ((outputDirectory != null) && (!outputDirectory.getAbsolutePath().
152                 endsWith(getDestDir()))) {
153             this.reportOutputDirectory = new File(outputDirectory,
154                     getDestDir());
155         } else {
156             this.reportOutputDirectory = outputDirectory;
157         }
158     }
159 
160     /**
161      * {@inheritDoc}
162      */
163     public File getReportOutputDirectory() {
164         if (reportOutputDirectory == null) {
165             return getOutputDirectory();
166         }
167 
168         return reportOutputDirectory;
169     }
170 
171     /**
172      * {@inheritDoc}
173      */
174     public boolean isExternalReport() {
175         return true;
176     }
177 
178     /**
179      * {@inheritDoc}
180      */
181     public boolean canGenerateReport() {
182         List<String> sourcePaths = getSourcePaths();
183         List<String> files = getFiles(sourcePaths);
184 
185         return canGenerateReport(files);
186     }
187 
188     /**
189      * Returns the destination directory for the HTML output.
190      *
191      * @return the destination directory
192      */
193     public String getDestDir() {
194         return destDir;
195     }
196 
197     /**
198      * Sets the destination directory for the HTML output.
199      *
200      * @param destDir the destination directory
201      */
202     public void setDestDir(String destDir) {
203         this.destDir = destDir;
204     }
205 }