Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit b60bb8e

Browse files
authored
Merge pull request #49 from cwiejack/master
Add ability to add additional source and test-source folders
2 parents 22c20bf + 61f5173 commit b60bb8e

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

src/main/java/com/mysema/maven/apt/AbstractProcessorMojo.java

+47-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.concurrent.Executors;
2323
import java.util.concurrent.Future;
2424

25+
import com.google.common.base.Joiner;
2526
import org.apache.commons.io.FileUtils;
2627
import org.apache.maven.artifact.Artifact;
2728
import org.apache.maven.artifact.DependencyResolutionRequiredException;
@@ -111,6 +112,20 @@ public abstract class AbstractProcessorMojo extends AbstractMojo {
111112
*/
112113
private List<Artifact> pluginArtifacts;
113114

115+
/**
116+
* A list of additional source roots for the apt processor
117+
*
118+
* @parameter required=false
119+
*/
120+
private List<String> additionalSourceRoots;
121+
122+
/**
123+
* A list of additional test source roots for the apt processor
124+
*
125+
* @parameter required=false
126+
*/
127+
private List<String> additionalTestSourceRoots;
128+
114129
/**
115130
* @parameter
116131
*/
@@ -422,17 +437,46 @@ protected Set<File> getSourceDirectories() {
422437
File outputDirectory = getOutputDirectory();
423438
String outputPath = outputDirectory.getAbsolutePath();
424439
Set<File> directories = new HashSet<File>();
425-
List<String> directoryNames = isForTest() ? project.getTestCompileSourceRoots()
426-
: project.getCompileSourceRoots();
440+
List<String> directoryNames = isForTest() ? getTestCompileSourceRoots()
441+
: getCompileSourceRoots();
427442
for (String name : directoryNames) {
428443
File file = new File(name);
429-
if (!file.getAbsolutePath().equals(outputPath) && file.exists()) {
444+
if (!file.getAbsolutePath().equals(outputPath) && file.exists() && file.isDirectory()) {
430445
directories.add(file);
431446
}
432447
}
433448
return directories;
434449
}
435450

451+
452+
private List<String> getTestCompileSourceRoots() {
453+
@SuppressWarnings("unchecked")
454+
final List<String> testCompileSourceRoots = project.getTestCompileSourceRoots();
455+
if (additionalTestSourceRoots == null) {
456+
return testCompileSourceRoots;
457+
}
458+
if (getLog().isDebugEnabled()) {
459+
getLog().debug("Adding additional test source roots: " + Joiner.on(", ").skipNulls().join(additionalTestSourceRoots));
460+
}
461+
List<String> sourceRoots = new ArrayList<String>(testCompileSourceRoots);
462+
sourceRoots.addAll(additionalTestSourceRoots);
463+
return sourceRoots;
464+
}
465+
466+
private List<String> getCompileSourceRoots() {
467+
@SuppressWarnings("unchecked")
468+
final List<String> compileSourceRoots = project.getCompileSourceRoots();
469+
if (additionalSourceRoots == null) {
470+
return compileSourceRoots;
471+
}
472+
if (getLog().isDebugEnabled()) {
473+
getLog().debug("Adding additional source roots: " + Joiner.on(", ").skipNulls().join(additionalSourceRoots));
474+
}
475+
List<String> sourceRoots = new ArrayList<String>(compileSourceRoots);
476+
sourceRoots.addAll(additionalSourceRoots);
477+
return sourceRoots;
478+
}
479+
436480
protected boolean isForTest() {
437481
return false;
438482
}

0 commit comments

Comments
 (0)