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 sources to the project's sources.
11   *
12   * @author Keegan Witt
13   * @since 1.0-beta-1
14   */
15  @Mojo(name = "addSources", defaultPhase = LifecyclePhase.INITIALIZE, threadSafe = true)
16  public class AddSourcesMojo extends AbstractGroovySourcesMojo {
17  
18      /**
19       * The Groovy source files (relative paths).
20       * Default: "${project.basedir}/src/main/groovy/**/*.groovy"
21       */
22      @Parameter
23      protected FileSet[] sources;
24  
25      /**
26       * Executes this mojo.
27       */
28      @Override
29      public void execute() {
30          for (FileSet source : getFilesets(sources, false)) {
31              addSourcePath(source.getDirectory());
32          }
33      }
34  
35      /**
36       * Adds the specified source path to the project's main compile sources.
37       *
38       * @param path The source path to add to the project's main compile sources
39       */
40      protected void addSourcePath(final String path) {
41          if (!project.getCompileSourceRoots().contains(path)) {
42              getLog().debug("Added source directory: " + path);
43              project.addCompileSourceRoot(path);
44          }
45      }
46  
47  }