View Javadoc
1   package org.codehaus.gmavenplus.mojo;
2   
3   import org.apache.maven.plugins.annotations.LifecyclePhase;
4   import org.apache.maven.plugins.annotations.Mojo;
5   import org.apache.maven.plugins.annotations.Parameter;
6   import org.apache.maven.shared.model.fileset.FileSet;
7   
8   
9   /**
10   * This mojo adds Groovy test sources to the project's test sources.
11   *
12   * @author Keegan Witt
13   * @since 1.0-beta-3
14   */
15  @Mojo(name = "addTestSources", defaultPhase = LifecyclePhase.INITIALIZE, threadSafe = true)
16  public class AddTestSourcesMojo extends AbstractGroovySourcesMojo {
17  
18      /**
19       * The Groovy test source files (relative paths).
20       * Default: "${project.basedir}/src/test/groovy/**/*.groovy"
21       */
22      @Parameter
23      protected FileSet[] testSources;
24  
25      /**
26       * Executes this mojo.
27       */
28      @Override
29      public void execute() {
30          for (FileSet testSource : getTestFilesets(testSources, false)) {
31              addTestSourcePath(testSource.getDirectory());
32          }
33      }
34  
35      /**
36       * Adds the specified test source path to the project's test compile sources.
37       *
38       * @param path The test source path to add to the project's test compile sources
39       */
40      protected void addTestSourcePath(final String path) {
41          if (!project.getTestCompileSourceRoots().contains(path)) {
42              getLog().debug("Added test source directory: " + path);
43              project.addTestCompileSourceRoot(path);
44          }
45      }
46  
47  }