Skip to content

Commit 4b00808

Browse files
Merge pull request #1205 from anthonydahanne/spotless
Add Spotless plugin for style
2 parents abaed48 + 8b8a56a commit 4b00808

File tree

1,153 files changed

+61674
-45428
lines changed

Some content is hidden

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

1,153 files changed

+61674
-45428
lines changed

.github/workflows/maven.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
name: Java CI
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
410

511
jobs:
612
build:
713
runs-on: ubuntu-latest
814
strategy:
915
matrix:
10-
java: [ 8, 11, 17, 21 ]
16+
java: [ 8, 11 ]
1117
name: Java ${{ matrix.java }} build
1218
steps:
1319
- uses: actions/checkout@v4
@@ -26,5 +32,8 @@ jobs:
2632
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
2733
restore-keys: ${{ runner.os }}-m2
2834
- name: Build with Maven
29-
run: ./mvnw clean install -Dgpg.skip
35+
run: ./mvnw clean package -Dgpg.skip
36+
- if: ${{ matrix.java != 8 }}
37+
name: Check style with Spotless
38+
run: ./mvnw spotless:check
3039

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/AbstractPayloadCachingRootProvider.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,40 @@
1717
package org.cloudfoundry.reactor;
1818

1919
import com.fasterxml.jackson.databind.ObjectMapper;
20-
import org.springframework.web.util.UriComponents;
21-
import org.springframework.web.util.UriComponentsBuilder;
22-
import reactor.core.publisher.Mono;
23-
2420
import java.util.Map;
2521
import java.util.concurrent.ConcurrentHashMap;
2622
import java.util.concurrent.ConcurrentMap;
23+
import org.springframework.web.util.UriComponents;
24+
import org.springframework.web.util.UriComponentsBuilder;
25+
import reactor.core.publisher.Mono;
2726

2827
abstract class AbstractPayloadCachingRootProvider extends AbstractRootProvider {
2928

30-
private final ConcurrentMap<ConnectionContext, Mono<Map<String, String>>> payloads = new ConcurrentHashMap<>(1);
29+
private final ConcurrentMap<ConnectionContext, Mono<Map<String, String>>> payloads =
30+
new ConcurrentHashMap<>(1);
3131

3232
protected abstract Mono<Map<String, String>> doGetPayload(ConnectionContext connectionContext);
3333

3434
@Override
3535
protected final Mono<UriComponents> doGetRoot(String key, ConnectionContext connectionContext) {
36-
return this.payloads.computeIfAbsent(connectionContext, this::getPayload)
37-
.map(payload -> {
38-
if (!payload.containsKey(key)) {
39-
throw new IllegalArgumentException(String.format("Payload does not contain key '%s;", key));
40-
}
41-
42-
return normalize(UriComponentsBuilder.fromUriString(payload.get(key)));
43-
});
36+
return this.payloads
37+
.computeIfAbsent(connectionContext, this::getPayload)
38+
.map(
39+
payload -> {
40+
if (!payload.containsKey(key)) {
41+
throw new IllegalArgumentException(
42+
String.format("Payload does not contain key '%s;", key));
43+
}
44+
45+
return normalize(UriComponentsBuilder.fromUriString(payload.get(key)));
46+
});
4447
}
4548

4649
abstract ObjectMapper getObjectMapper();
4750

4851
private Mono<Map<String, String>> getPayload(ConnectionContext connectionContext) {
4952
Mono<Map<String, String>> cached = doGetPayload(connectionContext);
5053

51-
return connectionContext.getCacheDuration()
52-
.map(cached::cache)
53-
.orElseGet(cached::cache);
54+
return connectionContext.getCacheDuration().map(cached::cache).orElseGet(cached::cache);
5455
}
55-
5656
}

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/AbstractRootProvider.java

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
package org.cloudfoundry.reactor;
1818

1919
import io.netty.handler.codec.http.HttpHeaders;
20+
import java.util.Optional;
21+
import java.util.regex.Matcher;
22+
import java.util.regex.Pattern;
2023
import org.cloudfoundry.reactor.util.JsonCodec;
2124
import org.cloudfoundry.reactor.util.Operator;
2225
import org.cloudfoundry.reactor.util.OperatorContext;
@@ -27,10 +30,6 @@
2730
import reactor.core.publisher.Mono;
2831
import reactor.netty.http.client.HttpClient;
2932

30-
import java.util.Optional;
31-
import java.util.regex.Matcher;
32-
import java.util.regex.Pattern;
33-
3433
/**
3534
* An abstract implementation of {@link RootProvider} that ensures that returned values are trusted (if configured) and cached.
3635
*/
@@ -47,16 +46,20 @@ public final void checkForValidApiHost() {
4746
Matcher matcher = HOSTNAME_PATTERN.matcher(getApiHost());
4847

4948
if (!matcher.matches()) {
50-
throw new IllegalArgumentException(String.format("API hostname %s is not correctly formatted (e.g. 'api.local.pcfdev.io')", getApiHost()));
49+
throw new IllegalArgumentException(
50+
String.format(
51+
"API hostname %s is not correctly formatted (e.g."
52+
+ " 'api.local.pcfdev.io')",
53+
getApiHost()));
5154
}
5255
}
5356

