Skip to content

Commit 629adfb

Browse files
committed
[Gradle] Spotless plugin update
provides better configuration cache support requires some rework due to changed defaults
1 parent cd2433d commit 629adfb

File tree

13 files changed

+252
-64
lines changed

13 files changed

+252
-64
lines changed

build-tools-internal/build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,12 @@ tasks.named("jar") {
386386

387387
spotless {
388388
java {
389-
// IDEs can sometimes run annotation processors that leave files in
390-
// here, causing Spotless to complain. Even though this path ought not
391-
// to exist, exclude it anyway in order to avoid spurious failures.
392-
toggleOffOn()
389+
// workaround for https://github.com/diffplug/spotless/issues/2317
390+
//toggleOffOn()
391+
target project.fileTree("src/main/java") {
392+
include '**/*.java'
393+
exclude '**/DockerBase.java'
394+
}
393395
}
394396
}
395397

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ org.gradle.welcome=never
22
org.gradle.warning.mode=none
33
org.gradle.parallel=true
44
# We need to declare --add-exports to make spotless working seamlessly with jdk16
5-
org.gradle.jvmargs=-XX:+HeapDumpOnOutOfMemoryError -Xss2m --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
5+
org.gradle.jvmargs=-XX:+HeapDumpOnOutOfMemoryError -Xss2m --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED
66

77
# Enforce the build to fail on deprecated gradle api usage
88
systemProp.org.gradle.warning.mode=fail

gradle/build.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ snakeyaml = { group = "org.yaml", name = "snakeyaml", version = { strictly = "2.
4444
spock-core = { group = "org.spockframework", name="spock-core", version.ref="spock" }
4545
spock-junit4 = { group = "org.spockframework", name="spock-junit4", version.ref="spock" }
4646
spock-platform = { group = "org.spockframework", name="spock-bom", version.ref="spock" }
47-
spotless-plugin = "com.diffplug.spotless:spotless-plugin-gradle:6.25.0"
47+
spotless-plugin = "com.diffplug.spotless:spotless-plugin-gradle:7.0.0.BETA4"
4848
wiremock = "com.github.tomakehurst:wiremock-jre8-standalone:2.23.2"
4949
xmlunit-core = "org.xmlunit:xmlunit-core:2.8.2"

gradle/verification-metadata.xml

Lines changed: 130 additions & 0 deletions
Large diffs are not rendered by default.

server/src/test/java/org/elasticsearch/repositories/RepositoriesModuleTests.java

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,26 @@ public void setUp() throws Exception {
6565
}
6666

6767
public void testCanRegisterTwoRepositoriesWithDifferentTypes() {
68-
when(plugin1.getRepositories(eq(environment), eq(contentRegistry), eq(clusterService),
69-
eq(MockBigArrays.NON_RECYCLING_INSTANCE), eq(recoverySettings),
70-
any(RepositoriesMetrics.class)))
71-
.thenReturn(Collections.singletonMap("type1", factory));
72-
when(plugin2.getRepositories(eq(environment), eq(contentRegistry), eq(clusterService),
73-
eq(MockBigArrays.NON_RECYCLING_INSTANCE), eq(recoverySettings),
74-
any(RepositoriesMetrics.class)))
75-
.thenReturn(Collections.singletonMap("type2", factory));
68+
when(
69+
plugin1.getRepositories(
70+
eq(environment),
71+
eq(contentRegistry),
72+
eq(clusterService),
73+
eq(MockBigArrays.NON_RECYCLING_INSTANCE),
74+
eq(recoverySettings),
75+
any(RepositoriesMetrics.class)
76+
)
77+
).thenReturn(Collections.singletonMap("type1", factory));
78+
when(
79+
plugin2.getRepositories(
80+
eq(environment),
81+
eq(contentRegistry),
82+
eq(clusterService),
83+
eq(MockBigArrays.NON_RECYCLING_INSTANCE),
84+
eq(recoverySettings),
85+
any(RepositoriesMetrics.class)
86+
)
87+
).thenReturn(Collections.singletonMap("type2", factory));
7688

7789
// Would throw
7890
new RepositoriesModule(
@@ -83,18 +95,32 @@ public void testCanRegisterTwoRepositoriesWithDifferentTypes() {
8395
mock(ClusterService.class),
8496
MockBigArrays.NON_RECYCLING_INSTANCE,
8597
contentRegistry,
86-
recoverySettings, TelemetryProvider.NOOP);
98+
recoverySettings,
99+
TelemetryProvider.NOOP
100+
);
87101
}
88102

89103
public void testCannotRegisterTwoRepositoriesWithSameTypes() {
90-
when(plugin1.getRepositories(eq(environment), eq(contentRegistry), eq(clusterService),
91-
eq(MockBigArrays.NON_RECYCLING_INSTANCE), eq(recoverySettings),
92-
any(RepositoriesMetrics.class)))
93-
.thenReturn(Collections.singletonMap("type1", factory));
94-
when(plugin2.getRepositories(eq(environment), eq(contentRegistry), eq(clusterService),
95-
eq(MockBigArrays.NON_RECYCLING_INSTANCE), eq(recoverySettings),
96-
any(RepositoriesMetrics.class)))
97-
.thenReturn(Collections.singletonMap("type1", factory));
104+
when(
105+
plugin1.getRepositories(
106+
eq(environment),
107+
eq(contentRegistry),
108+
eq(clusterService),
109+
eq(MockBigArrays.NON_RECYCLING_INSTANCE),
110+
eq(recoverySettings),
111+
any(RepositoriesMetrics.class)
112+
)
113+
).thenReturn(Collections.singletonMap("type1", factory));
114+
when(
115+
plugin2.getRepositories(
116+
eq(environment),
117+
eq(contentRegistry),
118+
eq(clusterService),
119+
eq(MockBigArrays.NON_RECYCLING_INSTANCE),
120+
eq(recoverySettings),
121+
any(RepositoriesMetrics.class)
122+
)
123+
).thenReturn(Collections.singletonMap("type1", factory));
98124

99125
IllegalArgumentException ex = expectThrows(
100126
IllegalArgumentException.class,
@@ -106,7 +132,9 @@ public void testCannotRegisterTwoRepositoriesWithSameTypes() {
106132
clusterService,
107133
MockBigArrays.NON_RECYCLING_INSTANCE,
108134
contentRegistry,
109-
recoverySettings, TelemetryProvider.NOOP)
135+
recoverySettings,
136+
TelemetryProvider.NOOP
137+
)
110138
);
111139

112140
assertEquals("Repository type [type1] is already registered", ex.getMessage());
@@ -130,17 +158,25 @@ public void testCannotRegisterTwoInternalRepositoriesWithSameTypes() {
130158
clusterService,
131159
MockBigArrays.NON_RECYCLING_INSTANCE,
132160
contentRegistry,
133-
recoverySettings, TelemetryProvider.NOOP)
161+
recoverySettings,
162+
TelemetryProvider.NOOP
163+
)
134164
);
135165

136166
assertEquals("Internal repository type [type1] is already registered", ex.getMessage());
137167
}
138168

