|
2 | 2 |
|
3 | 3 | import org.apache.maven.project.MavenProject; |
4 | 4 |
|
| 5 | +import java.io.File; |
5 | 6 | import java.io.IOException; |
6 | 7 | import java.nio.file.Files; |
7 | 8 | import java.nio.file.Path; |
| 9 | +import java.util.ArrayList; |
| 10 | +import java.util.List; |
8 | 11 | import java.util.function.Predicate; |
9 | 12 |
|
10 | 13 | public class NonEmptyProjectCheck implements Predicate<MavenProject> { |
11 | 14 |
|
12 | 15 | @SuppressWarnings("unchecked") |
13 | 16 | @Override |
14 | 17 | public boolean test(MavenProject project) { |
15 | | - return project.getTestCompileSourceRoots().stream().anyMatch(this::exists) |
16 | | - && project.getCompileSourceRoots().stream().anyMatch(this::exists); |
| 18 | + var baseDir = project.getBasedir() != null ? project.getBasedir() : new File(""); |
| 19 | + return augmentTests(baseDir, project.getTestCompileSourceRoots()).stream().anyMatch(this::exists) |
| 20 | + && augmentMain(baseDir, project.getCompileSourceRoots()).stream().anyMatch(this::exists); |
17 | 21 | } |
18 | | - |
| 22 | + |
| 23 | + // maven projects for other jvm languages are often not properly configured |
| 24 | + // and don't declare their source directories |
| 25 | + private List<String> augmentTests(File basedir, List<String> existing) { |
| 26 | + var groovy = basedir.toPath().resolve("src/test/groovy"); |
| 27 | + var updated = new ArrayList<>(existing); |
| 28 | + updated.add(groovy.toAbsolutePath().toString()); |
| 29 | + return updated; |
| 30 | + } |
| 31 | + |
| 32 | + private List<String> augmentMain(File basedir, List<String> existing) { |
| 33 | + var groovy = basedir.toPath().resolve("src/main/groovy"); |
| 34 | + var updated = new ArrayList<>(existing); |
| 35 | + updated.add(groovy.toAbsolutePath().toString()); |
| 36 | + return updated; |
| 37 | + } |
| 38 | + |
19 | 39 | private boolean exists(String root) { |
20 | 40 | var p = Path.of(root); |
21 | 41 | try { |
|
0 commit comments