Skip to content

Commit 9bf83d2

Browse files
committed
Merge remote-tracking branch 'es/6.x' into ccr-6.x
* es/6.x: (46 commits) Docs: Add note about missing mapping for doc values field (#29036) [DOCS] Removed 6.1.4, 6.2.2, and 6.2.3 coming tags Remove BytesArray and BytesReference usage from XContentFactory (#29151) Fix BWC issue for PreSyncedFlushResponse Add pluggable XContentBuilder writers and human readable writers (#29120) Add unreleased version 6.2.4 (#29171) Add unreleased version 6.1.5 (#29168) Add a note about using the `retry_failed` flag before accepting data loss (#29160) Fix typo in percolate-query.asciidoc (#29155) Add release notes for 6.1.4 and 6.2.3 Require HTTP::Tiny 0.070 for release notes script REST high-level client: add clear cache API (#28866) Relax remote check for bwc project checkouts (#28666) Set Java 9 checkstyle to depend on checkstyle conf (#28383) Docs: Add example of resetting index setting (#29048) Plugins: Fix module name conflict check for meta plugins (#29146) Build: Fix meta plugin bundled plugin names (#29147) Build: Simplify rest spec hack configuration (#29149) CLI: Close subcommands in MultiCommand (#28954) Build: Fix meta modules to not install as plugin in tests (#29150) ...
2 parents c838141 + ac0f281 commit 9bf83d2

File tree

138 files changed

+2896
-940
lines changed

Some content is hidden

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

138 files changed

+2896
-940
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.gradle.doc
2121

22+
import groovy.transform.PackageScope
2223
import org.elasticsearch.gradle.doc.SnippetsTask.Snippet
2324
import org.gradle.api.InvalidUserDataException
2425
import org.gradle.api.tasks.Input
@@ -99,6 +100,43 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
99100
return snippet.language == 'js' || snippet.curl
100101
}
101102

