Skip to content

Commit c808692

Browse files
Format everything (#2866)
1 parent 83573b8 commit c808692

File tree

218 files changed

+13406
-8840
lines changed

Some content is hidden

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

218 files changed

+13406
-8840
lines changed

build.gradle

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -70,56 +70,7 @@ apply plugin: 'opensearch.opensearchplugin'
7070
apply plugin: 'opensearch.pluginzip'
7171
apply plugin: 'opensearch.rest-test'
7272
apply plugin: 'opensearch.testclusters'
73-
// apply from: 'gradle/formatting.gradle'
74-
75-
spotless {
76-
java {
77-
// Normally this isn't necessary, but we have Java sources in
78-
// non-standard places
79-
target '**/com/amazon/dlic/**/*.java'
80-
target '**/com/amazon/security/**/*.java'
81-
target '**/test/**/*.java'
82-
target '**/integrationTest/**/*.java'
83-
84-
removeUnusedImports()
85-
eclipse().configFile rootProject.file('formatter/formatterConfig.xml')
86-
trimTrailingWhitespace()
87-
endWithNewline();
88-
89-
// note: you can use an empty string for all the imports you didn't specify explicitly, and '\\#` prefix for static imports
90-
importOrder('java', 'javax', '', 'com.amazon', 'org.opensearch', '\\#')
91-
92-
custom 'Refuse wildcard imports', {
93-
// Wildcard imports can't be resolved; fail the build
94-
if (it =~ /\s+import .*\*;/) {
95-
throw new AssertionError("Do not use wildcard imports. 'spotlessApply' cannot resolve this issue.")
96-
}
97-
}
98-
99-
// See DEVELOPER_GUIDE.md for details of when to enable this.
100-
if (System.getProperty('spotless.paddedcell') != null) {
101-
paddedCell()
102-
}
103-
}
104-
format 'misc', {
105-
target '*.md', '*.gradle', '**/*.json', '**/*.yaml', '**/*.yml', '**/*.svg'
106-
107-
trimTrailingWhitespace()
108-
endWithNewline()
109-
}
110-
format('javaFoo', JavaExtension) {
111-
112-
importOrder('java', 'javax', '', 'com.amazon', 'org.opensearch', '\\#')
113-
target '**/*.java'
114-
targetExclude '**/com/amazon/dlic/**/*.java'
115-
targetExclude '**/com/amazon/security/**/*.java'
116-
targetExclude '**/test/**/*.java'
117-
targetExclude '**/integrationTest/**/*.java'
118-
119-
trimTrailingWhitespace()
120-
endWithNewline();
121-
}
122-
}
73+
apply from: 'gradle/formatting.gradle'
12374

12475
licenseFile = rootProject.file('LICENSE.txt')
12576
noticeFile = rootProject.file('NOTICE.txt')

gradle/formatting.gradle

Lines changed: 21 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,26 @@
1-
/*
2-
* SPDX-License-Identifier: Apache-2.0
3-
*
4-
* The OpenSearch Contributors require contributions made to
5-
* this file be licensed under the Apache-2.0 license or a
6-
* compatible open source license.
7-
*
8-
* Modifications Copyright OpenSearch Contributors. See
9-
* GitHub history for details.
10-
*/
11-
12-
/*
13-
* Licensed to Elasticsearch under one or more contributor
14-
* license agreements. See the NOTICE file distributed with
15-
* this work for additional information regarding copyright
16-
* ownership. Elasticsearch licenses this file to you under
17-
* the Apache License, Version 2.0 (the "License"); you may
18-
* not use this file except in compliance with the License.
19-
* You may obtain a copy of the License at
20-
*
21-
* http://www.apache.org/licenses/LICENSE-2.0
22-
*
23-
* Unless required by applicable law or agreed to in writing,
24-
* software distributed under the License is distributed on an
25-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
26-
* KIND, either express or implied. See the License for the
27-
* specific language governing permissions and limitations
28-
* under the License.
29-
*/
30-
31-
import org.opensearch.gradle.BuildPlugin
32-
33-
/*
34-
* This script plugin configures formatting for Java source using Spotless
35-
* for Gradle. Since the act of formatting existing source can interfere
36-
* with developers' workflows, we don't automatically format all code
37-
* (yet). Instead, we maintain a list of projects that are excluded from
38-
* formatting, until we reach a point where we can comfortably format them
39-
* in one go without too much disruption.
40-
*
41-
* Any new sub-projects must not be added to the exclusions list!
42-
*
43-
* To perform a reformat, run:
44-
*
45-
* ./gradlew spotlessApply
46-
*
47-
* To check the current format, run:
48-
*
49-
* ./gradlew spotlessJavaCheck
50-
*
51-
* This is also carried out by the `precommit` task.
52-
*
53-
* For more about Spotless, see:
54-
*
55-
* https://github.com/diffplug/spotless/tree/master/plugin-gradle
56-
*/
57-
58-
org.opensearch.gradle.BuildPlugin {
59-
plugins.withType(BuildPlugin).whenPluginAdded {
60-
project.apply plugin: "com.diffplug.spotless"
61-
62-
spotless {
63-
java {
64-
// Normally this isn't necessary, but we have Java sources in
65-
// non-standard places
66-
target '**/*.java'
67-
68-
removeUnusedImports()
69-
eclipse().configFile rootProject.file('buildSrc/formatterConfig.xml')
70-
trimTrailingWhitespace()
71-
endWithNewline()
72-
73-
custom 'Refuse wildcard imports', {
74-
// Wildcard imports can't be resolved; fail the build
75-
if (it =~ /\s+import .*\*;/) {
76-
throw new AssertionError("Do not use wildcard imports. 'spotlessApply' cannot resolve this issue.")
77-
}
78-
}
79-
80-
// See DEVELOPER_GUIDE.md for details of when to enable this.
81-
if (System.getProperty('spotless.paddedcell') != null) {
82-
paddedCell()
83-
}
84-
}
85-
format 'misc', {
86-
target '*.md', '*.gradle', '**/*.yaml', '**/*.yml', '**/*.svg'
87-
88-
trimTrailingWhitespace()
89-
endWithNewline()
1+
allprojects {
2+
project.apply plugin: "com.diffplug.spotless"
3+
spotless {
4+
java {
5+
// Normally this isn't necessary, but we have Java sources in
6+
// non-standard places
7+
target '**/*.java'
8+
9+
removeUnusedImports()
10+
eclipse().configFile rootProject.file('formatter/formatterConfig.xml')
11+
trimTrailingWhitespace()
12+
endWithNewline();
13+
14+
// See DEVELOPER_GUIDE.md for details of when to enable this.
15+
if (System.getProperty('spotless.paddedcell') != null) {
16+
paddedCell()
9017
}
9118
}
19+
format 'misc', {
20+
target '*.md', '*.gradle', '**/*.json', '**/*.yaml', '**/*.yml', '**/*.svg'
9221

93-
precommit.dependsOn 'spotlessJavaCheck'
22+
trimTrailingWhitespace()
23+
endWithNewline()
24+
}
9425
}
9526
}

src/main/java/org/opensearch/security/DefaultObjectMapper.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class DefaultObjectMapper {
5757

5858
static {
5959
objectMapper.setSerializationInclusion(Include.NON_NULL);
60-
//objectMapper.enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS);
60+
// objectMapper.enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS);
6161
objectMapper.enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION);
6262
defaulOmittingObjectMapper.setSerializationInclusion(Include.NON_DEFAULT);
6363
defaulOmittingObjectMapper.enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION);
@@ -75,24 +75,31 @@ public static boolean getOrDefault(Map<String, Object> properties, String key, b
7575
if (value == null) {
7676
return defaultValue;
7777
} else if (value instanceof Boolean) {
78-
return (boolean)value;
78+
return (boolean) value;
7979
} else if (value instanceof String) {
80-
String text = ((String)value).trim();
80+
String text = ((String) value).trim();
8181
if ("true".equals(text) || "True".equals(text)) {
8282
return true;
8383
}
8484
if ("false".equals(text) || "False".equals(text)) {
8585
return false;
8686
}
87-
throw InvalidFormatException.from(null,
88-
"Cannot deserialize value of type 'boolean' from String \"" + text + "\": only \"true\" or \"false\" recognized)",
89-
null, Boolean.class);
87+
throw InvalidFormatException.from(
88+
null,
89+
"Cannot deserialize value of type 'boolean' from String \"" + text + "\": only \"true\" or \"false\" recognized)",
90+
null,
91+
Boolean.class
92+
);
9093
}
91-
throw MismatchedInputException.from(null, Boolean.class, "Cannot deserialize instance of 'boolean' out of '" + value + "' (Property: " + key + ")");
94+
throw MismatchedInputException.from(
95+
null,
96+
Boolean.class,
97+
"Cannot deserialize instance of 'boolean' out of '" + value + "' (Property: " + key + ")"
98+
);
9299
}
93100

94101
public static <T> T getOrDefault(Map<String, Object> properties, String key, T defaultValue) {
95-
T value = (T)properties.get(key);
102+
T value = (T) properties.get(key);
96103
return value != null ? value : defaultValue;
97104
}
98105

@@ -172,7 +179,7 @@ public static String writeValueAsString(Object value, boolean omitDefaults) thro
172179
return AccessController.doPrivileged(new PrivilegedExceptionAction<String>() {
173180
@Override
174181
public String run() throws Exception {
175-
return (omitDefaults?defaulOmittingObjectMapper:objectMapper).writeValueAsString(value);
182+
return (omitDefaults ? defaulOmittingObjectMapper : objectMapper).writeValueAsString(value);
176183
}
177184
});
178185
} catch (final PrivilegedActionException e) {
@@ -229,12 +236,11 @@ public static TypeFactory getTypeFactory() {
229236
}
230237

231238
public static Set<String> getFields(Class cls) {
232-
return objectMapper
233-
.getSerializationConfig()
234-
.introspect(getTypeFactory().constructType(cls))
235-
.findProperties()
236-
.stream()
237-
.map(BeanPropertyDefinition::getName)
238-
.collect(ImmutableSet.toImmutableSet());
239+
return objectMapper.getSerializationConfig()
240+
.introspect(getTypeFactory().constructType(cls))
241+
.findProperties()
242+
.stream()
243+
.map(BeanPropertyDefinition::getName)
244+
.collect(ImmutableSet.toImmutableSet());
239245
}
240246
}

0 commit comments

Comments
 (0)