Skip to content

Commit 3ec9eb6

Browse files
committed
chore(codestyle): add plugin to verify google code format
1 parent 876355e commit 3ec9eb6

File tree

136 files changed

+882
-954
lines changed

Some content is hidden

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

136 files changed

+882
-954
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ description. You can download the
3333
[IntelliJ Java Google Style](https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml)
3434
to import in these settings in IntelliJ.
3535

36+
These conventions are checked during the build phase. If the build fails because
37+
the code is not using the correct style you can fix this easily by running a gradle task
38+
```bash
39+
./gradlew googleJavaFormat
40+
```
41+
3642
### SonarLint
3743

3844
It would also be very helpful to install the SonarLint plugin in your IDE and fix any

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ plugins {
3131
id "org.sonarqube" version "3.2.0"
3232
id "jacoco"
3333
id 'io.codearte.nexus-staging' version '0.30.0'
34+
id 'com.github.sherter.google-java-format' version '0.9' apply false
3435
}
3536

3637
sonarqube {
@@ -48,6 +49,7 @@ subprojects {
4849
apply plugin: 'java'
4950
apply plugin: 'maven-publish'
5051
apply plugin: 'signing'
52+
apply plugin: 'com.github.sherter.google-java-format'
5153

5254
repositories {
5355
mavenLocal()
@@ -78,6 +80,8 @@ subprojects {
7880

7981
compileJava.dependsOn(processResources)
8082

83+
compileJava.mustRunAfter verifyGoogleJavaFormat
84+
8185
jacocoTestReport {
8286
reports {
8387
xml.enabled = true

graphql-java-kickstart/src/main/java/graphql/kickstart/execution/BatchedDataLoaderGraphQLBuilder.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,25 @@ public BatchedDataLoaderGraphQLBuilder(
2424
}
2525

2626
GraphQL newGraphQL(GraphQLBatchedInvocationInput invocationInput, GraphQLBuilder graphQLBuilder) {
27-
Supplier<Instrumentation> supplier = augment(invocationInput,
28-
graphQLBuilder.getInstrumentationSupplier());
29-
return invocationInput.getInvocationInputs().stream().findFirst()
27+
Supplier<Instrumentation> supplier =
28+
augment(invocationInput, graphQLBuilder.getInstrumentationSupplier());
29+
return invocationInput.getInvocationInputs().stream()
30+
.findFirst()
3031
.map(GraphQLSingleInvocationInput::getSchema)
3132
.map(schema -> graphQLBuilder.build(schema, supplier))
32-
.orElseThrow(() -> new IllegalArgumentException(
33-
"Batched invocation input must contain at least one query"));
33+
.orElseThrow(
34+
() ->
35+
new IllegalArgumentException(
36+
"Batched invocation input must contain at least one query"));
3437
}
3538

3639
private Supplier<Instrumentation> augment(
3740
GraphQLBatchedInvocationInput batchedInvocationInput,
38-
Supplier<Instrumentation> instrumentationSupplier
39-
) {
41+
Supplier<Instrumentation> instrumentationSupplier) {
4042
List<ExecutionInput> executionInputs = batchedInvocationInput.getExecutionInputs();
41-
return batchedInvocationInput.getContextSetting()
42-
.configureInstrumentationForContext(instrumentationSupplier, executionInputs,
43-
optionsSupplier.get());
43+
return batchedInvocationInput
44+
.getContextSetting()
45+
.configureInstrumentationForContext(
46+
instrumentationSupplier, executionInputs, optionsSupplier.get());
4447
}
45-
4648
}

graphql-java-kickstart/src/main/java/graphql/kickstart/execution/DecoratedExecutionResult.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,4 @@ public Map<Object, Object> getExtensions() {
4040
public Map<String, Object> toSpecification() {
4141
return result.toSpecification();
4242
}
43-
4443
}

graphql-java-kickstart/src/main/java/graphql/kickstart/execution/DefaultGraphQLRootObjectBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ public class DefaultGraphQLRootObjectBuilder extends StaticGraphQLRootObjectBuil
55
public DefaultGraphQLRootObjectBuilder() {
66
super(new Object());
77
}
8-
98
}

graphql-java-kickstart/src/main/java/graphql/kickstart/execution/GraphQLBatchedQueryResult.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
@RequiredArgsConstructor
99
class GraphQLBatchedQueryResult implements GraphQLQueryResult {
1010

11-
@Getter
12-
private final List<ExecutionResult> results;
11+
@Getter private final List<ExecutionResult> results;
1312

1413
@Override
1514
public boolean isBatched() {
@@ -20,5 +19,4 @@ public boolean isBatched() {
2019
public boolean isAsynchronous() {
2120
return false;
2221
}
23-
2422
}

graphql-java-kickstart/src/main/java/graphql/kickstart/execution/GraphQLInvoker.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ public CompletableFuture<GraphQLQueryResult> queryAsync(GraphQLInvocationInput i
3535
return executeAsync((GraphQLSingleInvocationInput) invocationInput)
3636
.thenApply(GraphQLQueryResult::create);
3737
}
38-
GraphQLBatchedInvocationInput batchedInvocationInput = (GraphQLBatchedInvocationInput) invocationInput;
38+
GraphQLBatchedInvocationInput batchedInvocationInput =
39+
(GraphQLBatchedInvocationInput) invocationInput;
3940
return executeAsync(batchedInvocationInput).thenApply(GraphQLQueryResult::create);
4041
}
4142

4243
private CompletableFuture<List<ExecutionResult>> executeAsync(
4344
GraphQLBatchedInvocationInput batchedInvocationInput) {
44-
GraphQL graphQL = batchedDataLoaderGraphQLBuilder
45-
.newGraphQL(batchedInvocationInput, graphQLBuilder);
45+
GraphQL graphQL =
46+
batchedDataLoaderGraphQLBuilder.newGraphQL(batchedInvocationInput, graphQLBuilder);
4647
return sequence(
4748
batchedInvocationInput.getExecutionInputs().stream()
4849
.map(executionInput -> proxy.executeAsync(graphQL, executionInput))
@@ -52,14 +53,15 @@ private CompletableFuture<List<ExecutionResult>> executeAsync(
5253
@SuppressWarnings({"unchecked", "rawtypes"})
5354
private <T> CompletableFuture<List<T>> sequence(List<CompletableFuture<T>> futures) {
5455
CompletableFuture[] futuresArray = futures.toArray(new CompletableFuture[0]);
55-
return CompletableFuture.allOf(futuresArray).thenApply(aVoid -> {
56-
List<T> result = new ArrayList<>(futures.size());
57-
for (CompletableFuture future : futuresArray) {
58-
assert future.isDone(); // per the API contract of allOf()
59-
result.add((T) future.join());
60-
}
61-
return result;
62-
});
56+
return CompletableFuture.allOf(futuresArray)
57+
.thenApply(
58+
aVoid -> {
59+
List<T> result = new ArrayList<>(futures.size());
60+
for (CompletableFuture future : futuresArray) {
61+
assert future.isDone(); // per the API contract of allOf()
62+
result.add((T) future.join());
63+
}
64+
return result;
65+
});
6366
}
6467
}
65-

graphql-java-kickstart/src/main/java/graphql/kickstart/execution/GraphQLInvokerProxy.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@
88
public interface GraphQLInvokerProxy {
99

1010
CompletableFuture<ExecutionResult> executeAsync(GraphQL graphQL, ExecutionInput executionInput);
11-
1211
}

graphql-java-kickstart/src/main/java/graphql/kickstart/execution/GraphQLInvokerSubjectProxy.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@
1212
public class GraphQLInvokerSubjectProxy implements GraphQLInvokerProxy {
1313

1414
@Override
15-
public CompletableFuture<ExecutionResult> executeAsync(GraphQL graphQL,
16-
ExecutionInput executionInput) {
15+
public CompletableFuture<ExecutionResult> executeAsync(
16+
GraphQL graphQL, ExecutionInput executionInput) {
1717
GraphQLContext context = (GraphQLContext) executionInput.getContext();
18-
if (Subject.getSubject(AccessController.getContext()) == null && context.getSubject()
19-
.isPresent()) {
20-
return context.getSubject()
18+
if (Subject.getSubject(AccessController.getContext()) == null
19+
&& context.getSubject().isPresent()) {
20+
return context
21+
.getSubject()
2122
.map(it -> Subject.doAs(it, doAction(graphQL, executionInput)))
2223
.orElseGet(() -> graphQL.executeAsync(executionInput));
2324
}
2425
return graphQL.executeAsync(executionInput);
2526
}
2627

27-
private PrivilegedAction<CompletableFuture<ExecutionResult>> doAction(GraphQL graphQL,
28-
ExecutionInput executionInput) {
28+
private PrivilegedAction<CompletableFuture<ExecutionResult>> doAction(
29+
GraphQL graphQL, ExecutionInput executionInput) {
2930
return () -> graphQL.executeAsync(executionInput);
3031
}
31-
3232
}

graphql-java-kickstart/src/main/java/graphql/kickstart/execution/GraphQLObjectMapper.java

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,18 @@
2424
import java.util.function.Supplier;
2525
import lombok.SneakyThrows;
2626

27-
/**
28-
* @author Andrew Potter
29-
*/
27+
/** @author Andrew Potter */
3028
public class GraphQLObjectMapper {
3129

32-
private static final TypeReference<Map<String, List<String>>>
33-
MULTIPART_MAP_TYPE_REFERENCE = new TypeReference<Map<String, List<String>>>() {
34-
};
30+
private static final TypeReference<Map<String, List<String>>> MULTIPART_MAP_TYPE_REFERENCE =
31+
new TypeReference<Map<String, List<String>>>() {};
3532
private final ObjectMapperProvider objectMapperProvider;
3633
private final Supplier<GraphQLErrorHandler> graphQLErrorHandlerSupplier;
3734

3835
private ObjectMapper mapper;
3936

40-
protected GraphQLObjectMapper(ObjectMapperProvider objectMapperProvider,
37+
protected GraphQLObjectMapper(
38+
ObjectMapperProvider objectMapperProvider,
4139
Supplier<GraphQLErrorHandler> graphQLErrorHandlerSupplier) {
4240
this.objectMapperProvider = objectMapperProvider;
4341
this.graphQLErrorHandlerSupplier = graphQLErrorHandlerSupplier;
@@ -62,9 +60,7 @@ public ObjectMapper getJacksonMapper() {
6260
return result;
6361
}
6462

65-
/**
66-
* @return an {@link ObjectReader} for deserializing {@link GraphQLRequest}
67-
*/
63+
/** @return an {@link ObjectReader} for deserializing {@link GraphQLRequest} */
6864
public ObjectReader getGraphQLRequestMapper() {
6965
return getJacksonMapper().reader().forType(GraphQLRequest.class);
7066
}
@@ -102,8 +98,7 @@ public List<GraphQLRequest> readBatchedGraphQLRequest(String query) throws IOExc
10298

10399
@SneakyThrows
104100
public String serializeResultAsJson(ExecutionResult executionResult) {
105-
return getJacksonMapper()
106-
.writeValueAsString(createResultFromExecutionResult(executionResult));
101+
return getJacksonMapper().writeValueAsString(createResultFromExecutionResult(executionResult));
107102
}
108103

109104
public void serializeResultAsJson(Writer writer, ExecutionResult executionResult)
@@ -120,8 +115,7 @@ public void serializeResultAsJson(Writer writer, ExecutionResult executionResult
120115
*/
121116
@SneakyThrows
122117
public byte[] serializeResultAsBytes(ExecutionResult executionResult) {
123-
return getJacksonMapper()
124-
.writeValueAsBytes(createResultFromExecutionResult(executionResult));
118+
return getJacksonMapper().writeValueAsBytes(createResultFromExecutionResult(executionResult));
125119
}
126120

127121
public boolean areErrorsPresent(ExecutionResult executionResult) {
@@ -151,13 +145,16 @@ public Map<String, Object> convertSanitizedExecutionResult(ExecutionResult execu
151145
return convertSanitizedExecutionResult(executionResult, true);
152146
}
153147

154-
public Map<String, Object> convertSanitizedExecutionResult(ExecutionResult executionResult,
155-
boolean includeData) {
148+
public Map<String, Object> convertSanitizedExecutionResult(
149+
ExecutionResult executionResult, boolean includeData) {
156150
final Map<String, Object> result = new LinkedHashMap<>();
157151

158152
if (areErrorsPresent(executionResult)) {
159-
result.put("errors", executionResult.getErrors().stream().map(GraphQLError::toSpecification)
160-
.collect(toList()));
153+
result.put(
154+
"errors",
155+
executionResult.getErrors().stream()
156+
.map(GraphQLError::toSpecification)
157+
.collect(toList()));
161158
}
162159

163160
if (executionResult.getExtensions() != null && !executionResult.getExtensions().isEmpty()) {
@@ -173,9 +170,8 @@ public Map<String, Object> convertSanitizedExecutionResult(ExecutionResult execu
173170

174171
@SneakyThrows
175172
public Map<String, Object> deserializeVariables(String variables) {
176-
return VariablesDeserializer
177-
.deserializeVariablesObject(getJacksonMapper().readValue(variables, Object.class),
178-
getJacksonMapper());
173+
return VariablesDeserializer.deserializeVariablesObject(
174+
getJacksonMapper().readValue(variables, Object.class), getJacksonMapper());
179175
}
180176

181177
@SneakyThrows

graphql-java-kickstart/src/main/java/graphql/kickstart/execution/GraphQLQueryInvoker.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@
1212
import java.util.List;
1313
import java.util.function.Supplier;
1414

15-
/**
16-
* @author Andrew Potter
17-
*/
15+
/** @author Andrew Potter */
1816
public class GraphQLQueryInvoker {
1917

2018
private final Supplier<ExecutionStrategyProvider> getExecutionStrategyProvider;
2119
private final Supplier<Instrumentation> getInstrumentation;
2220
private final Supplier<PreparsedDocumentProvider> getPreparsedDocumentProvider;
2321
private final Supplier<DataLoaderDispatcherInstrumentationOptions> optionsSupplier;
2422

25-
protected GraphQLQueryInvoker(Supplier<ExecutionStrategyProvider> getExecutionStrategyProvider,
23+
protected GraphQLQueryInvoker(
24+
Supplier<ExecutionStrategyProvider> getExecutionStrategyProvider,
2625
Supplier<Instrumentation> getInstrumentation,
2726
Supplier<PreparsedDocumentProvider> getPreparsedDocumentProvider,
2827
Supplier<DataLoaderDispatcherInstrumentationOptions> optionsSupplier) {
@@ -37,20 +36,24 @@ public static Builder newBuilder() {
3736
}
3837

3938
public GraphQLInvoker toGraphQLInvoker() {
40-
GraphQLBuilder graphQLBuilder = new GraphQLBuilder()
41-
.executionStrategyProvider(getExecutionStrategyProvider)
42-
.instrumentation(getInstrumentation)
43-
.preparsedDocumentProvider(getPreparsedDocumentProvider);
39+
GraphQLBuilder graphQLBuilder =
40+
new GraphQLBuilder()
41+
.executionStrategyProvider(getExecutionStrategyProvider)
42+
.instrumentation(getInstrumentation)
43+
.preparsedDocumentProvider(getPreparsedDocumentProvider);
4444
return new GraphQLInvoker(graphQLBuilder, new BatchedDataLoaderGraphQLBuilder(optionsSupplier));
4545
}
4646

4747
public static class Builder {
4848

49-
private Supplier<ExecutionStrategyProvider> getExecutionStrategyProvider = DefaultExecutionStrategyProvider::new;
49+
private Supplier<ExecutionStrategyProvider> getExecutionStrategyProvider =
50+
DefaultExecutionStrategyProvider::new;
5051
private Supplier<Instrumentation> getInstrumentation = () -> SimpleInstrumentation.INSTANCE;
51-
private Supplier<PreparsedDocumentProvider> getPreparsedDocumentProvider = () -> NoOpPreparsedDocumentProvider.INSTANCE;
52-
private Supplier<DataLoaderDispatcherInstrumentationOptions> dataLoaderDispatcherInstrumentationOptionsSupplier = DataLoaderDispatcherInstrumentationOptions::newOptions;
53-
52+
private Supplier<PreparsedDocumentProvider> getPreparsedDocumentProvider =
53+
() -> NoOpPreparsedDocumentProvider.INSTANCE;
54+
private Supplier<DataLoaderDispatcherInstrumentationOptions>
55+
dataLoaderDispatcherInstrumentationOptionsSupplier =
56+
DataLoaderDispatcherInstrumentationOptions::newOptions;
5457

5558
public Builder withExecutionStrategyProvider(ExecutionStrategyProvider provider) {
5659
return withExecutionStrategyProvider(() -> provider);
@@ -103,7 +106,9 @@ public Builder withDataLoaderDispatcherInstrumentationOptions(
103106
}
104107

105108
public GraphQLQueryInvoker build() {
106-
return new GraphQLQueryInvoker(getExecutionStrategyProvider, getInstrumentation,
109+
return new GraphQLQueryInvoker(
110+
getExecutionStrategyProvider,
111+
getInstrumentation,
107112
getPreparsedDocumentProvider,
108113
dataLoaderDispatcherInstrumentationOptionsSupplier);
109114
}

graphql-java-kickstart/src/main/java/graphql/kickstart/execution/GraphQLRequest.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@
88
import java.util.HashMap;
99
import java.util.Map;
1010

11-
/**
12-
* @author Andrew Potter
13-
*/
11+
/** @author Andrew Potter */
1412
@JsonIgnoreProperties(ignoreUnknown = true)
1513
public class GraphQLRequest {
1614

1715
private String query;
16+
1817
@JsonDeserialize(using = VariablesDeserializer.class)
1918
private Map<String, Object> variables = new HashMap<>();
19+
2020
private String operationName;
2121

22-
public GraphQLRequest() {
23-
}
22+
public GraphQLRequest() {}
2423

2524
public GraphQLRequest(String query, Map<String, Object> variables, String operationName) {
2625
this.query = query;
@@ -31,8 +30,8 @@ public GraphQLRequest(String query, Map<String, Object> variables, String operat
3130
}
3231

3332
public static GraphQLRequest createIntrospectionRequest() {
34-
return new GraphQLRequest(IntrospectionQuery.INTROSPECTION_QUERY, new HashMap<>(),
35-
"IntrospectionQuery");
33+
return new GraphQLRequest(
34+
IntrospectionQuery.INTROSPECTION_QUERY, new HashMap<>(), "IntrospectionQuery");
3635
}
3736

3837
public static GraphQLRequest createQueryOnlyRequest(String query) {
@@ -64,7 +63,4 @@ public String getOperationName() {
6463
public void setOperationName(String operationName) {
6564
this.operationName = operationName;
6665
}
67-
6866
}
69-
70-

graphql-java-kickstart/src/main/java/graphql/kickstart/execution/GraphQLRootObjectBuilder.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
public interface GraphQLRootObjectBuilder {
44

5-
/**
6-
* @return the graphql root object
7-
*/
5+
/** @return the graphql root object */
86
Object build();
9-
107
}

0 commit comments

Comments
 (0)