Skip to content

Commit 73400f8

Browse files
breskebyelasticsearchmachine
andauthored
[Gradle] Fix configuration cache issues in distribution subproject (#124281) (#125101)
* [Gradle] Fix configuration cache issues in distribution subproject - do not reference tasks from task execution time - do not use project references at task execution time - use layout.settingsDir for resolving root project dir * Fix test coverage * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
1 parent bdbc5d9 commit 73400f8

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionArchiveCheckPlugin.java

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import org.gradle.api.Task;
2020
import org.gradle.api.file.ArchiveOperations;
2121
import org.gradle.api.plugins.BasePlugin;
22+
import org.gradle.api.provider.ListProperty;
23+
import org.gradle.api.provider.Provider;
2224
import org.gradle.api.tasks.Copy;
2325
import org.gradle.api.tasks.TaskProvider;
2426

@@ -103,22 +105,26 @@ private static TaskProvider<Task> registerCheckMlCppNoticeTask(
103105
) {
104106
TaskProvider<Task> checkMlCppNoticeTask = project.getTasks().register("checkMlCppNotice", task -> {
105107
task.dependsOn(checkExtraction);
108+
final Provider<Path> noticePath = checkExtraction.map(
109+
c -> c.getDestinationDir()
110+
.toPath()
111+
.resolve("elasticsearch-" + VersionProperties.getElasticsearch() + "/modules/x-pack-ml/NOTICE.txt")
112+
);
113+
ListProperty<String> expectedMlLicenses = extension.expectedMlLicenses;
106114
task.doLast(new Action<Task>() {
107115
@Override
108116
public void execute(Task task) {
109117
// this is just a small sample from the C++ notices,
110118
// the idea being that if we've added these lines we've probably added all the required lines
111-
final List<String> expectedLines = extension.expectedMlLicenses.get();
112-
final Path noticePath = checkExtraction.get()
113-
.getDestinationDir()
114-
.toPath()
115-
.resolve("elasticsearch-" + VersionProperties.getElasticsearch() + "/modules/x-pack-ml/NOTICE.txt");
119+
final List<String> expectedLines = expectedMlLicenses.get();
116120
final List<String> actualLines;
117121
try {
118-
actualLines = Files.readAllLines(noticePath);
122+
actualLines = Files.readAllLines(noticePath.get());
119123
for (final String expectedLine : expectedLines) {
120124
if (actualLines.contains(expectedLine) == false) {
121-
throw new GradleException("expected [" + noticePath + " to contain [" + expectedLine + "] but it did not");
125+
throw new GradleException(
126+
"expected [" + noticePath.get() + " to contain [" + expectedLine + "] but it did not"
127+
);
122128
}
123129
}
124130
} catch (IOException ioException) {
@@ -133,43 +139,37 @@ public void execute(Task task) {
133139
private TaskProvider<Task> registerCheckNoticeTask(Project project, TaskProvider<Copy> checkExtraction) {
134140
return project.getTasks().register("checkNotice", task -> {
135141
task.dependsOn(checkExtraction);
136-
task.doLast(new Action<Task>() {
137-
@Override
138-
public void execute(Task task) {
139-
final List<String> noticeLines = Arrays.asList("Elasticsearch", "Copyright 2009-2024 Elasticsearch");
140-
final Path noticePath = checkExtraction.get()
141-
.getDestinationDir()
142-
.toPath()
143-
.resolve("elasticsearch-" + VersionProperties.getElasticsearch() + "/NOTICE.txt");
144-
assertLinesInFile(noticePath, noticeLines);
145-
}
142+
var noticePath = checkExtraction.map(
143+
copy -> copy.getDestinationDir().toPath().resolve("elasticsearch-" + VersionProperties.getElasticsearch() + "/NOTICE.txt")
144+
);
145+
task.doLast(t -> {
146+
final List<String> noticeLines = Arrays.asList("Elasticsearch", "Copyright 2009-2024 Elasticsearch");
147+
assertLinesInFile(noticePath.get(), noticeLines);
146148
});
147149
});
148150
}
149151

150152
private TaskProvider<Task> registerCheckLicenseTask(Project project, TaskProvider<Copy> checkExtraction) {
151153
TaskProvider<Task> checkLicense = project.getTasks().register("checkLicense", task -> {
152154
task.dependsOn(checkExtraction);
153-
task.doLast(new Action<Task>() {
154-
@Override
155-
public void execute(Task task) {
156-
String licenseFilename = null;
157-
if (project.getName().contains("oss-") || project.getName().equals("integ-test-zip")) {
158-
licenseFilename = "AGPL-3.0+SSPL-1.0+ELASTIC-LICENSE-2.0.txt";
159-
} else {
160-
licenseFilename = "ELASTIC-LICENSE-2.0.txt";
161-
}
162-
final List<String> licenseLines;
163-
try {
164-
licenseLines = Files.readAllLines(project.getRootDir().toPath().resolve("licenses/" + licenseFilename));
165-
final Path licensePath = checkExtraction.get()
166-
.getDestinationDir()
167-
.toPath()
168-
.resolve("elasticsearch-" + VersionProperties.getElasticsearch() + "/LICENSE.txt");
169-
assertLinesInFile(licensePath, licenseLines);
170-
} catch (IOException ioException) {
171-
ioException.printStackTrace();
172-
}
155+
String projectName = project.getName();
156+
Provider<Path> licensePathProvider = checkExtraction.map(
157+
copy -> copy.getDestinationDir().toPath().resolve("elasticsearch-" + VersionProperties.getElasticsearch() + "/LICENSE.txt")
158+
);
159+
File rootDir = project.getLayout().getSettingsDirectory().getAsFile();
160+
task.doLast(t -> {
161+
String licenseFilename = null;
162+
if (projectName.contains("oss-") || projectName.equals("integ-test-zip")) {
163+
licenseFilename = "AGPL-3.0+SSPL-1.0+ELASTIC-LICENSE-2.0.txt";
164+
} else {
165+
licenseFilename = "ELASTIC-LICENSE-2.0.txt";
166+
}
167+
final List<String> licenseLines;
168+
try {
169+
licenseLines = Files.readAllLines(rootDir.toPath().resolve("licenses/" + licenseFilename));
170+
assertLinesInFile(licensePathProvider.get(), licenseLines);
171+
} catch (IOException ioException) {
172+
ioException.printStackTrace();
173173
}
174174
});
175175
});

0 commit comments

Comments
 (0)