Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.gradle.api.Task;
import org.gradle.api.file.ArchiveOperations;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Copy;
import org.gradle.api.tasks.TaskProvider;

Expand Down Expand Up @@ -103,22 +105,26 @@ private static TaskProvider<Task> registerCheckMlCppNoticeTask(
) {
TaskProvider<Task> checkMlCppNoticeTask = project.getTasks().register("checkMlCppNotice", task -> {
task.dependsOn(checkExtraction);
final Provider<Path> noticePath = checkExtraction.map(
c -> c.getDestinationDir()
.toPath()
.resolve("elasticsearch-" + VersionProperties.getElasticsearch() + "/modules/x-pack-ml/NOTICE.txt")
);
ListProperty<String> expectedMlLicenses = extension.expectedMlLicenses;
task.doLast(new Action<Task>() {
@Override
public void execute(Task task) {
// this is just a small sample from the C++ notices,
// the idea being that if we've added these lines we've probably added all the required lines
final List<String> expectedLines = extension.expectedMlLicenses.get();
final Path noticePath = checkExtraction.get()
.getDestinationDir()
.toPath()
.resolve("elasticsearch-" + VersionProperties.getElasticsearch() + "/modules/x-pack-ml/NOTICE.txt");
final List<String> expectedLines = expectedMlLicenses.get();
final List<String> actualLines;
try {
actualLines = Files.readAllLines(noticePath);
actualLines = Files.readAllLines(noticePath.get());
for (final String expectedLine : expectedLines) {
if (actualLines.contains(expectedLine) == false) {
throw new GradleException("expected [" + noticePath + " to contain [" + expectedLine + "] but it did not");
throw new GradleException(
"expected [" + noticePath.get() + " to contain [" + expectedLine + "] but it did not"
);
}
}
} catch (IOException ioException) {
Expand All @@ -133,43 +139,37 @@ public void execute(Task task) {
private TaskProvider<Task> registerCheckNoticeTask(Project project, TaskProvider<Copy> checkExtraction) {
return project.getTasks().register("checkNotice", task -> {
task.dependsOn(checkExtraction);
task.doLast(new Action<Task>() {
@Override
public void execute(Task task) {
final List<String> noticeLines = Arrays.asList("Elasticsearch", "Copyright 2009-2024 Elasticsearch");
final Path noticePath = checkExtraction.get()
.getDestinationDir()
.toPath()
.resolve("elasticsearch-" + VersionProperties.getElasticsearch() + "/NOTICE.txt");
assertLinesInFile(noticePath, noticeLines);
}
var noticePath = checkExtraction.map(
copy -> copy.getDestinationDir().toPath().resolve("elasticsearch-" + VersionProperties.getElasticsearch() + "/NOTICE.txt")
);
task.doLast(t -> {
final List<String> noticeLines = Arrays.asList("Elasticsearch", "Copyright 2009-2024 Elasticsearch");
assertLinesInFile(noticePath.get(), noticeLines);
});
});
}

private TaskProvider<Task> registerCheckLicenseTask(Project project, TaskProvider<Copy> checkExtraction) {
TaskProvider<Task> checkLicense = project.getTasks().register("checkLicense", task -> {
task.dependsOn(checkExtraction);
task.doLast(new Action<Task>() {
@Override
public void execute(Task task) {
String licenseFilename = null;
if (project.getName().contains("oss-") || project.getName().equals("integ-test-zip")) {
licenseFilename = "AGPL-3.0+SSPL-1.0+ELASTIC-LICENSE-2.0.txt";
} else {
licenseFilename = "ELASTIC-LICENSE-2.0.txt";
}
final List<String> licenseLines;
try {
licenseLines = Files.readAllLines(project.getRootDir().toPath().resolve("licenses/" + licenseFilename));
final Path licensePath = checkExtraction.get()
.getDestinationDir()
.toPath()
.resolve("elasticsearch-" + VersionProperties.getElasticsearch() + "/LICENSE.txt");
assertLinesInFile(licensePath, licenseLines);
} catch (IOException ioException) {
ioException.printStackTrace();
}
String projectName = project.getName();
Provider<Path> licensePathProvider = checkExtraction.map(
copy -> copy.getDestinationDir().toPath().resolve("elasticsearch-" + VersionProperties.getElasticsearch() + "/LICENSE.txt")
);
File rootDir = project.getLayout().getSettingsDirectory().getAsFile();
task.doLast(t -> {
String licenseFilename = null;
if (projectName.contains("oss-") || projectName.equals("integ-test-zip")) {
licenseFilename = "AGPL-3.0+SSPL-1.0+ELASTIC-LICENSE-2.0.txt";
} else {
licenseFilename = "ELASTIC-LICENSE-2.0.txt";
}
final List<String> licenseLines;
try {
licenseLines = Files.readAllLines(rootDir.toPath().resolve("licenses/" + licenseFilename));
assertLinesInFile(licensePathProvider.get(), licenseLines);
} catch (IOException ioException) {
ioException.printStackTrace();
}
});
});
Expand Down
Loading