Skip to content

Commit 27e925c

Browse files
authored
Add spotless for formatting Java source files (#120)
* Add spotlessJavaCheck. Format existing code. - add spotlessJavaCheck. - format existing code. - upgrade deprecated gradle constructs. Signed-off-by: Mulugeta Mammo <mulugeta.mammo@intel.com> * Apply spotless to files in the .github directory. Signed-off-by: Mulugeta Mammo <mulugeta.mammo@intel.com> * Fix three minor issues: 1) Remove the Elasticsearch attribution in spotless formatter. 2) Use java instead of 'java'. 3) Remove version resolution for jackson. Signed-off-by: Mulugeta Mammo <mulugeta.mammo@intel.com> --------- Signed-off-by: Mulugeta Mammo <mulugeta.mammo@intel.com>
1 parent be53471 commit 27e925c

File tree

18 files changed

+605
-187
lines changed

18 files changed

+605
-187
lines changed

.github/workflows/add-untriaged.yml

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
name: Apply 'untriaged' label during issue lifecycle
2-
3-
on:
4-
issues:
5-
types: [opened, reopened, transferred]
6-
7-
jobs:
8-
apply-label:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- uses: actions/github-script@v6
12-
with:
13-
script: |
14-
github.rest.issues.addLabels({
15-
issue_number: context.issue.number,
16-
owner: context.repo.owner,
17-
repo: context.repo.repo,
18-
labels: ['untriaged']
19-
})
1+
name: Apply 'untriaged' label during issue lifecycle
2+
3+
on:
4+
issues:
5+
types: [opened, reopened, transferred]
6+
7+
jobs:
8+
apply-label:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/github-script@v6
12+
with:
13+
script: |
14+
github.rest.issues.addLabels({
15+
issue_number: context.issue.number,
16+
owner: context.repo.owner,
17+
repo: context.repo.repo,
18+
labels: ['untriaged']
19+
})

.github/workflows/delete-backport-branch.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: Delete merged branch of the backport PRs
2-
on:
2+
on:
33
pull_request:
44
types:
55
- closed
6-
6+
77
jobs:
88
delete-branch:
99
runs-on: ubuntu-latest

.github/workflows/publish-maven-snapshots.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ jobs:
3232
export SONATYPE_PASSWORD=$(aws secretsmanager get-secret-value --secret-id maven-snapshots-password --query SecretString --output text)
3333
echo "::add-mask::$SONATYPE_USERNAME"
3434
echo "::add-mask::$SONATYPE_PASSWORD"
35-
./gradlew publishPluginZipPublicationToSnapshotsRepository
35+
./gradlew publishPluginZipPublicationToSnapshotsRepository

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Custom Codecs
55
Custom Codecs plugin makes it possible for users to provide custom Lucene codecs for loading through Apache Lucene's `NamedSPILoader`.
6-
These codecs can be used to customize the on-disk representation of the opensearch indexes. For example, zstd compression can be used for
6+
These codecs can be used to customize the on-disk representation of the opensearch indexes. For example, zstd compression can be used for
77
`StoredField` types through the `ZstdCodec`.
88

99
## Security
@@ -13,4 +13,3 @@ See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more inform
1313
## License
1414

1515
This project is licensed under the Apache-2.0 License.
16-

build.gradle