139169
public void testCannotRegisterNormalAndInternalRepositoriesWithSameTypes() {
140-
when(plugin1.getRepositories(eq(environment), eq(contentRegistry), eq(clusterService),
141-
eq(MockBigArrays.NON_RECYCLING_INSTANCE), eq(recoverySettings),
142-
any(RepositoriesMetrics.class)))
143-
.thenReturn(Collections.singletonMap("type1", factory));
170+
when(
171+
plugin1.getRepositories(
172+
eq(environment),
173+
eq(contentRegistry),
174+
eq(clusterService),
175+
eq(MockBigArrays.NON_RECYCLING_INSTANCE),
176+
eq(recoverySettings),
177+
any(RepositoriesMetrics.class)
178+
)
179+
).thenReturn(Collections.singletonMap("type1", factory));
144180
when(plugin2.getInternalRepositories(environment, contentRegistry, clusterService, recoverySettings)).thenReturn(
145181
Collections.singletonMap("type1", factory)
146182
);
@@ -155,7 +191,9 @@ public void testCannotRegisterNormalAndInternalRepositoriesWithSameTypes() {
155191
clusterService,
156192
MockBigArrays.NON_RECYCLING_INSTANCE,
157193
contentRegistry,
158-
recoverySettings, TelemetryProvider.NOOP)
194+
recoverySettings,
195+
TelemetryProvider.NOOP
196+
)
159197
);
160198