5457
public Mono<Operator> createOperator(ConnectionContext connectionContext) {
5558
HttpClient httpClient = connectionContext.getHttpClient();
5659
return getRoot(connectionContext)
57-
.map(root -> OperatorContext.of(connectionContext, root))
58-
.map(operatorContext -> new Operator(operatorContext, httpClient))
59-
.map(operator -> operator.headers(this::addHeaders));
60+
.map(root -> OperatorContext.of(connectionContext, root))
61+
.map(operatorContext -> new Operator(operatorContext, httpClient))
62+
.map(operator -> operator.headers(this::addHeaders));
6063
}
6164

6265
/**
@@ -66,32 +69,32 @@ public Mono<Operator> createOperator(ConnectionContext connectionContext) {
6669

6770
@Override
6871
public final Mono<String> getRoot(String key, ConnectionContext connectionContext) {
69-
Mono<String> cached = doGetRoot(key, connectionContext)
70-
.delayUntil(uri -> trust(uri.getHost(), uri.getPort(), connectionContext))
71-
.map(UriComponents::toUriString);
72+
Mono<String> cached =
73+
doGetRoot(key, connectionContext)
74+
.delayUntil(uri -> trust(uri.getHost(), uri.getPort(), connectionContext))
75+
.map(UriComponents::toUriString);
7276

73-
return connectionContext.getCacheDuration()
74-
.map(cached::cache)
75-
.orElseGet(cached::cache);
77+
return connectionContext.getCacheDuration().map(cached::cache).orElseGet(cached::cache);
7678
}
7779

7880
@Override
7981
public final Mono<String> getRoot(ConnectionContext connectionContext) {
80-
Mono<String> cached = doGetRoot(connectionContext)
81-
.delayUntil(uri -> trust(uri.getHost(), uri.getPort(), connectionContext))
82-
.map(UriComponents::toUriString);
82+
Mono<String> cached =
83+
doGetRoot(connectionContext)
84+
.delayUntil(uri -> trust(uri.getHost(), uri.getPort(), connectionContext))
85+
.map(UriComponents::toUriString);
8386

84-
return connectionContext.getCacheDuration()
85-
.map(cached::cache)
86-
.orElseGet(cached::cache);
87+
return connectionContext.getCacheDuration().map(cached::cache).orElseGet(cached::cache);
8788
}
8889

8990
protected abstract Mono<UriComponents> doGetRoot(ConnectionContext connectionContext);
9091

91-
protected abstract Mono<UriComponents> doGetRoot(String key, ConnectionContext connectionContext);
92+
protected abstract Mono<UriComponents> doGetRoot(
93+
String key, ConnectionContext connectionContext);
9294

9395
protected final UriComponents getRoot() {
94-
UriComponentsBuilder builder = UriComponentsBuilder.newInstance().scheme("https").host(getApiHost());
96+
UriComponentsBuilder builder =
97+
UriComponentsBuilder.newInstance().scheme("https").host(getApiHost());
9598
getPort().ifPresent(builder::port);
9699

97100
return normalize(builder);
@@ -135,5 +138,4 @@ private String getScheme() {
135138
private Mono<Void> trust(String host, int port, ConnectionContext connectionContext) {
136139
return connectionContext.trust(host, port);
137140
}
138-
139141
}

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/ConnectionContext.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
package org.cloudfoundry.reactor;
1818

1919
import com.fasterxml.jackson.databind.ObjectMapper;
20-
import reactor.core.publisher.Mono;
21-
import reactor.netty.http.client.HttpClient;
22-
2320
import java.time.Duration;
2421
import java.util.Optional;
22+
import reactor.core.publisher.Mono;
23+
import reactor.netty.http.client.HttpClient;
2524

2625
/**
2726
* Common, reusable, connection context
@@ -60,5 +59,4 @@ public interface ConnectionContext {
6059
* @param port the port of the endpoint to trust
6160
*/
6261
Mono<Void> trust(String host, int port);
63-
6462
}

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/RootProvider.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,4 @@ public interface RootProvider {
3939
* @return the normalized API root
4040
*/
4141
Mono<String> getRoot(String key, ConnectionContext connectionContext);
42-
4342
}

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/TokenProvider.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,5 @@ public interface TokenProvider {
3737
*
3838
* @param connectionContext A {@link ConnectionContext} to be used to identity which connection the tokens should be invalidated for
3939
*/
40-
default void invalidate(ConnectionContext connectionContext) {
41-
}
42-
40+
default void invalidate(ConnectionContext connectionContext) {}
4341
}

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/CloudFoundryClientCompatibilityChecker.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.cloudfoundry.reactor.client;
1818

