Browse Source

Fix ES|QL build.gradle for configuration-cache (#125097)

Earlier work on the ES|QL port of docs to V3 introduced an issue in the build.gradle file making it fail with --configuration-cache. This fixes that, as well as one other broken link and removes some unused files.

In addition we bring back partial support for deleting unused files. It is tricky to have full support for this due to the mix of static and generated content, particularly in the operators snippets.
Craig Taverner 7 months ago
parent
commit
50a7eb09d4

+ 0 - 9
docs/reference/query-languages/esql/_snippets/operators/types/not_like.md

@@ -1,9 +0,0 @@
-% This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it.
-
-**Supported types**
-
-| str | pattern | result |
-| --- | --- | --- |
-| keyword | keyword | boolean |
-| text | keyword | boolean |
-

+ 0 - 9
docs/reference/query-languages/esql/_snippets/operators/types/not_rlike.md

@@ -1,9 +0,0 @@
-% This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it.
-
-**Supported types**
-
-| str | pattern | result |
-| --- | --- | --- |
-| keyword | keyword | boolean |
-| text | keyword | boolean |
-

+ 31 - 15
x-pack/plugin/esql/build.gradle

@@ -99,11 +99,18 @@ tasks.named("test").configure {
     def imagesDocFolder = file("${rootDir}/docs/reference/query-languages/esql/images")
     def snippetsDocFolder = file("${rootDir}/docs/reference/query-languages/esql/_snippets")
     def kibanaDocFolder = file("${rootDir}/docs/reference/query-languages/esql/kibana")
+    def snippetsTree = fileTree(snippetsFolder).matching {
+      include "**/types/*.md"  // Recursively include all types/*.md files (effectively counting functions and operators)
+    }
+    def imagesTree = fileTree(imagesFolder).matching {
+      include "**/*.svg"  // Recursively include all SVG files
+    }
+    def kibanaTree = fileTree(kibanaFolder).matching {
+      include "**/*.json"  // Recursively include all JSON files
+    }
 
     doLast {
-      List snippets = fileTree(snippetsFolder).matching {
-        include "**/types/*.md"  // Recursively include all types/*.md files (effectively counting functions and operators)
-      }.files.collect { it.name }
+      def snippets = snippetsTree.files.collect { it.name }
       int countSnippets = snippets.size()
       if (countSnippets == 0) {
         logger.quiet("ESQL Docs: No function/operator snippets created. Skipping sync.")
@@ -113,19 +120,27 @@ tasks.named("test").configure {
           from snippetsFolder
           into snippetsDocFolder
           include '**/*.md'
-          preserve {
-            // The snippets directory contains generated and static content, so we must preserve all MD files.
-            include '**/*.md'
+          if (countSnippets <= 100) {
+            // If we do not run the full test of tests, do not attempt to remove potentially unused files
+            preserve {
+              // The snippets directory contains generated and static content, so we must preserve all MD files.
+              include '**/*.md'
+            }
+          } else {
+            // If we do run the full test of tests, be careful about what we need to preserve
+            preserve {
+              // The lists are static, and the operators are a mix of generated and static content
+              include '*.md', '**/operators/*.md', '**/operators/**/*.md', '**/lists/*.md'
+            }
           }
         }
       }
 
-      List images = fileTree(imagesFolder).matching {
-        include "**/*.svg"  // Recursively include all SVG files
-      }.files.collect { it.name }
+      List images = imagesTree.files.collect { it.name }
       int countImages = images.size()
       Closure replaceFont = line -> {
         // The es-docs team has a recommended set of fonts for use with code, and they size similarly to the previous Roboto Mono, which is no longer available in the docs webpage
+        // We do not change the original SVG generator to use these because it requires the fonts to exist in the JVM running the code
         line.replaceAll(
           /font-family:\s*Roboto Mono[^;]*;/,
           'font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;'
@@ -139,17 +154,18 @@ tasks.named("test").configure {
           from imagesFolder
           into imagesDocFolder
           include '**/*.svg'
-          preserve {
-            // Some operator files are currently static, so we must preserve them all
-            include '**/*.svg'
+          if (countImages <= 100) {
+            // If we do not run the full test of tests, do not attempt to remove potentially unused files
+            preserve {
+              // Some operator files are currently static, so we must preserve them all
+              include '**/*.svg'
+            }
           }
           filter replaceFont
         }
       }
 
-      List kibana = fileTree(kibanaFolder).matching {
-        include "**/*.json"  // Recursively include all JSON files
-      }.files.collect { it.name }
+      List kibana = kibanaTree.files.collect { it.name }
       int countKibana = kibana.size()
       if (countKibana == 0) {
         logger.quiet("ESQL Docs: No function/operator kibana docs created. Skipping sync.")

+ 1 - 1
x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/DocsV3Support.java

@@ -310,7 +310,7 @@ public abstract class DocsV3Support {
         // Various other remaining old asciidoc links
         // <<match-field-params,match query parameters>>
         return switch (parts[0]) {
-            case "match-field-params" -> makeLink(key, "", "/reference/query-languages/query-dsl-match-query.md");
+            case "match-field-params" -> makeLink(key, "", "/reference/query-languages/query-dsl/query-dsl-match-query.md");
             case "search-aggregations-bucket-histogram-aggregation" -> makeLink(
                 key,
                 "",