From 879c248a01d33d56e1b09c82cb79a2f97177ac33 Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Mon, 21 Oct 2024 09:56:22 +0200 Subject: [PATCH] [Build] Fix checkstyle exclusions on windows --- .../gradle/util/PlatformUtils.java | 23 +++++++++++++++++++ x-pack/plugin/esql/build.gradle | 7 +++--- x-pack/plugin/kql/build.gradle | 3 ++- 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 build-tools/src/main/java/org/elasticsearch/gradle/util/PlatformUtils.java diff --git a/build-tools/src/main/java/org/elasticsearch/gradle/util/PlatformUtils.java b/build-tools/src/main/java/org/elasticsearch/gradle/util/PlatformUtils.java new file mode 100644 index 0000000000000..2f093a19032c8 --- /dev/null +++ b/build-tools/src/main/java/org/elasticsearch/gradle/util/PlatformUtils.java @@ -0,0 +1,23 @@ +/* + * 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.util; + +import java.util.stream.Collectors; + +public class PlatformUtils { + + public static String normalize(String input) { + return input.lines() + .map(it -> it.replace('\\', '/')) + .map(it -> it.replaceAll("\\d+\\.\\d\\ds", "0.00s")) + .map(it -> it.replace("file:/./", "file:./")) + .collect(Collectors.joining("\n")); + } +} diff --git a/x-pack/plugin/esql/build.gradle b/x-pack/plugin/esql/build.gradle index c8d704cd2b8bf..766d0c0f13892 100644 --- a/x-pack/plugin/esql/build.gradle +++ b/x-pack/plugin/esql/build.gradle @@ -1,6 +1,7 @@ import org.elasticsearch.gradle.internal.info.BuildParams import org.elasticsearch.gradle.internal.precommit.CheckForbiddenApisTask; import org.elasticsearch.gradle.internal.util.SourceDirectoryCommandLineArgumentProvider; +import static org.elasticsearch.gradle.util.PlatformUtils.normalize apply plugin: 'elasticsearch.internal-es-plugin' apply plugin: 'elasticsearch.internal-cluster-test' @@ -56,7 +57,7 @@ def generatedSourceDir = projectDirectory.dir("src/main/generated") tasks.named("compileJava").configure { options.compilerArgumentProviders.add(new SourceDirectoryCommandLineArgumentProvider(generatedSourceDir)) // IntelliJ sticks generated files here and we can't stop it.... - exclude { it.file.toString().contains("src/main/generated-src/generated") } + exclude { normalize(it.file.toString()).contains("src/main/generated-src/generated") } } interface Injected { @@ -262,8 +263,8 @@ tasks.register("regen") { tasks.named("spotlessJava") { dependsOn stringTemplates } tasks.named('checkstyleMain').configure { excludes = [ "**/*.java.st" ] - exclude { it.file.toString().contains("src/main/generated-src/generated") } - exclude { it.file.toString().contains("src/main/generated") } + exclude { normalize(it.file.toString()).contains("src/main/generated-src/generated") } + exclude { normalize(it.file.toString()).contains("src/main/generated") } } def prop(Type, type, TYPE, BYTES, Array) { diff --git a/x-pack/plugin/kql/build.gradle b/x-pack/plugin/kql/build.gradle index d1c949834b021..198099329c7c0 100644 --- a/x-pack/plugin/kql/build.gradle +++ b/x-pack/plugin/kql/build.gradle @@ -1,4 +1,5 @@ import org.elasticsearch.gradle.internal.info.BuildParams +import static org.elasticsearch.gradle.util.PlatformUtils.normalize apply plugin: 'elasticsearch.internal-es-plugin' apply plugin: 'elasticsearch.internal-cluster-test' @@ -54,7 +55,7 @@ pluginManager.withPlugin('com.diffplug.spotless') { } } tasks.named('checkstyleMain').configure { - exclude { it.file.toString().contains("src/main/java/org/elasticsearch/xpack/kql/parser/KqlBase") } + exclude { normalize(it.file.toString()).contains("src/main/java/org/elasticsearch/xpack/kql/parser/KqlBase") } } tasks.register("cleanGenerated", Delete) {