161199
assertEquals("Internal repository type [type1] is already registered as a non-internal repository", ex.getMessage());

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/validation/SimpleServiceIntegrationValidatorTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ public void testValidate_ServiceThrowsException() {
7171
any()
7272
);
7373

74-
assertThrows(ElasticsearchStatusException.class, () -> {
75-
underTest.validate(mockInferenceService, mockModel, mockActionListener);});
74+
assertThrows(
75+
ElasticsearchStatusException.class,
76+
() -> { underTest.validate(mockInferenceService, mockModel, mockActionListener); }
77+
);
7678

7779
verifyCallToService(false);
7880
}

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/process/AnalyticsProcessManagerTests.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,20 @@ public void testRunJob_TaskIsStopping() {
138138
when(task.isStopping()).thenReturn(true);
139139
when(task.getParams()).thenReturn(new StartDataFrameAnalyticsAction.TaskParams("data_frame_id", MlConfigVersion.CURRENT, false));
140140

141-
processManager.runJob(task, dataFrameAnalyticsConfig, dataExtractorFactory,
141+
processManager.runJob(
142+
task,
143+
dataFrameAnalyticsConfig,
144+
dataExtractorFactory,
142145
ActionTestUtils.assertNoFailureListener(stepResponse -> {
143-
assertThat(processManager.getProcessContextCount(), equalTo(0));
144-
assertThat(stepResponse.isTaskComplete(), is(true));
146+
assertThat(processManager.getProcessContextCount(), equalTo(0));
147+
assertThat(stepResponse.isTaskComplete(), is(true));
145148

146-
InOrder inOrder = inOrder(task);
147-
inOrder.verify(task).isStopping();
148-
inOrder.verify(task).getParams();
149-
verifyNoMoreInteractions(task);
150-
}));
149+
InOrder inOrder = inOrder(task);
150+
inOrder.verify(task).isStopping();
151+
inOrder.verify(task).getParams();
152+
verifyNoMoreInteractions(task);
153+
})
154+
);
151155
}
152156

