Skip to content

Commit

Permalink
Apply spring-javaformat and checkstyle
Browse files Browse the repository at this point in the history
This commit adds the spring-javaformat code formatter and checkstyle
rules to the project to make code formatting and style more consistent
with other Spring projects.
  • Loading branch information
scottfrederick committed May 19, 2020
1 parent 175e851 commit efbedf8
Show file tree
Hide file tree
Showing 209 changed files with 4,387 additions and 4,524 deletions.
22 changes: 14 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -26,6 +26,7 @@ buildscript {
classpath 'io.spring.gradle:spring-io-plugin:0.0.8.RELEASE'
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.12'
classpath 'io.spring.nohttp:nohttp-gradle:0.0.1.RELEASE'
classpath 'io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.22'
}
}

Expand All @@ -50,12 +51,6 @@ ext {
] as String[]
}

apply plugin: 'io.spring.nohttp'

checkstyle {
toolVersion = 8.16
}

allprojects {
apply plugin: 'java'
apply plugin: 'maven'
Expand All @@ -68,6 +63,15 @@ allprojects {
apply plugin: "io.spring.dependency-management"
apply plugin: 'org.asciidoctor.gradle.asciidoctor'

apply plugin: 'io.spring.nohttp'
apply plugin: 'io.spring.javaformat'
apply plugin: 'checkstyle'

checkstyle {
toolVersion = 8.29
configDir = new File("${rootProject.projectDir}/src/checkstyle")
}

group = 'org.springframework.credhub'

asciidoctor {
Expand Down Expand Up @@ -133,6 +137,8 @@ subprojects {
}

dependencies {
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:0.0.22")

testCompile("junit:junit:$junitVersion")
testCompile("org.mockito:mockito-core:$mockitoVersion")
}
Expand Down
16 changes: 16 additions & 0 deletions publish-maven.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2016-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

apply plugin: 'maven'

install {
Expand Down
16 changes: 16 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2016-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

rootProject.name = 'spring-credhub'

include ':spring-credhub-core'
Expand Down
4 changes: 2 additions & 2 deletions spring-credhub-core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 the original author or authors.
* Copyright 2016-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,68 +18,70 @@

import java.security.NoSuchAlgorithmException;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;

import io.netty.channel.ChannelOption;
import io.netty.handler.ssl.ClientAuth;
import io.netty.handler.ssl.IdentityCipherSuiteFilter;
import io.netty.handler.ssl.JdkSslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.SslProvider;

import org.springframework.credhub.support.ClientOptions;
import org.springframework.http.client.reactive.ClientHttpConnector;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import reactor.netty.http.client.HttpClient;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import org.springframework.credhub.support.ClientOptions;
import org.springframework.http.client.reactive.ClientHttpConnector;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;

/**
* Factory for {@link ClientHttpConnector} that supports {@link ReactorClientHttpConnector}.
* Factory for {@link ClientHttpConnector} that supports
* {@link ReactorClientHttpConnector}.
*
* @author Mark Paluch
* @author Scott Frederick
*/
public class ClientHttpConnectorFactory {
public final class ClientHttpConnectorFactory {

private static final Log logger = LogFactory.getLog(ClientHttpConnectorFactory.class);

private static final SslCertificateUtils sslCertificateUtils = new SslCertificateUtils();

private ClientHttpConnectorFactory() {
}

/**
* Create a {@link ClientHttpConnector} for the given {@link ClientOptions}.
*
* @param options must not be {@literal null}
* @return a new {@link ClientHttpConnector}.
*/
public static ClientHttpConnector create(ClientOptions options) {
HttpClient httpClient = HttpClient.create();

if (usingCustomCerts(options)) {
TrustManagerFactory trustManagerFactory =
sslCertificateUtils.createTrustManagerFactory(options.getCaCertFiles());

httpClient = httpClient.secure(sslContextSpec -> sslContextSpec
.sslContext(SslContextBuilder.forClient()
.sslProvider(SslProvider.JDK)
.trustManager(trustManagerFactory)));
} else {
httpClient = httpClient.secure(sslContextSpec -> {
TrustManagerFactory trustManagerFactory = sslCertificateUtils
.createTrustManagerFactory(options.getCaCertFiles());

httpClient = httpClient.secure((sslContextSpec) -> sslContextSpec.sslContext(
SslContextBuilder.forClient().sslProvider(SslProvider.JDK).trustManager(trustManagerFactory)));
}
else {
httpClient = httpClient.secure((sslContextSpec) -> {
try {
sslContextSpec
.sslContext(new JdkSslContext(SSLContext.getDefault(), true, null,
IdentityCipherSuiteFilter.INSTANCE, null, ClientAuth.REQUIRE, null, false));
} catch (NoSuchAlgorithmException e) {
logger.error("Error configuring HTTP connections", e);
throw new RuntimeException("Error configuring HTTP connections", e);
sslContextSpec.sslContext(new JdkSslContext(SSLContext.getDefault(), true, null,
IdentityCipherSuiteFilter.INSTANCE, null, ClientAuth.REQUIRE, null, false));
}
catch (NoSuchAlgorithmException ex) {
logger.error("Error configuring HTTP connections", ex);
throw new RuntimeException("Error configuring HTTP connections", ex);
}
});
}

if (options.getConnectionTimeout() != null) {
httpClient = httpClient.tcpConfiguration(tcpClient ->
tcpClient.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
httpClient = httpClient
.tcpConfiguration((tcpClient) -> tcpClient.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
Math.toIntExact(options.getConnectionTimeout().toMillis())));
}

Expand All @@ -89,4 +91,5 @@ public static ClientHttpConnector create(ClientOptions options) {
private static boolean usingCustomCerts(ClientOptions options) {
return options.getCaCertFiles() != null;
}

}
Loading

0 comments on commit efbedf8

Please sign in to comment.