Skip to content

Commit c36892b

Browse files
Merge branch 'master' into machine-dependent-heap
2 parents 75cb18b + 83a5256 commit c36892b

File tree

743 files changed

+8912
-1937
lines changed

Some content is hidden

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

743 files changed

+8912
-1937
lines changed

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ indent_size = 2
1313

1414
[*.groovy]
1515
indent_size = 4
16+
max_line_length = 140
1617

1718
[*.java]
1819
indent_size = 4
20+
max_line_length = 140
1921

2022
[*.json]
2123
indent_size = 2

CONTRIBUTING.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,47 @@ You can import the Elasticsearch project into IntelliJ IDEA via:
164164
- In the subsequent dialog navigate to the root `build.gradle` file
165165
- In the subsequent dialog select **Open as Project**
166166

167+
#### Checkstyle
168+
169+
If you have the [Checkstyle] plugin installed, you can configure IntelliJ to
170+
check the Elasticsearch code. However, the Checkstyle configuration file does
171+
not work by default with the IntelliJ plugin, so instead an IDE-specific config
172+
file is generated automatically after IntelliJ finishes syncing.
173+
174+
1. Open **Preferences > Tools > Checkstyle**
175+
2. Change the "Scan Scope" to "Only Java sources (including tests)"
176+
3. Check the "+" under "Configuration file"
177+
4. Set "Description" to "Elasticsearch" (or whatever you want)
178+
5. Select "Use a local Checkstyle file"
179+
6. For the "File", navigate to `build/checkstyle_ide.xml`
180+
7. Tick "Store relative to project location"
181+
8. Click "Next"
182+
9. The Checkstyle config file contains the variable `config_loc`, and
183+
IntelliJ will ask for a value. Fill in `buildSrc/src/main/resources`.
184+
This allows the config file to reference the exclusions file in that directory.
185+
10. Click "Next", then "Finish".
186+
11. Click the box next to the new configuration to make it "Active". Without doing this,
187+
you'll have to explicitly choose the "Elasticsearch" configuration in the Checkstyle
188+
tool window and run the check manually. You can still do this with an active config.
189+
12. Click "OK" to apply the new preferences
190+
191+
#### Formatting
192+
193+
We are in the process of migrating towards automatic formatting Java file
194+
using [spotless], backed by the Eclipse formatter. If you have the [Eclipse
195+
Code Formatter] installed, you can apply formatting directly in IntelliJ.
196+
197+
1. Open **Preferences > Other Settings > Eclipse Code Formatter**
198+
2. Click "Use the Eclipse Code Formatter"
199+
3. Under "Eclipse formatter config", select "Eclipse workspace/project
200+
folder or config file"
201+
4. Click "Browse", and navigate to the file `buildSrc/formatterConfig.xml`
202+
5. Click "OK"
203+
204+
Note that only some sub-projects in the Elasticsearch project are currently
205+
fully-formatted. You can see a list of project that **are not**
206+
automatically formatted in [gradle/formatting.gradle](gradle/formatting.gradle).
207+
167208
### Importing the project into Eclipse
168209

169210
Elasticsearch builds using Gradle and Java 14. When importing into Eclipse you
@@ -699,3 +740,6 @@ non-documentation contribution. This is mentioned above, but it is worth
699740
repeating in this section because it has come up in this context.
700741

701742
[intellij]: https://blog.jetbrains.com/idea/2017/07/intellij-idea-2017-2-is-here-smart-sleek-and-snappy/
743+
[Checkstyle]: https://plugins.jetbrains.com/plugin/1065-checkstyle-idea
744+
[spotless]: https://github.com/diffplug/spotless
745+
[Eclipse Code Formatter]: https://plugins.jetbrains.com/plugin/6546-eclipse-code-formatter

