Skip to content

Commit 0cecf8a

Browse files
committed
Revert "Use git-ls-files as the source of file paths for license checks. (#15200)"
This reverts commit 5227fd7.
1 parent 5227fd7 commit 0cecf8a

File tree

8 files changed

+117
-272
lines changed

8 files changed

+117
-272
lines changed

.hgignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
syntax: glob
2+
*/build/*
3+
*.class
4+

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

Lines changed: 0 additions & 84 deletions
This file was deleted.

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.apache.lucene.gradle.plugins.gitinfo;
1818

1919
import org.gradle.api.file.FileSystemLocation;
20-
import org.gradle.api.provider.ListProperty;
2120
import org.gradle.api.provider.MapProperty;
2221
import org.gradle.api.provider.Property;
2322

@@ -33,10 +32,4 @@ public abstract class GitInfoExtension {
3332
* @return Return the location of {@code .git} directory (or file, if worktrees are used).
3433
*/
3534
public abstract Property<FileSystemLocation> getDotGitDir();
36-
37-
/**
38-
* @return Return a set of all versioned and non-versioned files (that are not ignored by {@code
39-
* .gitignore}).
40-
*/
41-
public abstract ListProperty<String> getAllNonIgnoredProjectFiles();
4235
}

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

Lines changed: 35 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,68 +19,55 @@
1919
import java.nio.file.Files;
2020
import java.nio.file.Path;
2121
import org.apache.lucene.gradle.plugins.LuceneGradlePlugin;
22-
import org.apache.lucene.gradle.plugins.globals.LuceneBuildGlobalsExtension;
23-
import org.gradle.api.Action;
2422
import org.gradle.api.GradleException;
2523
import org.gradle.api.Project;
2624
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;
3025

3126
public class GitInfoPlugin extends LuceneGradlePlugin {
3227
@Override
3328
public void apply(Project project) {
3429
applicableToRootProjectOnly(project);
3530

31+
var gitInfoProvider =
32+
project
33+
.getProviders()
34+
.of(
35+
GitInfoValueSource.class,
36+
spec -> {
37+
spec.getParameters().getRootProjectDir().set(project.getProjectDir());
38+
});
39+
3640
var gitInfoExtension =
3741
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();
6542

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();
7644

7745
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+
}
8160

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();
8572
}
8673
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,19 @@
2525
import java.util.regex.Matcher;
2626
import java.util.regex.Pattern;
2727
import javax.inject.Inject;
28+
import org.apache.tools.ant.taskdefs.condition.Os;
2829
import org.gradle.api.GradleException;
30+
import org.gradle.api.file.DirectoryProperty;
2931
import org.gradle.api.provider.ValueSource;
32+
import org.gradle.api.provider.ValueSourceParameters;
33+
import org.gradle.api.services.BuildServiceParameters;
3034
import org.gradle.process.ExecOperations;
3135

3236
public abstract class GitInfoValueSource
33-
implements ValueSource<Map<String, String>, GitValueSourceParameters> {
37+
implements ValueSource<Map<String, String>, GitInfoValueSource.Parameters> {
38+
public abstract static class Parameters implements BuildServiceParameters, ValueSourceParameters {
39+
public abstract DirectoryProperty getRootProjectDir();
40+
}
3441

3542
@Inject
3643
public abstract ExecOperations getExecOps();
@@ -47,9 +54,9 @@ public Map<String, String> obtain() {
4754
spec.setErrorOutput(out);
4855
spec.setIgnoreExitValue(true);
4956

50-
getParameters().configure(spec);
51-
52-
spec.setExecutable(getParameters().getGitExec().get());
57+
spec.setWorkingDir(
58+
getParameters().getRootProjectDir().getAsFile().get().getAbsolutePath());
59+
spec.setExecutable(Os.isFamily(Os.FAMILY_WINDOWS) ? "git.exe" : "git");
5360
spec.args("status", "--porcelain=v2", "--branch");
5461
});
5562
out.flush();

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

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)