+22-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@
99
* GitHub history for details.
1010
*/
1111

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+
1231
buildscript {
1332
ext {
1433
opensearch_group = "org.opensearch"
@@ -32,12 +51,14 @@ buildscript {
3251

3352
plugins {
3453
id 'java'
54+
id 'com.diffplug.spotless' version '6.25.0'
3555
}
3656

3757
apply plugin: 'opensearch.opensearchplugin'
3858
apply plugin: 'opensearch.internal-cluster-test'
3959
apply plugin: 'opensearch.pluginzip'
4060
apply plugin: 'opensearch.rest-test'
61+
apply from: 'gradle/formatting.gradle'
4162

4263
repositories {
4364
mavenLocal()
@@ -56,7 +77,7 @@ allprojects {
5677
version += "-SNAPSHOT"
5778
}
5879

59-
plugins.withId('java') {
80+
java {
6081
targetCompatibility = JavaVersion.VERSION_11
6182
sourceCompatibility = JavaVersion.VERSION_11
6283
}

bwc-test/src/test/java/org/opensearch/customcodecs/bwc/CustomCodecsBwcCompatibilityIT.java

+55-66
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@
77
*/
88
package org.opensearch.customcodecs.bwc;
99

10-
import java.io.IOException;
11-
import java.security.KeyManagementException;
12-
import java.security.KeyStoreException;
13-
import java.security.NoSuchAlgorithmException;
14-
import java.util.HashMap;
15-
import java.util.List;
16-
import java.util.Map;
17-
import java.util.Objects;
18-
import javax.net.ssl.SSLEngine;
19-
2010
import org.apache.hc.client5.http.auth.AuthScope;
2111
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
2212
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
@@ -29,10 +19,6 @@
2919
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
3020
import org.apache.hc.core5.reactor.ssl.TlsDetails;
3121
import org.apache.hc.core5.ssl.SSLContextBuilder;
32-
33-
import org.junit.AfterClass;
34-
import org.junit.Assume;
35-
import org.junit.Before;
3622
import org.opensearch.client.Response;
3723
import org.opensearch.client.RestClient;
3824
import org.opensearch.client.RestClientBuilder;
@@ -45,6 +31,20 @@
4531
import org.opensearch.core.xcontent.XContentBuilder;
4632
import org.opensearch.customcodecs.bwc.helper.RestHelper;
4733
import org.opensearch.test.rest.OpenSearchRestTestCase;
34+
import org.junit.AfterClass;
35+
import org.junit.Assume;
36+
import org.junit.Before;
37+
38+
import javax.net.ssl.SSLEngine;
39+
40+
import java.io.IOException;
41+
import java.security.KeyManagementException;
42+
import java.security.KeyStoreException;
43+
import java.security.NoSuchAlgorithmException;
44+
import java.util.HashMap;
45+
import java.util.List;
46+
import java.util.Map;
47+
import java.util.Objects;
4848

4949
import static org.opensearch.client.RestClientBuilder.DEFAULT_MAX_CONN_PER_ROUTE;
5050
import static org.opensearch.client.RestClientBuilder.DEFAULT_MAX_CONN_TOTAL;
@@ -62,14 +62,10 @@ public void testSetup() throws IOException {
6262
logger.info("Running Test for Cluster Type: {}", CLUSTER_TYPE);
6363
CLUSTER_NAME = System.getProperty("tests.clustername");
6464
if (testUserRestClient == null) {
65-
testUserRestClient = buildClient(
66-
super.restClientSettings(),
67-
super.getClusterHosts().toArray(new HttpHost[0])
68-
);
65+
testUserRestClient = buildClient(super.restClientSettings(), super.getClusterHosts().toArray(new HttpHost[0]));
6966
}
7067
}
7168

72-
7369
@Override
7470
protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOException {
7571
RestClientBuilder builder = RestClient.builder(hosts);
@@ -97,30 +93,26 @@ protected void configureHttpOrHttpsClient(RestClientBuilder builder, Settings se
9793
credentialsProvider.setCredentials(anyScope, new UsernamePasswordCredentials(username, password.toCharArray()));
9894

9995
try {
100-
final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder
101-
.create()
102-
.setHostnameVerifier(NoopHostnameVerifier.INSTANCE)
103-
.setSslContext(SSLContextBuilder.create().loadTrustMaterial(null, (chains, authType) -> true).build())
104-
// See https://issues.apache.org/jira/browse/HTTPCLIENT-2219
105-
.setTlsDetailsFactory(new Factory<SSLEngine, TlsDetails>() {
106-
@Override
107-
public TlsDetails create(final SSLEngine sslEngine) {
108-
return new TlsDetails(sslEngine.getSession(), sslEngine.getApplicationProtocol());
109-
}
110-
})
111-
.build();
96+
final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder.create()
97+
.setHostnameVerifier(NoopHostnameVerifier.INSTANCE)
98+
.setSslContext(SSLContextBuilder.create().loadTrustMaterial(null, (chains, authType) -> true).build())
99+
// See https://issues.apache.org/jira/browse/HTTPCLIENT-2219
100+
.setTlsDetailsFactory(new Factory<SSLEngine, TlsDetails>() {
101+
@Override
102+
public TlsDetails create(final SSLEngine sslEngine) {
103+
return new TlsDetails(sslEngine.getSession(), sslEngine.getApplicationProtocol());
104+
}
105+
})
106+
.build();
112107

113108
builder.setHttpClientConfigCallback(httpClientBuilder -> {
114-
final PoolingAsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder
115-
.create()
116-
.setMaxConnPerRoute(DEFAULT_MAX_CONN_PER_ROUTE)
117-
.setMaxConnTotal(DEFAULT_MAX_CONN_TOTAL)
118-
.setTlsStrategy(tlsStrategy)
119-
.build();
120-
121-
return httpClientBuilder
122-
.setDefaultCredentialsProvider(credentialsProvider)
123-
.setConnectionManager(connectionManager);
109+
final PoolingAsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder.create()
110+
.setMaxConnPerRoute(DEFAULT_MAX_CONN_PER_ROUTE)
111+
.setMaxConnTotal(DEFAULT_MAX_CONN_TOTAL)
112+
.setTlsStrategy(tlsStrategy)
113+
.build();
114+
115+
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider).setConnectionManager(connectionManager);
124116
});
125117
} catch (final NoSuchAlgorithmException | KeyManagementException | KeyStoreException ex) {
126118
throw new IOException(ex);
@@ -149,19 +141,17 @@ protected final boolean preserveReposUponCompletion() {
149141
return true;
150142
}
151143

152-
153144
@Override
154145
protected final Settings restClientSettings() {
155146
return Settings.builder()
156-
.put(super.restClientSettings())
157-
// increase the timeout here to 90 seconds to handle long waits for a green
158-
// cluster health. the waits for green need to be longer than a minute to
159-
// account for delayed shards
160-
.put(OpenSearchRestTestCase.CLIENT_SOCKET_TIMEOUT, "90s")
161-
.build();
147+
.put(super.restClientSettings())
148+
// increase the timeout here to 90 seconds to handle long waits for a green
149+
// cluster health. the waits for green need to be longer than a minute to
150+
// account for delayed shards
151+
.put(OpenSearchRestTestCase.CLIENT_SOCKET_TIMEOUT, "90s")
152+
.build();
162153
}
163154

164-
165155
/**
166156
* Tests backward compatibility by created a test user and role with DLS, FLS and masked field settings. Ingests
167157
* data into a test index and runs a matchAll query against the same.
@@ -176,7 +166,6 @@ public void testDataIngestionAndSearchBackwardsCompatibility() throws Exception
176166
searchMatchAll(index);
177167
}
178168

179-
180169
/**
181170
* Ingests data into the test index
182171
*
@@ -195,7 +184,7 @@ private void ingestData(String index) throws IOException {
195184
put("_index", index);
196185
}
197186
});
198-
187+
199188
try (final XContentBuilder contentBuilder = MediaTypeRegistry.JSON.contentBuilder()) {
200189
contentBuilder.map(indexRequest);
201190
bulkRequestBody.append(contentBuilder.toString() + "\n");
@@ -204,10 +193,10 @@ private void ingestData(String index) throws IOException {
204193
bulkRequestBody.append(Song.randomSong().asJson() + "\n");
205194
}
206195
List<Response> responses = RestHelper.requestAgainstAllNodes(
207-
testUserRestClient,
208-
"POST",
209-
"_bulk?refresh=wait_for",
210-
RestHelper.toHttpEntity(bulkRequestBody.toString())
196+
testUserRestClient,
197+
"POST",
198+
"_bulk?refresh=wait_for",
199+
RestHelper.toHttpEntity(bulkRequestBody.toString())
211200
);
212201
responses.forEach(r -> assertEquals(200, r.getStatusLine().getStatusCode()));
213202
}
@@ -223,10 +212,10 @@ private void searchMatchAll(String index) throws IOException {
223212
int numberOfRequests = Randomness.get().nextInt(10);
224213
while (numberOfRequests-- > 0) {
225214
List<Response> responses = RestHelper.requestAgainstAllNodes(
226-
testUserRestClient,
227-
"POST",
228-
index + "/_search",
229-
RestHelper.toHttpEntity(matchAllQuery)
215+
testUserRestClient,
216+
"POST",
217+
index + "/_search",
218+
RestHelper.toHttpEntity(matchAllQuery)
230219
);
231220
responses.forEach(r -> assertEquals(200, r.getStatusLine().getStatusCode()));
232221
}
@@ -247,13 +236,13 @@ private void createIndexIfNotExists(String index) throws IOException {
247236

248237
// creating index
249238
createIndex(
250-
index,
251-
Settings.builder()
252-
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
253-
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
254-
.put("index.codec", randomFrom("zstd", "zstd_no_dict"))
255-
.put("index.codec.compression_level", randomIntBetween(1, 6))
256-
.build()
239+
index,
240+
Settings.builder()
241+
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
242+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
243+
.put("index.codec", randomFrom("zstd", "zstd_no_dict"))
244+
.put("index.codec.compression_level", randomIntBetween(1, 6))
245+
.build()
257246
);
258247
ensureGreen(index);
259248
}

bwc-test/src/test/java/org/opensearch/customcodecs/bwc/Song.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
*/
1010
package org.opensearch.customcodecs.bwc;
1111

12+
import org.opensearch.common.Randomness;
13+
import org.opensearch.core.xcontent.MediaTypeRegistry;
14+
import org.opensearch.core.xcontent.XContentBuilder;
15+
1216
import java.io.IOException;
1317
import java.util.Map;
1418
import java.util.Objects;
1519
import java.util.UUID;
1620

17-
import org.opensearch.common.Randomness;
18-
import org.opensearch.core.xcontent.MediaTypeRegistry;
19-
import org.opensearch.core.xcontent.XContentBuilder;
20-
2121
public class Song {
2222

2323
public static final String FIELD_TITLE = "title";
@@ -57,12 +57,12 @@ public class Song {
5757
public static final String QUERY_TITLE_MAGNUM_OPUS = FIELD_TITLE + ":" + TITLE_MAGNUM_OPUS;
5858

5959
public static final Song[] SONGS = {
60-
new Song(ARTIST_FIRST, TITLE_MAGNUM_OPUS, LYRICS_1, 1, GENRE_ROCK),
61-
new Song(ARTIST_STRING, TITLE_SONG_1_PLUS_1, LYRICS_2, 2, GENRE_BLUES),
62-
new Song(ARTIST_TWINS, TITLE_NEXT_SONG, LYRICS_3, 3, GENRE_JAZZ),
63-
new Song(ARTIST_NO, TITLE_POISON, LYRICS_4, 4, GENRE_ROCK),
64-
new Song(ARTIST_YES, TITLE_AFFIRMATIVE, LYRICS_5, 5, GENRE_BLUES),
65-
new Song(ARTIST_UNKNOWN, TITLE_CONFIDENTIAL, LYRICS_6, 6, GENRE_JAZZ)};
60+
new Song(ARTIST_FIRST, TITLE_MAGNUM_OPUS, LYRICS_1, 1, GENRE_ROCK),
61+
new Song(ARTIST_STRING, TITLE_SONG_1_PLUS_1, LYRICS_2, 2, GENRE_BLUES),
62+
new Song(ARTIST_TWINS, TITLE_NEXT_SONG, LYRICS_3, 3, GENRE_JAZZ),
63+
new Song(ARTIST_NO, TITLE_POISON, LYRICS_4, 4, GENRE_ROCK),
64+
new Song(ARTIST_YES, TITLE_AFFIRMATIVE, LYRICS_5, 5, GENRE_BLUES),
65+
new Song(ARTIST_UNKNOWN, TITLE_CONFIDENTIAL, LYRICS_6, 6, GENRE_JAZZ) };
6666

6767
private final String artist;
6868
private final String title;
@@ -111,11 +111,11 @@ public String asJson() throws IOException {
111111

112112
public static Song randomSong() {
113113
return new Song(
114-
UUID.randomUUID().toString(),
115-
UUID.randomUUID().toString(),
116-
UUID.randomUUID().toString(),
117-
Randomness.get().nextInt(5),
118-
UUID.randomUUID().toString()
114+
UUID.randomUUID().toString(),
115+
UUID.randomUUID().toString(),
116+
UUID.randomUUID().toString(),
117+
Randomness.get().nextInt(5),
118+
UUID.randomUUID().toString()
119119
);
120120
}
121121
}

0 commit comments

Comments
 (0)