-
-
Notifications
You must be signed in to change notification settings - Fork 151
/
AddSourceMojo.java
65 lines (58 loc) · 2.11 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
/*
* This is free and unencumbered software released into the public domain.
* See UNLICENSE.
*/
package scala_maven;
import java.io.File;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import util.FileUtils;
/** Add more source directories to the POM. */
@Mojo(
name = "add-source",
executionStrategy = "always",
defaultPhase = LifecyclePhase.INITIALIZE,
threadSafe = true)
public class AddSourceMojo extends AbstractMojo {
/** The maven project */
@Parameter(property = "project", required = true, readonly = true)
private MavenProject project;
/** The directory in which scala source is found */
@Parameter(defaultValue = "${project.build.sourceDirectory}/../scala")
private File sourceDir;
/** The directory in which testing scala source is found */
@Parameter(defaultValue = "${project.build.testSourceDirectory}/../scala")
private File testSourceDir;
/**
* Should use CanonicalPath to normalize path (true => getCanonicalPath, false =>
* getAbsolutePath)
*
* @see <a href="https://github.com/davidB/maven-scala-plugin/issues/50">#50</a>
*/
@Parameter(property = "maven.scala.useCanonicalPath", defaultValue = "true")
private boolean useCanonicalPath;
@Override
public void execute() {
try {
if (sourceDir != null) {
final String path = FileUtils.pathOf(sourceDir, useCanonicalPath);
if (!project.getCompileSourceRoots().contains(path)) {
getLog().info("Add Source directory: " + path);
project.addCompileSourceRoot(path);
}
}
if (testSourceDir != null) {
final String path = FileUtils.pathOf(testSourceDir, useCanonicalPath);
if (!project.getTestCompileSourceRoots().contains(path)) {
getLog().info("Add Test Source directory: " + path);
project.addTestCompileSourceRoot(path);
}
}
} catch (final Exception exc) {
getLog().warn(exc);
}
}
}