|
19 | 19 | import java.nio.file.Files; |
20 | 20 | import java.nio.file.Path; |
21 | 21 | import org.apache.lucene.gradle.plugins.LuceneGradlePlugin; |
22 | | -import org.apache.lucene.gradle.plugins.globals.LuceneBuildGlobalsExtension; |
23 | | -import org.gradle.api.Action; |
24 | 22 | import org.gradle.api.GradleException; |
25 | 23 | import org.gradle.api.Project; |
26 | 24 | import org.gradle.api.file.Directory; |
27 | | -import org.gradle.api.file.FileSystemLocation; |
28 | | -import org.gradle.api.provider.Property; |
29 | | -import org.gradle.api.provider.ValueSourceSpec; |
30 | 25 |
|
31 | 26 | public class GitInfoPlugin extends LuceneGradlePlugin { |
32 | 27 | @Override |
33 | 28 | public void apply(Project project) { |
34 | 29 | applicableToRootProjectOnly(project); |
35 | 30 |
|
| 31 | + var gitInfoProvider = |
| 32 | + project |
| 33 | + .getProviders() |
| 34 | + .of( |
| 35 | + GitInfoValueSource.class, |
| 36 | + spec -> { |
| 37 | + spec.getParameters().getRootProjectDir().set(project.getProjectDir()); |
| 38 | + }); |
| 39 | + |
36 | 40 | var gitInfoExtension = |
37 | 41 | project.getExtensions().create(GitInfoExtension.NAME, GitInfoExtension.class); |
38 | | - var providers = project.getProviders(); |
39 | | - |
40 | | - Property<FileSystemLocation> dotGitDir = gitInfoExtension.getDotGitDir(); |
41 | | - dotGitDir |
42 | | - .convention( |
43 | | - providers.provider( |
44 | | - () -> { |
45 | | - Directory projectDirectory = |
46 | | - project.getRootProject().getLayout().getProjectDirectory(); |
47 | | - Path gitLocation = projectDirectory.getAsFile().toPath().resolve(".git"); |
48 | | - if (!Files.exists(gitLocation)) { |
49 | | - // don't return anything from the provider if we can't locate the .git |
50 | | - // folder. This will result in the property returning false from isPresent. |
51 | | - return null; |
52 | | - } |
53 | | - |
54 | | - if (Files.isDirectory(gitLocation)) { |
55 | | - return projectDirectory.dir(".git"); |
56 | | - } else if (Files.isRegularFile(gitLocation)) { |
57 | | - return projectDirectory.file(".git"); |
58 | | - } else { |
59 | | - throw new GradleException( |
60 | | - "Panic, .git location not a directory or file: " |
61 | | - + gitLocation.toAbsolutePath()); |
62 | | - } |
63 | | - })) |
64 | | - .finalizeValueOnRead(); |
65 | 42 |
|
66 | | - var gitExec = |
67 | | - project.getExtensions().getByType(LuceneBuildGlobalsExtension.class).externalTool("git"); |
68 | | - |
69 | | - Action<ValueSourceSpec<GitValueSourceParameters>> configureGitParams = |
70 | | - spec -> { |
71 | | - var params = spec.getParameters(); |
72 | | - params.getRootProjectDir().set(project.getProjectDir()); |
73 | | - params.getGitExec().set(gitExec); |
74 | | - params.getDotDir().set(dotGitDir); |
75 | | - }; |
| 43 | + gitInfoExtension.getGitInfo().value(gitInfoProvider).finalizeValueOnRead(); |
76 | 44 |
|
77 | 45 | gitInfoExtension |
78 | | - .getGitInfo() |
79 | | - .value(providers.of(GitInfoValueSource.class, configureGitParams)) |
80 | | - .finalizeValueOnRead(); |
| 46 | + .getDotGitDir() |
| 47 | + .convention( |
| 48 | + project |
| 49 | + .getProviders() |
| 50 | + .provider( |
| 51 | + () -> { |
| 52 | + Directory projectDirectory = |
| 53 | + project.getRootProject().getLayout().getProjectDirectory(); |
| 54 | + Path gitLocation = projectDirectory.getAsFile().toPath().resolve(".git"); |
| 55 | + if (!Files.exists(gitLocation)) { |
| 56 | + // don't return anything from the provider if we can't locate the .git |
| 57 | + // folder. This will result in the property returning false from isPresent. |
| 58 | + return null; |
| 59 | + } |
81 | 60 |
|
82 | | - gitInfoExtension |
83 | | - .getAllNonIgnoredProjectFiles() |
84 | | - .value(providers.of(GitFileListValueSource.class, configureGitParams)); |
| 61 | + if (Files.isDirectory(gitLocation)) { |
| 62 | + return projectDirectory.dir(".git"); |
| 63 | + } else if (Files.isRegularFile(gitLocation)) { |
| 64 | + return projectDirectory.file(".git"); |
| 65 | + } else { |
| 66 | + throw new GradleException( |
| 67 | + "Panic, .git location not a directory or file: " |
| 68 | + + gitLocation.toAbsolutePath()); |
| 69 | + } |
| 70 | + })) |
| 71 | + .finalizeValueOnRead(); |
85 | 72 | } |
86 | 73 | } |
0 commit comments