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