19+
import static org.cloudfoundry.util.tuple.TupleUtils.consumer;
20+
1921
import com.github.zafarkhaja.semver.Version;
2022
import org.cloudfoundry.client.CloudFoundryClient;
2123
import org.cloudfoundry.client.v2.info.GetInfoRequest;
@@ -24,8 +26,6 @@
2426
import org.slf4j.LoggerFactory;
2527
import reactor.core.publisher.Mono;
2628

27-
import static org.cloudfoundry.util.tuple.TupleUtils.consumer;
28-
2929
final class CloudFoundryClientCompatibilityChecker {
3030

3131
private final Logger logger = LoggerFactory.getLogger("cloudfoundry-client.compatibility");
@@ -38,21 +38,28 @@ final class CloudFoundryClientCompatibilityChecker {
3838

3939
void check() {
4040
this.info
41-
.get(GetInfoRequest.builder()
42-
.build())
43-
.map(response -> Version.valueOf(response.getApiVersion()))
44-
.zipWith(Mono.just(Version.valueOf(CloudFoundryClient.SUPPORTED_API_VERSION)))
45-
.subscribe(consumer((server, supported) -> logCompatibility(server, supported, this.logger)), t -> this.logger.error("An error occurred while checking version compatibility:", t));
41+
.get(GetInfoRequest.builder().build())
42+
.map(response -> Version.valueOf(response.getApiVersion()))
43+
.zipWith(Mono.just(Version.valueOf(CloudFoundryClient.SUPPORTED_API_VERSION)))
44+
.subscribe(
45+
consumer(
46+
(server, supported) ->
47+
logCompatibility(server, supported, this.logger)),
48+
t ->
49+
this.logger.error(
50+
"An error occurred while checking version compatibility:",
51+
t));
4652
}
4753

4854
private static void logCompatibility(Version server, Version supported, Logger logger) {
49-
String message = "Client supports API version {} and is connected to server with API version {}. Things may not work as expected.";
55+
String message =
56+
"Client supports API version {} and is connected to server with API version {}."
57+
+ " Things may not work as expected.";
5058

5159
if (server.greaterThan(supported)) {
5260
logger.info(message, supported, server);
5361
} else if (server.lessThan(supported)) {
5462
logger.warn(message, supported, server);
5563
}
5664
}
57-
5865
}

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/MethodNameComparator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ public final class MethodNameComparator implements Comparator<Method> {
2323

2424
public static final MethodNameComparator INSTANCE = new MethodNameComparator();
2525

26-
private MethodNameComparator() {
27-
}
26+
private MethodNameComparator() {}
2827

2928
@Override
3029
public int compare(Method a, Method b) {
3130
return a.getName().compareTo(b.getName());
3231
}
33-
3432
}

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/QueryBuilder.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,36 @@
1616

1717
package org.cloudfoundry.reactor.client;
1818

19+
import java.util.Collection;
20+
import java.util.Objects;
21+
import java.util.stream.Collectors;
22+
import java.util.stream.Stream;
1923
import org.cloudfoundry.QueryParameter;
2024
import org.cloudfoundry.reactor.util.AnnotationUtils;
2125
import org.cloudfoundry.reactor.util.AnnotationUtils.AnnotatedValue;
2226
import org.cloudfoundry.reactor.util.UriQueryParameter;
2327
import org.cloudfoundry.reactor.util.UriQueryParameterBuilder;
2428

25-
import java.util.Collection;
26-
import java.util.Objects;
27-
import java.util.stream.Collectors;
28-
import java.util.stream.Stream;
29-
3029
/**
3130
* A builder for Cloud Foundry queries
3231
*/
3332
public final class QueryBuilder implements UriQueryParameterBuilder {
3433

3534
public Stream<UriQueryParameter> build(Object instance) {
3635
return AnnotationUtils.streamAnnotatedValues(instance, QueryParameter.class)
37-
.map(QueryBuilder::processValue)
38-
.filter(Objects::nonNull);
36+
.map(QueryBuilder::processValue)
37+
.filter(Objects::nonNull);
3938
}
4039

41-
private static UriQueryParameter processCollection(QueryParameter queryParameter, Object value) {
42-
return processValue(queryParameter.value(), ((Collection<?>) value).stream()
43-
.map(Object::toString)
44-
.map(String::trim)
45-
.collect(Collectors.joining(queryParameter.delimiter())));
40+
private static UriQueryParameter processCollection(
41+
QueryParameter queryParameter, Object value) {
42+
return processValue(
43+
queryParameter.value(),
44+
((Collection<?>) value)
45+
.stream()
46+
.map(Object::toString)
47+
.map(String::trim)
48+
.collect(Collectors.joining(queryParameter.delimiter())));
4649
}
4750

4851
private static UriQueryParameter processValue(AnnotatedValue<QueryParameter> annotatedValue) {
@@ -58,5 +61,4 @@ private static UriQueryParameter processValue(AnnotatedValue<QueryParameter> ann
5861
private static UriQueryParameter processValue(String name, String value) {
5962
return UriQueryParameter.of(name, value);
6063
}
61-
6264
}

0 commit comments

Comments
 (0)