Skip to content

Commit 693bb69

Browse files
authored
Fix the build on missing .git. (#15204)
1 parent 5d82ac8 commit 693bb69

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/gitinfo/GitInfoPlugin.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public void apply(Project project) {
4646
project.getRootProject().getLayout().getProjectDirectory();
4747
Path gitLocation = projectDirectory.getAsFile().toPath().resolve(".git");
4848
if (!Files.exists(gitLocation)) {
49+
project
50+
.getLogger()
51+
.warn(
52+
"This seems to be a source bundle of Lucene (not a git clone). Some tasks may be "
53+
+ "skipped as they rely on .git to be present (you can run 'git init' if you "
54+
+ "like or use a full git clone).");
55+
4956
// don't return anything from the provider if we can't locate the .git
5057
// folder. This will result in the property returning false from isPresent.
5158
return null;
@@ -61,7 +68,7 @@ public void apply(Project project) {
6168
+ gitLocation.toAbsolutePath());
6269
}
6370
}))
64-
.finalizeValueOnRead();
71+
.finalizeValue();
6572

6673
var gitExec =
6774
project.getExtensions().getByType(LuceneBuildGlobalsExtension.class).externalTool("git");

build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/gitinfo/GitInfoValueSource.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ public abstract class GitInfoValueSource
3737

3838
@Override
3939
public Map<String, String> obtain() {
40+
if (!getParameters().getDotDir().isPresent()) {
41+
return Map.ofEntries(
42+
Map.entry("git.commit", "unknown"),
43+
Map.entry("git.commit-short", "unknown"),
44+
Map.entry("git.clean", "false"),
45+
Map.entry("git.changed-files", "not a git checkout"));
46+
}
47+
4048
try (var baos = new ByteArrayOutputStream();
4149
var out = new BufferedOutputStream(baos)) {
4250
var result =

build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/licenses/CheckLicensesPlugin.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ private void configureCheckLicenses(CheckLicensesTask task) {
5555
Project project = task.getProject();
5656

5757
assert project.getRootProject() == project;
58-
var allNonIgnoredFiles =
59-
project.getExtensions().getByType(GitInfoExtension.class).getAllNonIgnoredProjectFiles();
58+
GitInfoExtension gitInfoExt = project.getExtensions().getByType(GitInfoExtension.class);
59+
60+
task.setEnabled(gitInfoExt.getDotGitDir().isPresent());
61+
62+
var allNonIgnoredFiles = gitInfoExt.getAllNonIgnoredProjectFiles();
6063

6164
task.getReportFile().set(project.getLayout().getBuildDirectory().file("licenses-report.txt"));
6265

0 commit comments

Comments
 (0)