|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -package org.gradlex.javamodule.dependencies.initialization; |
| 17 | +package org.gradlex.javamodule.dependencies.internal.utils; |
18 | 18 |
|
19 | 19 | import org.gradle.api.provider.Property; |
20 | 20 | import org.gradle.api.provider.SetProperty; |
21 | 21 | import org.gradle.api.provider.ValueSource; |
22 | 22 | import org.gradle.api.provider.ValueSourceParameters; |
23 | 23 |
|
24 | 24 | import java.io.File; |
25 | | -import java.io.FileFilter; |
26 | 25 | import java.io.IOException; |
27 | | -import java.nio.file.DirectoryStream; |
28 | 26 | import java.nio.file.Files; |
29 | 27 | import java.nio.file.Path; |
30 | | -import java.nio.file.attribute.BasicFileAttributes; |
31 | | -import java.util.Arrays; |
32 | 28 | import java.util.List; |
33 | | -import java.util.function.BiPredicate; |
34 | 29 | import java.util.stream.Collectors; |
35 | 30 | import java.util.stream.Stream; |
36 | 31 |
|
37 | | -public abstract class ValueSourceDirectoryListing implements ValueSource<List<String>, ValueSourceDirectoryListing.DirectoryListingParameter> { |
| 32 | +public abstract class ValueModuleDirectoryListing implements ValueSource<List<String>, ValueModuleDirectoryListing.Parameter> { |
38 | 33 |
|
| 34 | + public interface Parameter extends ValueSourceParameters { |
| 35 | + Property<File> getDir(); |
| 36 | + SetProperty<String> getExplicitlyConfiguredFolders(); |
| 37 | + SetProperty<String> getExclusions(); |
| 38 | + Property<Boolean> getRequiresBuildFile(); |
| 39 | + } |
39 | 40 |
|
40 | 41 | @Override |
41 | 42 | public List<String> obtain() { |
42 | 43 | Path path = getParameters().getDir().get().toPath(); |
43 | | - File file = getParameters().getDir().get(); |
44 | | - try (Stream<Path> directoryStream = Files.find(path, 1, new BiPredicate<Path, BasicFileAttributes>() { |
45 | | - @Override |
46 | | - public boolean test(Path path, BasicFileAttributes basicFileAttributes) { |
47 | | - return basicFileAttributes.isDirectory(); |
48 | | - } |
49 | | - })) { |
50 | | - return directoryStream.filter(x -> !getParameters().getExclusions().get().contains(x.getFileName().toString())) |
51 | | - .filter(x -> getParameters().getRegexExclusions().get().stream().noneMatch(r -> x.getFileName().toString().matches(r))) |
| 44 | + try (Stream<Path> directoryStream = Files.find(path, 1, (unused, basicFileAttributes) -> basicFileAttributes.isDirectory())) { |
| 45 | + return directoryStream |
| 46 | + .filter(x -> !getParameters().getExplicitlyConfiguredFolders().get().contains(x.getFileName().toString())) |
| 47 | + .filter(x -> getParameters().getExclusions().get().stream().noneMatch(r -> x.getFileName().toString().matches(r))) |
52 | 48 | .filter(x -> checkBuildFile(x, getParameters())) |
53 | 49 | .map(x -> x.getFileName().toString()) |
54 | 50 | .sorted() |
55 | 51 | .collect(Collectors.toList()); |
56 | 52 |
|
57 | 53 | } catch (IOException e) { |
58 | | - throw new RuntimeException("Failed on " + file, e); |
| 54 | + throw new RuntimeException("Failed to inspect: " + path, e); |
59 | 55 | } |
60 | | - |
61 | | - |
62 | 56 | } |
63 | 57 |
|
64 | | - private boolean checkBuildFile(Path x, DirectoryListingParameter parameters) { |
| 58 | + private boolean checkBuildFile(Path x, Parameter parameters) { |
65 | 59 | if (!parameters.getRequiresBuildFile().get()) { |
66 | 60 | return true; |
67 | 61 | } |
68 | 62 | return Files.isRegularFile(x.resolve("build.gradle.kts")) || Files.isRegularFile(x.resolve("build.gradle")); |
69 | 63 | } |
70 | | - |
71 | | - interface DirectoryListingParameter extends ValueSourceParameters { |
72 | | - |
73 | | - Property<Boolean> getRequiresBuildFile(); |
74 | | - |
75 | | - Property<File> getDir(); |
76 | | - |
77 | | - SetProperty<String> getExclusions(); |
78 | | - |
79 | | - SetProperty<String> getRegexExclusions(); |
80 | | - |
81 | | - } |
82 | 64 | } |
0 commit comments