From ac4509edd49c52ed06e554dda283f88c0501a6bf Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Thu, 19 Oct 2023 19:50:45 +0200 Subject: [PATCH] Make GenerateProviderManifest configuration cache compatible --- .../internal/GenerateProviderManifest.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/GenerateProviderManifest.java diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/GenerateProviderManifest.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/GenerateProviderManifest.java new file mode 100644 index 0000000000000..e20e00ea3b110 --- /dev/null +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/GenerateProviderManifest.java @@ -0,0 +1,42 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.gradle.internal; + +import org.elasticsearch.gradle.util.FileUtils; +import org.gradle.api.DefaultTask; +import org.gradle.api.file.ConfigurableFileCollection; +import org.gradle.api.provider.Provider; +import org.gradle.api.tasks.Classpath; +import org.gradle.api.tasks.InputFiles; +import org.gradle.api.tasks.OutputFile; +import org.gradle.api.tasks.TaskAction; + +import java.io.File; +import java.util.stream.Collectors; + +abstract class GenerateProviderManifest extends DefaultTask { + + @Classpath + @InputFiles + abstract public ConfigurableFileCollection getProviderImplClasspath(); + + @OutputFile + abstract public Provider getManifestFile(); + + @TaskAction + void generateManifest() { + File manifestFile = getManifestFile().get(); + manifestFile.getParentFile().mkdirs(); + FileUtils.write(manifestFile, generateManifestContent(), "UTF-8"); + } + + private String generateManifestContent() { + return getProviderImplClasspath().getFiles().stream().map(File::getName).sorted().collect(Collectors.joining("\n")); + } +}