Skip to content

Commit d01efa4

Browse files
Changes to keep Checkstyle happy after reformatting (#76464)
* Reformatting to keep Checkstyle after formatting * Configure spotless everywhere, and disable the tasks if necessary * Add XContentBuilder helpers, fix test * Tweaks * Add a TODO Co-authored-by: Elastic Machine <[email protected]>
1 parent 86a5772 commit d01efa4

File tree

67 files changed

+739
-398
lines changed

Some content is hidden

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

67 files changed

+739
-398
lines changed

build-tools-internal/src/main/groovy/elasticsearch.formatting.gradle

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -199,49 +199,52 @@ def projectPathsToExclude = [
199199

200200
subprojects {
201201
plugins.withType(ElasticsearchJavaPlugin).whenPluginAdded {
202-
if (projectPathsToExclude.contains(project.path) == false) {
203-
project.apply plugin: "com.diffplug.spotless"
202+
project.apply plugin: "com.diffplug.spotless"
204203

205-
spotless {
206-
java {
207-
if (project.path == ':server') {
208-
target 'src/*/java/org/elasticsearch/action/admin/cluster/repositories/**/*.java',
209-
'src/*/java/org/elasticsearch/action/admin/cluster/snapshots/**/*.java',
210-
'src/*/java/org/elasticsearch/index/snapshots/**/*.java',
211-
'src/*/java/org/elasticsearch/repositories/**/*.java',
212-
'src/*/java/org/elasticsearch/snapshots/**/*.java'
204+
spotless {
205+
java {
206+
if (project.path == ':server') {
207+
target 'src/*/java/org/elasticsearch/action/admin/cluster/repositories/**/*.java',
208+
'src/*/java/org/elasticsearch/action/admin/cluster/snapshots/**/*.java',
209+
'src/*/java/org/elasticsearch/index/snapshots/**/*.java',
210+
'src/*/java/org/elasticsearch/repositories/**/*.java',
211+
'src/*/java/org/elasticsearch/snapshots/**/*.java'
213212

214-
targetExclude 'src/main/java/org/elasticsearch/search/aggregations/metrics/HyperLogLogPlusPlus.java'
215-
} else {
216-
// Normally this isn't necessary, but we have Java sources in
217-
// non-standard places
218-
target 'src/**/*.java'
219-
}
213+
targetExclude 'src/main/java/org/elasticsearch/search/aggregations/metrics/HyperLogLogPlusPlus.java'
214+
} else {
215+
// Normally this isn't necessary, but we have Java sources in
216+
// non-standard places
217+
target 'src/**/*.java'
218+
}
220219

221-
toggleOffOn('@formatter:off', '@formatter:on') // use `@formatter:off` and `@formatter:on` to toggle formatting - ONLY IF STRICTLY NECESSARY
222-
removeUnusedImports()
223-
importOrderFile rootProject.file('build-tools-internal/elastic.importorder')
224-
eclipse().configFile rootProject.file('build-tools-internal/formatterConfig.xml')
225-
trimTrailingWhitespace()
220+
toggleOffOn('@formatter:off', '@formatter:on') // use `@formatter:off` and `@formatter:on` to toggle formatting - ONLY IF STRICTLY NECESSARY
221+
removeUnusedImports()
222+
importOrderFile rootProject.file('build-tools-internal/elastic.importorder')
223+
eclipse().configFile rootProject.file('build-tools-internal/formatterConfig.xml')
224+
trimTrailingWhitespace()
226225

227-
// Sometimes Spotless will report a "misbehaving rule which can't make up its
228-
// mind" and will recommend enabling the `paddedCell()` setting. If you
229-
// enabled this setting and run the format check again,
230-
// Spotless will write files to
231-
// `$PROJECT/build/spotless-diagnose-java/` to aid diagnosis. It writes
232-
// different copies of the formatted files, so that you can see how they
233-
// differ and infer what is the problem.
226+
// Sometimes Spotless will report a "misbehaving rule which can't make up its
227+
// mind" and will recommend enabling the `paddedCell()` setting. If you
228+
// enabled this setting and run the format check again,
229+
// Spotless will write files to
230+
// `$PROJECT/build/spotless-diagnose-java/` to aid diagnosis. It writes
231+
// different copies of the formatted files, so that you can see how they
232+
// differ and infer what is the problem.
234233

235-
// The `paddedCell()` option is disabled for normal operation so that any
236-
// misbehaviour is detected, and not just suppressed. You can enabled the
237-
// option from the command line by running Gradle with `-Dspotless.paddedcell`.
238-
if (providers.systemProperty('spotless.paddedcell').forUseAtConfigurationTime().isPresent()) {
239-
paddedCell()
240-
}
234+
// The `paddedCell()` option is disabled for normal operation so that any
235+
// misbehaviour is detected, and not just suppressed. You can enabled the
236+
// option from the command line by running Gradle with `-Dspotless.paddedcell`.
237+
if (providers.systemProperty('spotless.paddedcell').forUseAtConfigurationTime().isPresent()) {
238+
paddedCell()
241239
}
242240
}
241+
}
243242

244-
tasks.named("precommit").configure { dependsOn 'spotlessJavaCheck' }
243+
if (projectPathsToExclude.contains(project.path)) {
244+
tasks.named('spotlessJavaCheck').configure { enabled = false }
245+
tasks.named('spotlessApply').configure { enabled = false }
245246
}
247+
248+
tasks.named("precommit").configure { dependsOn 'spotlessJavaCheck' }
246249
}
247250
}

client/rest-high-level/src/main/java/org/elasticsearch/client/analytics/ParsedInference.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.io.IOException;
2222
import java.util.List;
2323

24+
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;
25+
2426
/**
2527
* This class parses the superset of all possible fields that may be written by
2628
* InferenceResults. The warning field is mutually exclusive with all the other fields.
@@ -29,8 +31,6 @@
2931
* Boolean or a Double. For regression results {@link #getValue()} is always
3032
* a Double.
3133
*/
32-
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;
33-
3434
public class ParsedInference extends ParsedAggregation {
3535

3636
@SuppressWarnings("unchecked")

client/rest-high-level/src/main/java/org/elasticsearch/client/graph/Vertex.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,25 +162,31 @@ public void setWeight(final double weight) {
162162
this.weight = weight;
163163
}
164164

165+
// @formatter:off
165166
/**
166167
* If the {@link GraphExploreRequest#useSignificance(boolean)} is true (the default)
167168
* this statistic is available.
168169
* @return the number of documents in the index that contain this term (see bg_count in
169-
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html">
170-
* the significant_terms aggregation</a>)
170+
* <a
171+
* href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html"
172+
* >the significant_terms aggregation</a>)
171173
*/
174+
// @formatter:on
172175
public long getBg() {
173176
return bg;
174177
}
175178

179+
// @formatter:off
176180
/**
177181
* If the {@link GraphExploreRequest#useSignificance(boolean)} is true (the default)
178182
* this statistic is available.
179183
* Together with {@link #getBg()} these numbers are used to derive the significance of a term.
180184
* @return the number of documents in the sample of best matching documents that contain this term (see fg_count in
181-
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html">
182-
* the significant_terms aggregation</a>)
185+
* <a
186+
* href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html"
187+
* >the significant_terms aggregation</a>)
183188
*/
189+
// @formatter:on
184190
public long getFg() {
185191
return fg;
186192
}

client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,10 +1269,14 @@ public void testIndexPutSettingNonExistent() throws IOException {
12691269
exception = expectThrows(ElasticsearchException.class, () -> execute(indexUpdateSettingsRequest,
12701270
highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync));
12711271
assertThat(exception.status(), equalTo(RestStatus.BAD_REQUEST));
1272-
assertThat(exception.getMessage(), equalTo(
1272+
assertThat(
1273+
exception.getMessage(),
1274+
equalTo(
12731275
"Elasticsearch exception [type=illegal_argument_exception, "
1274-
+ "reason=unknown setting [index.no_idea_what_you_are_talking_about] please check that any required plugins are installed, "
1275-
+ "or check the breaking changes documentation for removed settings]"));
1276+
+ "reason=unknown setting [index.no_idea_what_you_are_talking_about] please check that any required plugins "
1277+
+ "are installed, or check the breaking changes documentation for removed settings]"
1278+
)
1279+
);
12761280
}
12771281

12781282
@SuppressWarnings("unchecked")

client/rest-high-level/src/test/java/org/elasticsearch/client/MachineLearningGetResultsIT.java

Lines changed: 112 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@
3535
import org.elasticsearch.client.ml.job.results.OverallBucket;
3636
import org.elasticsearch.core.TimeValue;
3737
import org.elasticsearch.common.xcontent.XContentType;
38+
import org.elasticsearch.test.XContentTestUtils;
3839
import org.junit.After;
3940
import org.junit.Before;
4041

4142
import java.io.IOException;
4243
import java.util.Arrays;
4344
import java.util.Date;
45+
import java.util.HashMap;
4446
import java.util.List;
47+
import java.util.Map;
4548

4649
import static org.hamcrest.Matchers.closeTo;
4750
import static org.hamcrest.Matchers.equalTo;
@@ -138,55 +141,133 @@ private void addCategoriesIndexRequests(BulkRequest bulkRequest) {
138141
}
139142
}
140143

141-
private void addModelSnapshotIndexRequests(BulkRequest bulkRequest) {
144+
private void addModelSnapshotIndexRequests(BulkRequest bulkRequest) throws IOException {
142145
// Index a number of model snapshots, one of which contains the new model_size_stats fields
143146
// 'model_bytes_exceeded' and 'model_bytes_memory_limit' that were introduced in 7.2.0.
144147
// We want to verify that we can parse the snapshots whether or not these fields are present.
145148
{
146149
IndexRequest indexRequest = new IndexRequest(RESULTS_INDEX);
147-
indexRequest.source("{\"job_id\":\"" + JOB_ID + "\", \"timestamp\":1541587919000, " +
148-
"\"description\":\"State persisted due to job close at 2018-11-07T10:51:59+0000\", \"snapshot_id\":\"1541587919\"," +
149-
"\"snapshot_doc_count\":1, \"model_size_stats\":{\"job_id\":\"" + JOB_ID + "\", \"result_type\":\"model_size_stats\"," +
150-
"\"model_bytes\":51722, \"peak_model_bytes\":61322, \"model_bytes_exceeded\":10762, \"model_bytes_memory_limit\":40960," +
151-
"\"total_by_field_count\":3, \"total_over_field_count\":0, \"total_partition_field_count\":2," +
152-
"\"bucket_allocation_failures_count\":0, \"memory_status\":\"ok\", \"log_time\":1541587919000," +
153-
" \"timestamp\":1519930800000},\"latest_record_time_stamp\":1519931700000, \"latest_result_time_stamp\":1519930800000," +
154-
" \"retain\":false }", XContentType.JSON);
150+
Map<String, Object> modelSizeStats = new HashMap<>();
151+
modelSizeStats.put("job_id", JOB_ID);
152+
modelSizeStats.put("result_type", "model_size_stats");
153+
modelSizeStats.put("model_bytes", 51722);
154+
modelSizeStats.put("peak_model_bytes", 61322);
155+
modelSizeStats.put("model_bytes_exceeded", 10762);
156+
modelSizeStats.put("model_bytes_memory_limit", 40960);
157+
modelSizeStats.put("total_by_field_count", 3);
158+
modelSizeStats.put("total_over_field_count", 0);
159+
modelSizeStats.put("total_partition_field_count", 2);
160+
modelSizeStats.put("bucket_allocation_failures_count", 0);
161+
modelSizeStats.put("memory_status", "ok");
162+
modelSizeStats.put("log_time", 1541587919000L);
163+
modelSizeStats.put("timestamp", 1519930800000L);
164+
165+
Map<String, Object> source = new HashMap<>();
166+
source.put("job_id", JOB_ID);
167+
source.put("timestamp", 1541587919000L);
168+
source.put("description", "State persisted due to job close at 2018-11-07T10:51:59+0000");
169+
source.put("snapshot_id", "1541587919");
170+
source.put("snapshot_doc_count", 1);
171+
source.put("latest_record_time_stamp", 1519931700000L);
172+
source.put("latest_result_time_stamp", 1519930800000L);
173+
source.put("retain", false);
174+
source.put("model_size_stats", modelSizeStats);
175+
176+
indexRequest.source(XContentTestUtils.convertToXContent(source, XContentType.JSON), XContentType.JSON);
155177
bulkRequest.add(indexRequest);
156178
}
157179
// Also index one that contains 'memory_assignment_basis', which was added in 7.11
158180
{
159181
IndexRequest indexRequest = new IndexRequest(RESULTS_INDEX);
160-
indexRequest.source("{\"job_id\":\"" + JOB_ID + "\", \"timestamp\":1541587929000, " +
161-
"\"description\":\"State persisted due to job close at 2018-11-07T10:52:09+0000\", \"snapshot_id\":\"1541587929\"," +
162-
"\"snapshot_doc_count\":1, \"model_size_stats\":{\"job_id\":\"" + JOB_ID + "\", \"result_type\":\"model_size_stats\"," +
163-
"\"model_bytes\":51722, \"peak_model_bytes\":61322, \"model_bytes_exceeded\":10762, \"model_bytes_memory_limit\":40960," +
164-
"\"total_by_field_count\":3, \"total_over_field_count\":0, \"total_partition_field_count\":2," +
165-
"\"bucket_allocation_failures_count\":0, \"memory_status\":\"ok\", \"assignment_memory_basis\":\"model_memory_limit\"," +
166-
" \"log_time\":1541587929000, \"timestamp\":1519930800000},\"latest_record_time_stamp\":1519931700000," +
167-
"\"latest_result_time_stamp\":1519930800000, \"retain\":false }", XContentType.JSON);
182+
183+
Map<String, Object> modelSizeStats = new HashMap<>();
184+
modelSizeStats.put("job_id", JOB_ID);
185+
modelSizeStats.put("result_type", "model_size_stats");
186+
modelSizeStats.put("model_bytes", 51722);
187+
modelSizeStats.put("peak_model_bytes", 61322);
188+
modelSizeStats.put("model_bytes_exceeded", 10762);
189+
modelSizeStats.put("model_bytes_memory_limit", 40960);
190+
modelSizeStats.put("total_by_field_count", 3);
191+
modelSizeStats.put("total_over_field_count", 0);
192+
modelSizeStats.put("total_partition_field_count", 2);
193+
modelSizeStats.put("bucket_allocation_failures_count", 0);
194+
modelSizeStats.put("memory_status", "ok");
195+
modelSizeStats.put("assignment_memory_basis", "model_memory_limit");
196+
modelSizeStats.put("log_time", 1541587929000L);
197+
modelSizeStats.put("timestamp", 1519930800000L);
198+
199+
Map<String, Object> source = new HashMap<>();
200+
source.put("job_id", JOB_ID);
201+
source.put("timestamp", 1541587929000L);
202+
source.put("description", "State persisted due to job close at 2018-11-07T10:52:09+0000");
203+
source.put("snapshot_id", "1541587929");
204+
source.put("snapshot_doc_count", 1);
205+
source.put("latest_record_time_stamp", 1519931700000L);
206+
source.put("latest_result_time_stamp", 1519930800000L);
207+
source.put("retain", false);
208+
source.put("model_size_stats", modelSizeStats);
209+
210+
indexRequest.source(XContentTestUtils.convertToXContent(source, XContentType.JSON), XContentType.JSON);
168211
bulkRequest.add(indexRequest);
169212
}
170213
{
171214
IndexRequest indexRequest = new IndexRequest(RESULTS_INDEX);
172-
indexRequest.source("{\"job_id\":\"" + JOB_ID + "\", \"timestamp\":1541588919000, " +
173-
"\"description\":\"State persisted due to job close at 2018-11-07T11:08:39+0000\", \"snapshot_id\":\"1541588919\"," +
174-
"\"snapshot_doc_count\":1, \"model_size_stats\":{\"job_id\":\"" + JOB_ID + "\", \"result_type\":\"model_size_stats\"," +
175-
"\"model_bytes\":51722, \"peak_model_bytes\":61322, \"total_by_field_count\":3, \"total_over_field_count\":0," +
176-
"\"total_partition_field_count\":2,\"bucket_allocation_failures_count\":0, \"memory_status\":\"ok\"," +
177-
"\"log_time\":1541588919000,\"timestamp\":1519930800000},\"latest_record_time_stamp\":1519931700000," +
178-
"\"latest_result_time_stamp\":1519930800000, \"retain\":false }", XContentType.JSON);
215+
216+
Map<String, Object> modelSizeStats = new HashMap<>();
217+
modelSizeStats.put("job_id", JOB_ID);
218+
modelSizeStats.put("result_type", "model_size_stats");
219+
modelSizeStats.put("model_bytes", 51722);
220+
modelSizeStats.put("peak_model_bytes", 61322);
221+
modelSizeStats.put("total_by_field_count", 3);
222+
modelSizeStats.put("total_over_field_count", 0);
223+
modelSizeStats.put("total_partition_field_count", 2);
224+
modelSizeStats.put("bucket_allocation_failures_count", 0);
225+
modelSizeStats.put("memory_status", "ok");
226+
modelSizeStats.put("log_time", 1541588919000L);
227+
modelSizeStats.put("timestamp", 1519930800000L);
228+
229+
Map<String, Object> source = new HashMap<>();
230+
source.put("job_id", JOB_ID);
231+
source.put("timestamp", 1541588919000L);
232+
source.put("description", "State persisted due to job close at 2018-11-07T11:08:39+0000");
233+
source.put("snapshot_id", "1541588919");
234+
source.put("snapshot_doc_count", 1);
235+
source.put("latest_record_time_stamp", 1519931700000L);
236+
source.put("latest_result_time_stamp", 1519930800000L);
237+
source.put("retain", false);
238+
source.put("model_size_stats", modelSizeStats);
239+
240+
indexRequest.source(XContentTestUtils.convertToXContent(source, XContentType.JSON), XContentType.JSON);
179241
bulkRequest.add(indexRequest);
180242
}
181243
{
182244
IndexRequest indexRequest = new IndexRequest(RESULTS_INDEX);
183-
indexRequest.source("{\"job_id\":\"" + JOB_ID + "\", \"timestamp\":1541589919000, " +
184-
"\"description\":\"State persisted due to job close at 2018-11-07T11:25:19+0000\", \"snapshot_id\":\"1541589919\"," +
185-
"\"snapshot_doc_count\":1, \"model_size_stats\":{\"job_id\":\"" + JOB_ID + "\", \"result_type\":\"model_size_stats\"," +
186-
"\"model_bytes\":51722, \"peak_model_bytes\":61322, \"total_by_field_count\":3, \"total_over_field_count\":0," +
187-
"\"total_partition_field_count\":2,\"bucket_allocation_failures_count\":0, \"memory_status\":\"ok\"," +
188-
"\"log_time\":1541589919000,\"timestamp\":1519930800000},\"latest_record_time_stamp\":1519931700000," +
189-
"\"latest_result_time_stamp\":1519930800000, \"retain\":false }", XContentType.JSON);
245+
246+
Map<String, Object> modelSizeStats = new HashMap<>();
247+
modelSizeStats.put("job_id", JOB_ID);
248+
modelSizeStats.put("result_type", "model_size_stats");
249+
modelSizeStats.put("model_bytes", 51722);
250+
modelSizeStats.put("peak_model_bytes", 61322);
251+
modelSizeStats.put("total_by_field_count", 3);
252+
modelSizeStats.put("total_over_field_count", 0);
253+
modelSizeStats.put("total_partition_field_count", 2);
254+
modelSizeStats.put("bucket_allocation_failures_count", 0);
255+
modelSizeStats.put("memory_status", "ok");
256+
modelSizeStats.put("log_time", 1541589919000L);
257+
modelSizeStats.put("timestamp", 1519930800000L);
258+
259+
Map<String, Object> source = new HashMap<>();
260+
source.put("job_id", JOB_ID);
261+
source.put("timestamp", 1541589919000L);
262+
source.put("description", "State persisted due to job close at 2018-11-07T11:25:19+0000");
263+
source.put("snapshot_id", "1541589919");
264+
source.put("snapshot_doc_count", 1);
265+
source.put("latest_record_time_stamp", 1519931700000L);
266+
source.put("latest_result_time_stamp", 1519930800000L);
267+
source.put("retain", false);
268+
source.put("model_size_stats", modelSizeStats);
269+
270+
indexRequest.source(XContentTestUtils.convertToXContent(source, XContentType.JSON), XContentType.JSON);
190271
bulkRequest.add(indexRequest);
191272
}
192273
}

client/rest/src/main/java/org/elasticsearch/client/Response.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public HttpEntity getEntity() {
121121
* Length of RFC 1123 format (with quotes and leading space), used in
122122
* matchWarningHeaderPatternByPrefix(String).
123123
*/
124+
// @formatter:off
124125
private static final int WARNING_HEADER_DATE_LENGTH = 0
125126
+ 1
126127
+ 1
@@ -131,6 +132,7 @@ public HttpEntity getEntity() {
131132
+ 2 + 1 + 2 + 1 + 2 + 1
132133
+ 3
133134
+ 1;
135+
// @formatter:on
134136

135137
/**
136138
* Tests if a string matches the RFC 7234 specification for warning headers.

0 commit comments

Comments
 (0)