build.gradle

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -287,23 +287,17 @@ gradle.projectsEvaluated {
287287
// :test:framework:test cannot run before and after :server:test
288288
return
289289
}
290-
tasks.matching {it.name.equals('integTest')}.configureEach {integTestTask ->
290+
tasks.matching { it.name.equals('integTest')}.configureEach {integTestTask ->
291291
integTestTask.mustRunAfter tasks.matching { it.name.equals("test") }
292292
}
293293

294294
configurations.matching { it.canBeResolved }.all { Configuration configuration ->
295295
dependencies.matching { it instanceof ProjectDependency }.all { ProjectDependency dep ->
296296
Project upstreamProject = dep.dependencyProject
297-
if (upstreamProject != null) {
298-
if (project.path == upstreamProject.path) {
299-
// TODO: distribution integ tests depend on themselves (!), fix that
300-
return
301-
}
297+
if (project.path != upstreamProject?.path) {
302298
for (String taskName : ['test', 'integTest']) {
303-
Task task = project.tasks.findByName(taskName)
304-
Task upstreamTask = upstreamProject.tasks.findByName(taskName)
305-
if (task != null && upstreamTask != null) {
306-
task.shouldRunAfter(upstreamTask)
299+
project.tasks.matching { it.name == taskName }.configureEach {task ->
300+
task.shouldRunAfter(upstreamProject.tasks.matching { upStreamTask -> upStreamTask.name == taskName })
307301
}
308302
}
309303
}
@@ -487,7 +481,7 @@ allprojects {
487481
subprojects {
488482
project.ext.disableTasks = { String... tasknames ->
489483
for (String taskname : tasknames) {
490-
project.tasks.named(taskname).configure { onlyIf { false } }
484+
project.tasks.named(taskname).configure { enabled = false }
491485
}
492486
}
493487
}

buildSrc/reaper/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
jar {
1+
tasks.named("jar").configure {
22
archiveFileName = "${project.name}.jar"
33
manifest {
44
attributes 'Main-Class': 'org.elasticsearch.gradle.reaper.Reaper'

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import org.elasticsearch.gradle.Version
2323
import org.elasticsearch.gradle.VersionProperties
2424
import org.gradle.api.Plugin
2525
import org.gradle.api.Project
26-
import org.gradle.api.Task
26+
import org.gradle.api.file.Directory
27+
import org.gradle.api.file.DirectoryProperty
28+
import org.gradle.api.provider.Provider
2729
import org.gradle.api.tasks.TaskProvider
2830

2931
/**
@@ -72,8 +74,13 @@ class DocsTestPlugin implements Plugin<Project> {
7274
}
7375
}
7476

75-
project.tasks.register('buildRestTests', RestTestsFromSnippetsTask) {
77+
Provider<Directory> restRootDir = project.getLayout().buildDirectory.dir("rest")
78+
TaskProvider<RestTestsFromSnippetsTask> buildRestTests = project.tasks.register('buildRestTests', RestTestsFromSnippetsTask) {
7679
defaultSubstitutions = commonDefaultSubstitutions
80+
testRoot.convention(restRootDir)
7781
}
82+
83+
// TODO: This effectively makes testRoot not customizable, which we don't do anyway atm
84+
project.sourceSets.test.output.dir(restRootDir, builtBy: buildRestTests)
7885
}
7986
}

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ package org.elasticsearch.gradle.doc
2222
import groovy.transform.PackageScope
2323
import org.elasticsearch.gradle.doc.SnippetsTask.Snippet
2424
import org.gradle.api.InvalidUserDataException
25+
import org.gradle.api.file.DirectoryProperty
2526
import org.gradle.api.tasks.Input
2627
import org.gradle.api.tasks.Internal
2728
import org.gradle.api.tasks.OutputDirectory
29+
import org.gradle.api.model.ObjectFactory
2830

31+
import javax.inject.Inject;
2932
import java.nio.file.Files
3033
import java.nio.file.Path
3134

@@ -54,19 +57,16 @@ class RestTestsFromSnippetsTask extends SnippetsTask {
5457

5558
/**
5659
* Root directory of the tests being generated. To make rest tests happy
57-
* we generate them in a testRoot() which is contained in this directory.
60+
* we generate them in a testRoot which is contained in this directory.
5861
*/
59-
@OutputDirectory
60-
File testRoot = project.file('build/rest')
62+
private DirectoryProperty testRoot
6163

6264
@Internal
6365
Set<String> names = new HashSet<>()
6466

65-
RestTestsFromSnippetsTask() {
66-
project.afterEvaluate {
67-
// Wait to set this so testRoot can be customized
68-
project.sourceSets.test.output.dir(testRoot, builtBy: this)
69-
}
67+
@Inject
68+
RestTestsFromSnippetsTask(ObjectFactory objectFactory) {
69+
testRoot = objectFactory.directoryProperty()
7070
TestBuilder builder = new TestBuilder()
7171
doFirst { outputRoot().delete() }
7272
perSnippet builder.&handleSnippet
@@ -79,10 +79,14 @@ class RestTestsFromSnippetsTask extends SnippetsTask {
7979
* contained within testRoot.
8080
*/
8181
File outputRoot() {
82-
return new File(testRoot, '/rest-api-spec/test')
82+
return new File(testRoot.get().asFile, '/rest-api-spec/test')
8383
}
8484

85-
/**
85+
@OutputDirectory
86+
DirectoryProperty getTestRoot() {
87+
return testRoot
88+
}
89+
/**
8690
* Is this snippet a candidate for conversion to `// CONSOLE`?
8791
*/
8892
static isConsoleCandidate(Snippet snippet) {

buildSrc/src/main/java/org/elasticsearch/gradle/util/GradleUtils.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.gradle.api.services.BuildService;
3333
import org.gradle.api.services.BuildServiceRegistration;
3434
import org.gradle.api.services.BuildServiceRegistry;
35+
import org.gradle.api.specs.Spec;
3536
import org.gradle.api.tasks.SourceSet;
3637
import org.gradle.api.tasks.SourceSetContainer;
3738
import org.gradle.api.tasks.TaskContainer;
@@ -82,11 +83,7 @@ public static <T extends Task> void maybeConfigure(
8283
Class<? extends T> type,
8384
Action<? super T> config
8485
) {
85-
tasks.withType(type).configureEach(task -> {
86-
if (task.getName().equals(name)) {
87-
config.execute(task);
88-
}
89-
});
86+
tasks.withType(type).matching((Spec<T>) t -> t.getName().equals(name)).configureEach(task -> { config.execute(task); });
9087
}
9188

9289
public static TaskProvider<?> findByName(TaskContainer tasks, String name) {

client/rest-high-level/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ tasks.named("integTest").configure {
7979
}
8080

8181
// Requires https://github.com/elastic/elasticsearch/pull/64403 to have this moved to task avoidance api.
82-
RestIntegTestTask asyncIntegTest = tasks.create("asyncIntegTest", RestIntegTestTask) {
82+
TaskProvider<RestIntegTestTask> asyncIntegTest = tasks.register("asyncIntegTest", RestIntegTestTask) {
8383
systemProperty 'tests.rest.async', 'true'
8484
systemProperty 'tests.rest.cluster.username', System.getProperty('tests.rest.cluster.username', 'test_user')
8585
systemProperty 'tests.rest.cluster.password', System.getProperty('tests.rest.cluster.password', 'test-password')

client/rest-high-level/src/main/java/org/elasticsearch/client/ml/job/config/CategorizationAnalyzerConfig.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.elasticsearch.client.ml.job.config;
2020

21+
import org.elasticsearch.action.admin.indices.analyze.AnalyzeAction;
2122
import org.elasticsearch.common.ParseField;
2223
import org.elasticsearch.common.settings.Settings;
2324
import org.elasticsearch.common.xcontent.ToXContentFragment;
@@ -59,9 +60,9 @@
5960
public class CategorizationAnalyzerConfig implements ToXContentFragment {
6061

6162
public static final ParseField CATEGORIZATION_ANALYZER = new ParseField("categorization_analyzer");
62-
private static final ParseField TOKENIZER = RestAnalyzeAction.Fields.TOKENIZER;
63-
private static final ParseField TOKEN_FILTERS = RestAnalyzeAction.Fields.TOKEN_FILTERS;
64-
private static final ParseField CHAR_FILTERS = RestAnalyzeAction.Fields.CHAR_FILTERS;
63+
private static final ParseField TOKENIZER = AnalyzeAction.Fields.TOKENIZER;
64+
private static final ParseField TOKEN_FILTERS = AnalyzeAction.Fields.TOKEN_FILTERS;
65+
private static final ParseField CHAR_FILTERS = AnalyzeAction.Fields.CHAR_FILTERS;
6566

6667
/**
6768
* This method is only used in the unit tests - in production code this config is always parsed as a fragment.

client/test/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ tasks.named('forbiddenApisTest').configure {
4545

4646
// JarHell is part of es server, which we don't want to pull in
4747
// TODO: Not anymore. Now in :libs:elasticsearch-core
48-
jarHell.enabled = false
48+
tasks.named("jarHell").configure { enabled = false }
4949

5050
// TODO: should we have licenses for our test deps?
5151
tasks.named("dependencyLicenses").configure { enabled = false }

0 commit comments

Comments
 (0)