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 test sources.
17   *
18   * @author Keegan Witt
19   * @since 1.0-beta-1
20   */
21  @Mojo(name = "groovydocTests", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true)
22  public class GroovyDocTestsMojo extends AbstractGroovyDocMojo {
23  
24      /**
25       * The Groovy test source files (relative paths).
26       * Default: "${project.basedir}/src/test/groovy/**/*.groovy"
27       */
28      @Parameter
29      protected FileSet[] testSources;
30  
31      /**
32       * The location for the generated test API docs.
33       */
34      @Parameter(defaultValue = "${project.build.directory}/testgapidocs")
35      protected File testGroovyDocOutputDirectory;
36  
37      /**
38       * Whether to include test Java sources in GroovyDoc generation.
39       *
40       * @since 1.7
41       */
42      @Parameter(defaultValue = "true")
43      protected boolean testGroovyDocJavaSources;
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 test classpath:\n" + project.getCompileClasspathElements());
55              } catch (DependencyResolutionRequiredException e) {
56                  getLog().debug("Unable to log project tset classpath");
57              }
58              doGroovyDocGeneration(getTestFilesets(testSources, testGroovyDocJavaSources), project.getTestClasspathElements(), testGroovyDocOutputDirectory);
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("Test dependencies weren't resolved.", e);
69          } catch (MalformedURLException e) {
70              throw new MojoExecutionException("Unable to add project test dependencies to classpath.", e);
71          }
72      }
73  
74  }