153157
public void testRunJob_ProcessContextAlreadyExists() {

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/token/TransportInvalidateTokenActionTests.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ public void testInvalidateTokensWhenIndexUnavailable() throws Exception {
8282
when(securityIndex.isAvailable(SecurityIndexManager.Availability.SEARCH_SHARDS)).thenReturn(false);
8383
when(securityIndex.indexExists()).thenReturn(true);
8484
when(securityIndex.defensiveCopy()).thenReturn(securityIndex);
85-
when(securityIndex.getUnavailableReason(SecurityIndexManager.Availability.PRIMARY_SHARDS))
86-
.thenReturn(new ElasticsearchException("simulated"));
85+
when(securityIndex.getUnavailableReason(SecurityIndexManager.Availability.PRIMARY_SHARDS)).thenReturn(
86+
new ElasticsearchException("simulated")
87+
);
8788
final TokenService tokenService = new TokenService(
8889
SETTINGS,
8990
Clock.systemUTC(),
@@ -102,8 +103,11 @@ public void testInvalidateTokensWhenIndexUnavailable() throws Exception {
102103

103104
Tuple<byte[], byte[]> newTokenBytes = tokenService.getRandomTokenBytes(true);
104105
InvalidateTokenRequest request = new InvalidateTokenRequest(
105-
tokenService.prependVersionAndEncodeAccessToken(TransportVersion.current(), newTokenBytes.v1()),
106-
ACCESS_TOKEN.getValue(), null, null);
106+
tokenService.prependVersionAndEncodeAccessToken(TransportVersion.current(), newTokenBytes.v1()),
107+
ACCESS_TOKEN.getValue(),
108+
null,
109+
null
110+
);
107111
PlainActionFuture<InvalidateTokenResponse> accessTokenfuture = new PlainActionFuture<>();
108112
action.doExecute(null, request, accessTokenfuture);
109113
ElasticsearchSecurityException ese = expectThrows(ElasticsearchSecurityException.class, accessTokenfuture::actionGet);
@@ -148,8 +152,11 @@ public void testInvalidateTokensWhenIndexClosed() throws Exception {
148152

149153
Tuple<byte[], byte[]> newTokenBytes = tokenService.getRandomTokenBytes(true);
150154
InvalidateTokenRequest request = new InvalidateTokenRequest(
151-
tokenService.prependVersionAndEncodeAccessToken(TransportVersion.current(), newTokenBytes.v1()),
152-
ACCESS_TOKEN.getValue(), null, null);
155+
tokenService.prependVersionAndEncodeAccessToken(TransportVersion.current(), newTokenBytes.v1()),
156+
ACCESS_TOKEN.getValue(),
157+
null,
158+
null
159+
);
153160
PlainActionFuture<InvalidateTokenResponse> accessTokenfuture = new PlainActionFuture<>();
154161
action.doExecute(null, request, accessTokenfuture);
155162
ElasticsearchSecurityException ese = expectThrows(ElasticsearchSecurityException.class, accessTokenfuture::actionGet);

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/AuthenticationServiceTests.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,8 +2041,14 @@ public void testExpiredToken() throws Exception {
20412041
.user(new User("creator"))
20422042
.realmRef(new RealmRef("test", "test", "test"))
20432043
.build(false);
2044-
tokenService.createOAuth2Tokens(newTokenBytes.v1(), newTokenBytes.v2(), expected, originatingAuth, Collections.emptyMap(),
2045-
tokenFuture);
2044+
tokenService.createOAuth2Tokens(
2045+
newTokenBytes.v1(),
2046+
newTokenBytes.v2(),
2047+
expected,
2048+
originatingAuth,
2049+
Collections.emptyMap(),
2050+
tokenFuture
2051+
);
20462052
}
20472053
String token = tokenFuture.get().getAccessToken();
20482054
mockGetTokenFromAccessTokenBytes(tokenService, newTokenBytes.v1(), expected, Map.of(), true, null, client);

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/CrossClusterAccessAuthenticationServiceTests.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ public void init() throws Exception {
7676
}
7777

7878
public void testAuthenticateThrowsOnUnsupportedMinVersions() throws IOException {
79-
when(clusterService.state().getMinTransportVersion()).thenReturn(TransportVersionUtils.randomVersionBetween(
79+
when(clusterService.state().getMinTransportVersion()).thenReturn(
80+
TransportVersionUtils.randomVersionBetween(
8081
random(),
8182
TransportVersions.MINIMUM_COMPATIBLE,
8283
TransportVersionUtils.getPreviousVersion(TRANSPORT_VERSION_ADVANCED_REMOTE_CLUSTER_SECURITY)
83-
));
84+
)
85+
);
8486
final var authcContext = mock(Authenticator.Context.class, Mockito.RETURNS_DEEP_STUBS);
8587
when(authcContext.getThreadContext()).thenReturn(threadContext);
8688
final var crossClusterAccessHeaders = new CrossClusterAccessHeaders(
@@ -93,12 +95,14 @@ public void testAuthenticateThrowsOnUnsupportedMinVersions() throws IOException
9395
when(auditableRequest.exceptionProcessingRequest(any(), any())).thenAnswer(
9496
i -> new ElasticsearchSecurityException("potato", (Exception) i.getArguments()[0])
9597
);
96-
doAnswer(invocationOnMock -> new Authenticator.Context(
98+
doAnswer(
99+
invocationOnMock -> new Authenticator.Context(
97100
threadContext,
98101
auditableRequest,
99102
mock(Realms.class),
100103
(AuthenticationToken) invocationOnMock.getArguments()[2]
101-
)).when(authenticationService).newContext(anyString(), any(), any());
104+
)
105+
).when(authenticationService).newContext(anyString(), any(), any());
102106

103107
final PlainActionFuture<Authentication> future = new PlainActionFuture<>();
104108
crossClusterAccessAuthenticationService.authenticate("action", mock(TransportRequest.class), future);

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/RealmsAuthenticatorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ public void testRecordingFailedAuthenticationMetric() {
326326
@SuppressWarnings("unchecked")
327327
final ActionListener<AuthenticationResult<User>> listener = (ActionListener<AuthenticationResult<User>>) invocationOnMock
328328
.getArguments()[1];
329-
listener.onResponse(AuthenticationResult.unsuccessful("unsuccessful realms authentication", null));
329+
listener.onResponse(AuthenticationResult.unsuccessful("unsuccessful realms authentication", null));
330330
return null;
331331
}).when(unsuccessfulRealm).authenticate(eq(authenticationToken), any());
332332

@@ -337,7 +337,7 @@ public void testRecordingFailedAuthenticationMetric() {
337337

338338
final PlainActionFuture<AuthenticationResult<Authentication>> future = new PlainActionFuture<>();
339339
realmsAuthenticator.authenticate(context, future);
340-
var e = expectThrows(ElasticsearchSecurityException.class, () -> future.actionGet());
340+
var e = expectThrows(ElasticsearchSecurityException.class, () -> future.actionGet());
341341
assertThat(e, sameInstance(exception));
342342

343343
assertSingleFailedAuthMetric(

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/NativePrivilegeStoreTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,7 @@ public void testGetPrivilegesWillOnlyWaitOnUnavailableShardException() {
363363
public void testGetPrivilegesFailsAfterWaitOnUnavailableShardException() {
364364
when(securityIndex.isAvailable(SecurityIndexManager.Availability.SEARCH_SHARDS)).thenReturn(false).thenReturn(false);
365365

366-
when(securityIndex.getUnavailableReason(SecurityIndexManager.Availability.SEARCH_SHARDS)).thenReturn(
367-
unavailableShardsException()
368-
);
366+
when(securityIndex.getUnavailableReason(SecurityIndexManager.Availability.SEARCH_SHARDS)).thenReturn(unavailableShardsException());
369367
doAnswer(invocation -> {
370368
@SuppressWarnings("unchecked")
371369
final var listener = (ActionListener<Void>) invocation.getArguments()[0];

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestUpdateCrossClusterApiKeyActionTests.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,10 @@ public void testLicenseEnforcement() throws Exception {
8989
// Disallow by license
9090
when(licenseState.isAllowed(Security.ADVANCED_REMOTE_CLUSTER_SECURITY_FEATURE)).thenReturn(false);
9191

92-
final FakeRestRequest restRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY).withContent(
93-
new BytesArray("""
94-
{
95-
"metadata": {}
96-
}"""),
97-
XContentType.JSON
98-
).withParams(Map.of("id", randomAlphaOfLength(10))).build();
92+
final FakeRestRequest restRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY).withContent(new BytesArray("""
93+
{
94+
"metadata": {}
95+
}"""), XContentType.JSON).withParams(Map.of("id", randomAlphaOfLength(10))).build();
9996
final SetOnce<RestResponse> responseSetOnce = new SetOnce<>();
10097
final RestChannel restChannel = new AbstractRestChannel(restRequest, randomBoolean()) {
10198
@Override

0 commit comments

Comments
 (0)