View Javadoc
1   /*
2    * Copyright (C) 2011 the original author or authors.
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   */
16  
17  package org.codehaus.gmavenplus.mojo;
18  
19  import org.apache.maven.artifact.DependencyResolutionRequiredException;
20  import org.apache.maven.plugin.MojoExecutionException;
21  import org.apache.maven.plugins.annotations.Mojo;
22  import org.apache.maven.plugins.annotations.Parameter;
23  import org.apache.maven.plugins.annotations.ResolutionScope;
24  import org.apache.maven.shared.model.fileset.FileSet;
25  
26  import java.io.File;
27  import java.lang.reflect.InvocationTargetException;
28  import java.net.MalformedURLException;
29  
30  
31  /**
32   * Generates GroovyDoc for the main sources.
33   *
34   * @author Keegan Witt
35   * @since 1.0-beta-1
36   */
37  @Mojo(name = "groovydoc", requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true)
38  public class GroovyDocMojo extends AbstractGroovyDocMojo {
39  
40      /**
41       * The Groovy source files (relative paths).
42       * Default: "${project.basedir}/src/main/groovy/**/*.groovy"
43       */
44      @Parameter
45      protected FileSet[] sources;
46  
47      /**
48       * The location for the generated API docs.
49       */
50      @Parameter(defaultValue = "${project.build.directory}/gapidocs")
51      protected File groovyDocOutputDirectory;
52  
53      /**
54       * Whether to include Java sources in GroovyDoc generation.
55       *
56       * @since 1.0-beta-2
57       */
58      @Parameter(defaultValue = "true")
59      protected boolean groovyDocJavaSources;
60  
61      /**
62       * Executes this mojo.
63       *
64       * @throws MojoExecutionException If an unexpected problem occurs (causes a "BUILD ERROR" message to be displayed)
65       */
66      @Override
67      public void execute() throws MojoExecutionException {
68          try {
69              try {
70                  getLog().debug("Project compile classpath:\n" + project.getCompileClasspathElements());
71              } catch (DependencyResolutionRequiredException e) {
72                  getLog().debug("Unable to log project compile classpath");
73              }
74              doGroovyDocGeneration(getFilesets(sources, groovyDocJavaSources), project.getRuntimeClasspathElements(), groovyDocOutputDirectory);
75          } catch (ClassNotFoundException e) {
76              throw new MojoExecutionException("Unable to get a Groovy class from classpath (" + e.getMessage() + "). Do you have Groovy as a compile dependency in your project?", e);
77          } catch (InvocationTargetException e) {
78              throw new MojoExecutionException("Error occurred while calling a method on a Groovy class from classpath.", e);
79          } catch (InstantiationException e) {
80              throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e);
81          } catch (IllegalAccessException e) {
82              throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e);
83          } catch (DependencyResolutionRequiredException e) {
84              throw new MojoExecutionException("Compile dependencies weren't resolved.", e);
85          } catch (MalformedURLException e) {
86              throw new MojoExecutionException("Unable to add project compile dependencies to classpath.", e);
87          }
88      }
89  
90  }