/
AddSourceMojo.java
67 lines (59 loc) · 2.04 KB
/
AddSourceMojo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package org_scala_tools_maven;
import java.io.File;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
/**
* Add more source directories to the POM.
*
* @executionStrategy always
* @goal add-source
* @phase initialize
* @requiresDirectInvocation false
*/
public class AddSourceMojo extends AbstractMojo {
/**
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;
/**
* The directory in which scala source is found
*
* @parameter expression="${project.build.sourceDirectory}/../scala"
*/
protected File sourceDir;
/**
* The directory in which testing scala source is found
*
* @parameter expression="${project.build.testSourceDirectory}/../scala"
*/
protected File testSourceDir;
/**
* Should use CanonicalPath to normalize path (true => getCanonicalPath, false => getAbsolutePath)
* @see https://github.com/davidB/maven-scala-plugin/issues/50
* @parameter expression="${maven.scala.useCanonicalPath}" default-value="true"
*/
protected boolean useCanonicalPath = true;
public void execute() throws MojoExecutionException {
try {
if (sourceDir != null) {
String path = FileUtils.pathOf(sourceDir, useCanonicalPath);
if (!project.getCompileSourceRoots().contains(path)) {
getLog().info("Add Source directory: " + path);
project.addCompileSourceRoot(path);
}
}
if (testSourceDir != null) {
String path = FileUtils.pathOf(testSourceDir, useCanonicalPath);
if (!project.getTestCompileSourceRoots().contains(path)) {
getLog().info("Add Test Source directory: " + path);
project.addTestCompileSourceRoot(path);
}
}
} catch(Exception exc) {
getLog().warn(exc);
}
}
}