Skip to content

Commit 5f48156

Browse files
Merge branch 'main' into merge-disk-space-aware-take-2
2 parents 305e4db + f76e201 commit 5f48156

File tree

61 files changed

+4110
-399
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+4110
-399
lines changed

build-tools/src/integTest/groovy/org/elasticsearch/gradle/test/TestBuildInfoPluginFuncTest.groovy

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import com.fasterxml.jackson.databind.ObjectMapper
55
import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest
66
import org.gradle.testkit.runner.TaskOutcome
77

8-
import java.nio.file.Path
9-
108
class TestBuildInfoPluginFuncTest extends AbstractGradleFuncTest {
11-
def "works"() {
9+
def "basic functionality"() {
1210
given:
1311
file("src/main/java/com/example/Example.java") << """
1412
package com.example;
@@ -54,12 +52,70 @@ class TestBuildInfoPluginFuncTest extends AbstractGradleFuncTest {
5452

5553
def location = Map.of(
5654
"module", "com.example",
57-
"representative_class", Path.of("com", "example", "Example.class").toString()
55+
"representative_class", "com/example/Example.class"
5856
)
5957
def expectedOutput = Map.of(
6058
"component", "example-component",
6159
"locations", List.of(location)
6260
)
6361
new ObjectMapper().readValue(output, Map.class) == expectedOutput
6462
}
63+
64+
def "dependencies"() {
65+
buildFile << """
66+
import org.elasticsearch.gradle.plugin.GenerateTestBuildInfoTask;
67+
68+
plugins {
69+
id 'java'
70+
id 'elasticsearch.test-build-info'
71+
}
72+
73+
repositories {
74+
mavenCentral()
75+
}
76+
77+
dependencies {
78+
// We pin to specific versions here because they are known to have the properties we want to test.
79+
// We're not actually running this code.
80+
implementation "org.ow2.asm:asm:9.7.1" // has module-info.class
81+
implementation "junit:junit:4.13" // has Automatic-Module-Name, and brings in hamcrest which does not
82+
}
83+
84+
tasks.withType(GenerateTestBuildInfoTask.class) {
85+
componentName = 'example-component'
86+
outputFile = new File('build/generated-build-info/plugin-test-build-info.json')
87+
}
88+
"""
89+
90+
when:
91+
def result = gradleRunner('generateTestBuildInfo').build()
92+
def task = result.task(":generateTestBuildInfo")
93+
94+
95+
then:
96+
task.outcome == TaskOutcome.SUCCESS
97+
98+
def output = file("build/generated-build-info/plugin-test-build-info.json")
99+
output.exists() == true
100+
101+
def locationFromModuleInfo = Map.of(
102+
"module", "org.objectweb.asm",
103+
"representative_class", 'org/objectweb/asm/AnnotationVisitor.class'
104+
)
105+
def locationFromManifest = Map.of(
106+
"module", "junit",
107+
"representative_class", 'junit/textui/TestRunner.class'
108+
)
109+
def locationFromJarFileName = Map.of(
110+
"module", "hamcrest.core",
111+
"representative_class", 'org/hamcrest/BaseDescription.class'
112+
)
113+
def expectedOutput = Map.of(
114+
"component", "example-component",
115+
"locations", List.of(locationFromModuleInfo, locationFromManifest, locationFromJarFileName)
116+
)
117+
118+
def value = new ObjectMapper().readValue(output, Map.class)
119+
value == expectedOutput
120+
}
65121
}

build-tools/src/main/java/org/elasticsearch/gradle/plugin/GenerateTestBuildInfoTask.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import java.nio.file.attribute.BasicFileAttributes;
4242
import java.security.CodeSource;
4343
import java.util.ArrayList;
44-
import java.util.Arrays;
44+
import java.util.Comparator;
4545
import java.util.List;
4646
import java.util.jar.JarEntry;
4747
import java.util.jar.JarFile;
@@ -209,17 +209,16 @@ private String extractModuleNameFromJar(File file, JarFile jarFile) throws IOExc
209209
* @return a {@link StringBuilder} with the {@code META-INF/versions/<version number>} if it exists; otherwise null
210210
*/
211211
private static StringBuilder versionDirectoryIfExists(JarFile jarFile) {
212+
Comparator<Integer> numericOrder = Integer::compareTo;
212213
List<Integer> versions = jarFile.stream()
213214
.filter(je -> je.getName().startsWith(META_INF_VERSIONS_PREFIX) && je.getName().endsWith("/module-info.class"))
214215
.map(
215216
je -> Integer.parseInt(
216217
je.getName().substring(META_INF_VERSIONS_PREFIX.length(), je.getName().length() - META_INF_VERSIONS_PREFIX.length())
217218
)
218219
)
220+
.sorted(numericOrder.reversed())
219221
.toList();
220-
versions = new ArrayList<>(versions);
221-
versions.sort(Integer::compareTo);
222-
versions = versions.reversed();
223222
int major = Runtime.version().feature();
224223
StringBuilder path = new StringBuilder(META_INF_VERSIONS_PREFIX);
225224
for (int version : versions) {
@@ -300,7 +299,10 @@ private String extractClassNameFromDirectory(File dir) throws IOException {
300299
public @NotNull FileVisitResult visitFile(@NotNull Path candidate, @NotNull BasicFileAttributes attrs) {
301300
String name = candidate.getFileName().toString(); // Just the part after the last dir separator
302301
if (name.endsWith(".class") && (name.equals("module-info.class") || name.contains("$")) == false) {
303-
result = candidate.toAbsolutePath().toString().substring(dir.getAbsolutePath().length() + 1);
302+
result = candidate.toAbsolutePath()
303+
.toString()
304+
.substring(dir.getAbsolutePath().length() + 1)
305+
.replace(File.separatorChar, '/');
304306
return TERMINATE;
305307
} else {
306308
return CONTINUE;
@@ -316,20 +318,24 @@ private String extractClassNameFromDirectory(File dir) throws IOException {
316318
* if it exists or the preset one derived from the jar task
317319
*/
318320
private String extractModuleNameFromDirectory(File dir) throws IOException {
319-
List<File> files = new ArrayList<>(List.of(dir));
320-
while (files.isEmpty() == false) {
321-
File find = files.removeFirst();
322-
if (find.exists()) {
323-
if (find.getName().equals("module-info.class")) {
324-
try (InputStream inputStream = new FileInputStream(find)) {
325-
return extractModuleNameFromModuleInfo(inputStream);
321+
var visitor = new SimpleFileVisitor<Path>() {
322+
private String result = getModuleName().getOrNull();
323+
324+
@Override
325+
public @NotNull FileVisitResult visitFile(@NotNull Path candidate, @NotNull BasicFileAttributes attrs) throws IOException {
326+
String name = candidate.getFileName().toString(); // Just the part after the last dir separator
327+
if (name.equals("module-info.class")) {
328+
try (InputStream inputStream = new FileInputStream(candidate.toFile())) {
329+
result = extractModuleNameFromModuleInfo(inputStream);
330+
return TERMINATE;
326331
}
327-
} else if (find.isDirectory()) {
328-
files.addAll(Arrays.asList(find.listFiles()));
332+
} else {
333+
return CONTINUE;
329334
}
330335
}
331-
}
332-
return getModuleName().getOrNull();
336+
};
337+
Files.walkFileTree(dir.toPath(), visitor);
338+
return visitor.result;
333339
}
334340

335341
/**

docs/changelog/125408.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 125408
2+
summary: Prevent ML data retention logic from failing when deleting documents in read-only
3+
indices
4+
area: Machine Learning
5+
type: bug
6+
issues: []

docs/changelog/128259.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 128259
2+
summary: Added geometry validation for GEO types to exit early on invalid latitudes
3+
area: Geo
4+
type: bug
5+
issues:
6+
- 128234

docs/changelog/128263.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 128263
2+
summary: Allow lookup join on mixed numeric fields
3+
area: ES|QL
4+
type: enhancement
5+
issues: []

docs/changelog/128320.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 128320
2+
summary: Use new source loader when lower `docId` is accessed
3+
area: Codec
4+
type: bug
5+
issues: []

docs/reference/query-languages/esql/_snippets/functions/layout/round_to.md

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/lists/math-functions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* [`PI`](../../functions-operators/math-functions.md#esql-pi)
1717
* [`POW`](../../functions-operators/math-functions.md#esql-pow)
1818
* [`ROUND`](../../functions-operators/math-functions.md#esql-round)
19+
* [`ROUND_TO`](../../functions-operators/math-functions.md#esql-round_to)
1920
* [`SCALB`](../../functions-operators/math-functions.md#esql-scalb)
2021
* [`SIGNUM`](../../functions-operators/math-functions.md#esql-signum)
2122
* [`SIN`](../../functions-operators/math-functions.md#esql-sin)

docs/reference/query-languages/esql/functions-operators/math-functions.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ mapped_pages:
6666
:::{include} ../_snippets/functions/layout/round.md
6767
:::
6868

69+
:::{include} ../_snippets/functions/layout/round_to.md
70+
:::
71+
6972
:::{include} ../_snippets/functions/layout/scalb.md
7073
:::
7174

docs/reference/query-languages/query-dsl/query-dsl-match-query-phrase.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@ GET /_search
3434

3535
`zero_terms_query`
3636
: (Optional, string) Indicates whether no documents are returned if the `analyzer` removes all tokens, such as when using a `stop` filter. Valid values are:
37-
38-
`none` (Default)
39-
: No documents are returned if the `analyzer` removes all tokens.
40-
41-
`all`
42-
: Returns all documents, similar to a [`match_all`](/reference/query-languages/query-dsl/query-dsl-match-all-query.md) query.
43-
37+
- `none` (Default)
38+
No documents are returned if the `analyzer` removes all tokens.
39+
- `all`
40+
Returns all documents, similar to a [`match_all`](/reference/query-languages/query-dsl/query-dsl-match-all-query.md) query.
4441

4542
A phrase query matches terms up to a configurable `slop` (which defaults to 0) in any order. Transposed terms have a slop of 2.
4643

0 commit comments

Comments
 (0)