From 1d5706edfd44f3b1e7ffba71138897fbb0ff8f7d Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Thu, 2 Jan 2025 08:36:27 +0100 Subject: [PATCH] [Gradle] Make CopyCheckStyleConfTask usage cc compatible in serverless (#119249) This ensures we can use gradle configuration cache with elasticsearch serverless build --- ...nternalDistributionArchiveSetupPlugin.java | 4 ++-- .../precommit/CheckstylePrecommitPlugin.java | 3 ++- .../precommit/CopyCheckStyleConfTask.java | 21 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CopyCheckStyleConfTask.java diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionArchiveSetupPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionArchiveSetupPlugin.java index f7e2f3d0d6c30..c2547b72e21fa 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionArchiveSetupPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionArchiveSetupPlugin.java @@ -134,14 +134,14 @@ private void registerEmptyDirectoryTasks(Project project) { }); File pluginsDir = new File(project.getBuildDir(), "plugins-hack/plugins"); - project.getExtensions().add("pluginsDir", pluginsDir); + project.getExtensions().getExtraProperties().set("pluginsDir", pluginsDir); project.getTasks().register("createPluginsDir", EmptyDirTask.class, t -> { t.setDir(pluginsDir); t.setDirMode(0755); }); File jvmOptionsDir = new File(project.getBuildDir(), "jvm-options-hack/jvm.options.d"); - project.getExtensions().add("jvmOptionsDir", jvmOptionsDir); + project.getExtensions().getExtraProperties().set("jvmOptionsDir", jvmOptionsDir); project.getTasks().register("createJvmOptionsDir", EmptyDirTask.class, t -> { t.setDir(jvmOptionsDir); t.setDirMode(0750); diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckstylePrecommitPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckstylePrecommitPlugin.java index dbbe35905d208..dc8ea4424ba89 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckstylePrecommitPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckstylePrecommitPlugin.java @@ -42,7 +42,8 @@ public TaskProvider createTask(Project project) { File checkstyleDir = new File(project.getBuildDir(), "checkstyle"); File checkstyleSuppressions = new File(checkstyleDir, "checkstyle_suppressions.xml"); File checkstyleConf = new File(checkstyleDir, "checkstyle.xml"); - TaskProvider copyCheckstyleConf = project.getTasks().register("copyCheckstyleConf"); + TaskProvider copyCheckstyleConf = project.getTasks() + .register("copyCheckstyleConf", CopyCheckStyleConfTask.class); // configure inputs and outputs so up to date works properly copyCheckstyleConf.configure(t -> t.getOutputs().files(checkstyleSuppressions, checkstyleConf)); if ("jar".equals(checkstyleConfUrl.getProtocol())) { diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CopyCheckStyleConfTask.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CopyCheckStyleConfTask.java new file mode 100644 index 0000000000000..9e0f9c24bcef8 --- /dev/null +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CopyCheckStyleConfTask.java @@ -0,0 +1,21 @@ +/* + * 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +package org.elasticsearch.gradle.internal.precommit; + +import org.gradle.api.DefaultTask; +import org.gradle.api.file.FileSystemOperations; + +import javax.inject.Inject; + +public abstract class CopyCheckStyleConfTask extends DefaultTask { + + @Inject + public abstract FileSystemOperations getFs(); +}