View Javadoc

1   package org.scala_tools.maven;
2   
3   import java.io.File;
4   
5   import org.apache.maven.plugin.AbstractMojo;
6   import org.apache.maven.plugin.MojoExecutionException;
7   import org.apache.maven.project.MavenProject;
8   
9   /**
10   * Add more source directories to the POM.
11   *
12   * @executionStrategy always
13   * @goal add-source
14   * @phase generate-sources
15   * @requiresDirectInvocation false
16   */
17  public class AddSourceMojo extends AbstractMojo {
18  
19  	/**
20  	 * @parameter expression="${project}"
21  	 * @required
22  	 * @readonly
23  	 */
24  	private MavenProject project;
25  
26      /**
27       * @parameter expression="${project.build.sourceDirectory}/../scala"
28       */
29      protected File sourceDir;
30  
31      /**
32       * @parameter expression="${project.build.testSourceDirectory}/../scala"
33       */
34      protected File testSourceDir;
35  
36      public void execute() throws MojoExecutionException {
37      	try {
38  	    	if (sourceDir != null) {
39  	        	String path = sourceDir.getCanonicalPath();
40  	        	if (!project.getCompileSourceRoots().contains(path)) {
41  	        		getLog().info("Add Source directory: " + path);
42  	        		project.addCompileSourceRoot(path);
43  	        	}
44  			}
45  	    	if (testSourceDir != null) {
46  	        	String path = testSourceDir.getCanonicalPath();
47  	        	if (!project.getTestCompileSourceRoots().contains(path)) {
48  	        		getLog().info("Add Test Source directory: " + path);
49  	        		project.addCompileSourceRoot(path);
50  	        	}
51  			}
52      	} catch(Exception exc) {
53      		getLog().warn(exc);
54      	}
55  	}
56  }