103+
/**
104+
* Converts Kibana's block quoted strings into standard JSON. These
105+
* {@code """} delimited strings can be embedded in CONSOLE and can
106+
* contain newlines and {@code "} without the normal JSON escaping.
107+
* This has to add it.
108+
*/
109+
@PackageScope
110+
static String replaceBlockQuote(String body) {
111+
int start = body.indexOf('"""');
112+
if (start < 0) {
113+
return body
114+
}
115+
/*
116+
* 1.3 is a fairly wild guess of the extra space needed to hold
117+
* the escaped string.
118+
*/
119+
StringBuilder result = new StringBuilder((int) (body.length() * 1.3));
120+
int startOfNormal = 0;
121+
while (start >= 0) {
122+
int end = body.indexOf('"""', start + 3);
123+
if (end < 0) {
124+
throw new InvalidUserDataException(
125+
"Invalid block quote starting at $start in:\n$body")
126+
}
127+
result.append(body.substring(startOfNormal, start));
128+
result.append('"');
129+
result.append(body.substring(start + 3, end)
130+
.replace('"', '\\"')
131+
.replace("\n", "\\n"));
132+
result.append('"');
133+
startOfNormal = end + 3;
134+
start = body.indexOf('"""', startOfNormal);
135+
}
136+
result.append(body.substring(startOfNormal));
137+
return result.toString();
138+
}
139+
102140
private class TestBuilder {
103141
private static final String SYNTAX = {
104142
String method = /(?<method>GET|PUT|POST|HEAD|OPTIONS|DELETE)/
@@ -259,6 +297,8 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
259297
if (body != null) {
260298
// Throw out the leading newline we get from parsing the body
261299
body = body.substring(1)
300+
// Replace """ quoted strings with valid json ones
301+
body = replaceBlockQuote(body)
262302
current.println(" body: |")
263303
body.eachLine { current.println(" $it") }
264304
}

buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/MetaPluginBuildPlugin.groovy

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,28 @@ class MetaPluginBuildPlugin implements Plugin<Project> {
3737
project.plugins.apply(RestTestPlugin)
3838

3939
createBundleTask(project)
40+
boolean isModule = project.path.startsWith(':modules:')
4041

4142
project.integTestCluster {
4243
dependsOn(project.bundlePlugin)
43-
plugin(project.path)
4444
}
4545
BuildPlugin.configurePomGeneration(project)
4646
project.afterEvaluate {
4747
PluginBuildPlugin.addZipPomGeneration(project)
48+
if (isModule) {
49+
if (project.integTestCluster.distribution == 'integ-test-zip') {
50+
project.integTestCluster.module(project)
51+
}
52+
} else {
53+
project.integTestCluster.plugin(project.path)
54+
}
4855
}
4956

5057
RunTask run = project.tasks.create('run', RunTask)
5158
run.dependsOn(project.bundlePlugin)
52-
run.clusterConfig.plugin(project.path)
59+
if (isModule == false) {
60+
run.clusterConfig.plugin(project.path)
61+
}
5362
}
5463

5564
private static void createBundleTask(Project project) {
@@ -79,12 +88,13 @@ class MetaPluginBuildPlugin implements Plugin<Project> {
7988
buildProperties.extension.plugins.each { String bundledPluginProjectName ->
8089
Project bundledPluginProject = project.project(bundledPluginProjectName)
8190
bundledPluginProject.afterEvaluate {
91+
String bundledPluginName = bundledPluginProject.esplugin.name
8292
bundle.configure {
8393
dependsOn bundledPluginProject.bundlePlugin
8494
from(project.zipTree(bundledPluginProject.bundlePlugin.outputs.files.singleFile)) {
8595
eachFile { FileCopyDetails details ->
8696
// we want each path to have the plugin name interjected
87-
details.relativePath = new RelativePath(true, bundledPluginProjectName, details.relativePath.toString())
97+
details.relativePath = new RelativePath(true, bundledPluginName, details.relativePath.toString())
8898
}
8999
}
90100
}

buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin
2222
import org.gradle.api.Project
2323
import org.gradle.api.Task
2424
import org.gradle.api.plugins.JavaBasePlugin
25+
import org.gradle.api.plugins.quality.Checkstyle
2526

2627
/**
2728
* Validation tasks which should be run before committing. These run before tests.
@@ -142,7 +143,7 @@ class PrecommitTasks {
142143
]
143144
toolVersion = 7.5
144145
}
145-
for (String taskName : ['checkstyleMain', 'checkstyleTest']) {
146+
for (String taskName : ['checkstyleMain', 'checkstyleJava9', 'checkstyleTest']) {
146147
Task task = project.tasks.findByName(taskName)
147148
if (task != null) {
148149
project.tasks['check'].dependsOn.remove(task)
@@ -154,6 +155,11 @@ class PrecommitTasks {
154155
}
155156
}
156157
}
158+
159+
project.tasks.withType(Checkstyle) {
160+
dependsOn(copyCheckstyleConf)
161+
}
162+
157163
return checkstyleTask
158164
}
159165

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ package org.elasticsearch.gradle.test
2020

2121
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
2222
import org.elasticsearch.gradle.BuildPlugin
23+
import org.elasticsearch.gradle.VersionProperties
2324
import org.gradle.api.DefaultTask
25+
import org.gradle.api.Project
2426
import org.gradle.api.Task
2527
import org.gradle.api.execution.TaskExecutionAdapter
2628
import org.gradle.api.internal.tasks.options.Option
29+
import org.gradle.api.provider.Property
30+
import org.gradle.api.provider.Provider
31+
import org.gradle.api.tasks.Copy
2732
import org.gradle.api.tasks.Input
2833
import org.gradle.api.tasks.TaskState
2934

@@ -47,7 +52,7 @@ public class RestIntegTestTask extends DefaultTask {
4752

4853
/** Flag indicating whether the rest tests in the rest spec should be run. */
4954
@Input
50-
boolean includePackaged = false
55+
Property<Boolean> includePackaged = project.objects.property(Boolean)
5156

5257
public RestIntegTestTask() {
5358
runner = project.tasks.create("${name}Runner", RandomizedTestingTask.class)
@@ -92,10 +97,9 @@ public class RestIntegTestTask extends DefaultTask {
9297
}
9398

9499
// copy the rest spec/tests into the test resources
95-
RestSpecHack.configureDependencies(project)
96-
project.afterEvaluate {
97-
runner.dependsOn(RestSpecHack.configureTask(project, includePackaged))
98-
}
100+
Task copyRestSpec = createCopyRestSpecTask(project, includePackaged)
101+
runner.dependsOn(copyRestSpec)
102+
99103
// this must run after all projects have been configured, so we know any project
100104
// references can be accessed as a fully configured
101105
project.gradle.projectsEvaluated {
@@ -109,6 +113,11 @@ public class RestIntegTestTask extends DefaultTask {
109113
}
110114
}
111115

116+
/** Sets the includePackaged property */
117+
public void includePackaged(boolean include) {
118+
includePackaged.set(include)
119+
}
120+
112121
@Option(
113122
option = "debug-jvm",
114123
description = "Enable debugging configuration, to allow attaching a debugger to elasticsearch."
@@ -184,4 +193,47 @@ public class RestIntegTestTask extends DefaultTask {
184193
println('=========================================')
185194

186195
}
196+
197+
/**
198+
* Creates a task (if necessary) to copy the rest spec files.
199+
*
200+
* @param project The project to add the copy task to
201+
* @param includePackagedTests true if the packaged tests should be copied, false otherwise
202+
*/
203+
private static Task createCopyRestSpecTask(Project project, Provider<Boolean> includePackagedTests) {
204+
project.configurations {
205+
restSpec
206+
}
207+
project.dependencies {
208+
restSpec "org.elasticsearch:rest-api-spec:${VersionProperties.elasticsearch}"
209+
}
210+
Task copyRestSpec = project.tasks.findByName('copyRestSpec')
211+
if (copyRestSpec != null) {
212+
return copyRestSpec
213+
}
214+
Map copyRestSpecProps = [
215+
name : 'copyRestSpec',
216+
type : Copy,
217+
dependsOn: [project.configurations.restSpec, 'processTestResources']
218+
]
219+
copyRestSpec = project.tasks.create(copyRestSpecProps) {
220+
into project.sourceSets.test.output.resourcesDir
221+
}
222+
project.afterEvaluate {
223+
copyRestSpec.from({ project.zipTree(project.configurations.restSpec.singleFile) }) {
224+
include 'rest-api-spec/api/**'
225+
if (includePackagedTests.get()) {
226+
include 'rest-api-spec/test/**'
227+
}
228+
}
229+
}
230+
project.idea {
231+
module {
232+
if (scopes.TEST != null) {
233+
scopes.TEST.plus.add(project.configurations.restSpec)
234+
}
235+
}
236+
}
237+
return copyRestSpec
238+
}
187239
}

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestSpecHack.groovy

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.gradle.doc
21+
22+
import org.elasticsearch.gradle.doc.SnippetsTask.Snippet
23+
import org.gradle.api.InvalidUserDataException
24+
25+
import static org.elasticsearch.gradle.doc.RestTestsFromSnippetsTask.replaceBlockQuote
26+
27+
class RestTestFromSnippetsTaskTest extends GroovyTestCase {
28+
void testInvalidBlockQuote() {
29+
String input = "\"foo\": \"\"\"bar\"";
30+
String message = shouldFail({ replaceBlockQuote(input) });
31+
assertEquals("Invalid block quote starting at 7 in:\n$input", message);
32+
}
33+
34+
void testSimpleBlockQuote() {
35+
assertEquals("\"foo\": \"bort baz\"",
36+
replaceBlockQuote("\"foo\": \"\"\"bort baz\"\"\""));
37+
}
38+
39+
void testMultipleBlockQuotes() {
40+
assertEquals("\"foo\": \"bort baz\", \"bar\": \"other\"",
41+
replaceBlockQuote("\"foo\": \"\"\"bort baz\"\"\", \"bar\": \"\"\"other\"\"\""));
42+
}
43+
44+
void testEscapingInBlockQuote() {
45+
assertEquals("\"foo\": \"bort\\\" baz\"",
46+
replaceBlockQuote("\"foo\": \"\"\"bort\" baz\"\"\""));
47+
assertEquals("\"foo\": \"bort\\n baz\"",
48+
replaceBlockQuote("\"foo\": \"\"\"bort\n baz\"\"\""));
49+
}
50+
}

0 commit comments

Comments
 (0)