Skip to content

Commit

Permalink
Some more cleanup after review
Browse files Browse the repository at this point in the history
  • Loading branch information
breskeby committed Nov 27, 2023
1 parent ca3d2ba commit 0cddc75
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.file.SourceDirectorySet;
import org.gradle.api.internal.file.FileOperations;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.PathSensitive;
Expand All @@ -43,7 +43,7 @@
* A task to create a notice file which includes dependencies' notices.
*/
@CacheableTask
public class NoticeTask extends DefaultTask {
public abstract class NoticeTask extends DefaultTask {

@InputFile
@PathSensitive(PathSensitivity.RELATIVE)
Expand All @@ -57,19 +57,17 @@ public class NoticeTask extends DefaultTask {
/**
* Directories to include notices from
*/
private final ListProperty<File> licensesDirs;
@Internal
abstract ListProperty<File> getLicenseDirs();

private final FileOperations fileOperations;
private ObjectFactory objectFactory;

@Inject
public NoticeTask(BuildLayout buildLayout, ProjectLayout projectLayout, FileOperations fileOperations, ObjectFactory objectFactory) {
this.objectFactory = objectFactory;
public NoticeTask(BuildLayout buildLayout, ProjectLayout projectLayout, FileOperations fileOperations) {
this.fileOperations = fileOperations;
setDescription("Create a notice file from dependencies");
// Default licenses directory is ${projectDir}/licenses (if it exists)
licensesDirs = objectFactory.listProperty(File.class);
licensesDirs.add(projectLayout.getProjectDirectory().dir("licenses").getAsFile());
getLicenseDirs().add(projectLayout.getProjectDirectory().dir("licenses").getAsFile());
inputFile = new File(buildLayout.getRootDirectory(), "NOTICE.txt");
outputFile = projectLayout.getBuildDirectory().dir("notices/" + getName()).get().file("NOTICE.txt").getAsFile();
}
Expand All @@ -78,7 +76,7 @@ public NoticeTask(BuildLayout buildLayout, ProjectLayout projectLayout, FileOper
* Add notices from the specified directory.
*/
public void licensesDir(File licensesDir) {
licensesDirs.add(licensesDir);
getLicenseDirs().add(licensesDir);
}

public void source(Object source) {
Expand Down Expand Up @@ -185,7 +183,7 @@ public FileCollection getNoticeFiles() {
}

private List<File> existingLicenseDirs() {
return licensesDirs.get().stream().filter(d -> d.exists()).collect(Collectors.toList());
return getLicenseDirs().get().stream().filter(d -> d.exists()).collect(Collectors.toList());
}

@InputFiles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ public Collection<ElasticsearchCluster> getClusters() {
@Override
@Internal
public List<ResourceLock> getSharedResources() {
// Since we need to have the buildservice registered for configuration cache compatibility,
// we already get one lock for throttle service
List<ResourceLock> locks = new ArrayList<>(super.getSharedResources());
BuildServiceRegistryInternal serviceRegistry = getServices().get(BuildServiceRegistryInternal.class);
BuildServiceProvider<?, ?> serviceProvider = serviceRegistry.consume(THROTTLE_SERVICE_NAME, TestClustersThrottle.class);
SharedResource resource = serviceRegistry.forService(serviceProvider);
int nodeCount = clusters.stream().mapToInt(cluster -> cluster.getNodes().size()).sum();
if (nodeCount > 0) {
for (int i = 0; i < Math.min(nodeCount, resource.getMaxUsages()); i++) {
for (int i = 0; i < Math.min(nodeCount, resource.getMaxUsages() - 1); i++) {
locks.add(resource.getResourceLock());
}
}
Expand All @@ -88,7 +90,7 @@ public WorkResult delete(Object... objects) {

@Override
public void beforeStart() {
getTasksService().get().register(this);
TestClustersAware.super.beforeStart();
if (debugServer) {
enableDebug();
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/ml/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ tasks.register("extractNativeLicenses", Copy) {
tasks.named('generateNotice').configure {
dependsOn "extractNativeLicenses"
inputs.dir("${project.buildDir}/extractedNativeLicenses/platform/licenses")
licensesDir new File("${project.buildDir}/extractedNativeLicenses/platform/licenses")
licenseDirs.add(tasks.named("extractNativeLicenses").map {new File(it.destinationDir, "platform/licenses") })
}

tasks.named("dependencyLicenses").configure {
Expand Down

0 comments on commit 0cddc75

Please sign in to comment.