Skip to content

Commit

Permalink
Update spring-javaformat to 0.0.39
Browse files Browse the repository at this point in the history
Closes gh-2528
  • Loading branch information
marcusdacoregio committed Oct 19, 2023
1 parent db7b19b commit 2b69cff
Show file tree
Hide file tree
Showing 101 changed files with 767 additions and 657 deletions.
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ dependencies {
implementation 'com.apollographql.apollo:apollo-runtime:2.4.5'
implementation 'com.github.ben-manes:gradle-versions-plugin:0.38.0'
implementation 'com.github.spullara.mustache.java:compiler:0.9.11'
implementation 'io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.34'
implementation 'io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.39'
implementation 'io.spring.nohttp:nohttp-gradle:0.0.11'
implementation 'net.sourceforge.htmlunit:htmlunit:2.37.0'
implementation 'org.hidetake:gradle-ssh-plugin:2.10.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package io.spring.gradle.convention

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.plugins.JavaPlugin

/**
Expand All @@ -31,12 +32,14 @@ class CheckstylePlugin implements Plugin<Project> {

@Override
void apply(Project project) {
def versionCatalog = project.rootProject.extensions.getByType(VersionCatalogsExtension.class)
.named("libs")
project.plugins.withType(JavaPlugin) {
def checkstyleDir = project.rootProject.file(CHECKSTYLE_DIR)
if (checkstyleDir.exists() && checkstyleDir.directory) {
project.getPluginManager().apply('checkstyle')
project.dependencies.add('checkstyle', 'io.spring.javaformat:spring-javaformat-checkstyle:0.0.29')
project.dependencies.add('checkstyle', 'io.spring.nohttp:nohttp-checkstyle:0.0.3.RELEASE')
project.dependencies.add('checkstyle', versionCatalog.findLibrary('io-spring-javaformat-spring-javaformat-checkstyle').get())
project.dependencies.add('checkstyle', versionCatalog.findLibrary('io-spring-nohttp-nohttp-checkstyle').get())

project.checkstyle {
configDirectory = checkstyleDir
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ com-zaxxer-HikariCP = "com.zaxxer:HikariCP:5.0.1"
edu-umd-cs-mtc-multithreadedtc = "edu.umd.cs.mtc:multithreadedtc:1.01"
io-lettuce-lettuce-core = "io.lettuce:lettuce-core:6.2.6.RELEASE"
io-projectreactor-reactor-bom = { module = "io.projectreactor:reactor-bom", version = "2022.0.12" }
io-spring-javaformat-spring-javaformat-checkstyle = "io.spring.javaformat:spring-javaformat-checkstyle:0.0.29"
io-spring-javaformat-spring-javaformat-checkstyle = "io.spring.javaformat:spring-javaformat-checkstyle:0.0.39"
io-spring-nohttp-nohttp-checkstyle = "io.spring.nohttp:nohttp-checkstyle:0.0.11"
jakarta-servlet-jakarta-servlet-api = "jakarta.servlet:jakarta.servlet-api:6.0.0"
jakarta-servlet-jsp-jstl-jakarta-servlet-jsp-jstl-api = "jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api:3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface FindByIndexNameSessionRepository<S extends Session> extends Ses
* @since 1.1
*/
String PRINCIPAL_NAME_INDEX_NAME = FindByIndexNameSessionRepository.class.getName()
.concat(".PRINCIPAL_NAME_INDEX_NAME");
.concat(".PRINCIPAL_NAME_INDEX_NAME");

/**
* Find a {@link Map} of the session id to the {@link Session} of all sessions that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public final class MapSession implements Session, Serializable {
* Default {@link #setMaxInactiveInterval(Duration)} (30 minutes).
*/
public static final Duration DEFAULT_MAX_INACTIVE_INTERVAL = Duration
.ofSeconds(DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
.ofSeconds(DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);

private String id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ class CommonSessionRuntimeHints implements RuntimeHintsRegistrar {

@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
Arrays.asList(TypeReference.of(String.class), TypeReference.of(ArrayList.class),
TypeReference.of(TreeSet.class), TypeReference.of(Number.class), TypeReference.of(Long.class),
TypeReference.of(Integer.class), TypeReference.of(StackTraceElement.class),
TypeReference.of(Throwable.class), TypeReference.of(Exception.class),
TypeReference.of(RuntimeException.class),
TypeReference.of("java.util.Collections$UnmodifiableCollection"),
TypeReference.of("java.util.Collections$UnmodifiableList"),
TypeReference.of("java.util.Collections$EmptyList"),
TypeReference.of("java.util.Collections$UnmodifiableRandomAccessList"),
TypeReference.of("java.util.Collections$UnmodifiableSet")).forEach(hints.serialization()::registerType);
Arrays
.asList(TypeReference.of(String.class), TypeReference.of(ArrayList.class), TypeReference.of(TreeSet.class),
TypeReference.of(Number.class), TypeReference.of(Long.class), TypeReference.of(Integer.class),
TypeReference.of(StackTraceElement.class), TypeReference.of(Throwable.class),
TypeReference.of(Exception.class), TypeReference.of(RuntimeException.class),
TypeReference.of("java.util.Collections$UnmodifiableCollection"),
TypeReference.of("java.util.Collections$UnmodifiableList"),
TypeReference.of("java.util.Collections$EmptyList"),
TypeReference.of("java.util.Collections$UnmodifiableRandomAccessList"),
TypeReference.of("java.util.Collections$UnmodifiableSet"))
.forEach(hints.serialization()::registerType);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,37 @@ private void registerSecurityHintsIfNeeded(RuntimeHints hints) {
TypeReference.of("org.springframework.security.authentication.CredentialsExpiredException"),
TypeReference.of("org.springframework.security.authentication.InsufficientAuthenticationException"),
TypeReference
.of("org.springframework.security.web.authentication.session.SessionAuthenticationException"),
TypeReference.of(
"org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationException"),
.of("org.springframework.security.web.authentication.session.SessionAuthenticationException"),
TypeReference
.of("org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationException"),
TypeReference.of("org.springframework.security.core.userdetails.User$AuthorityComparator"))
.forEach((type) -> hints.serialization().registerType(type, (hint) -> hint.onReachableType(
.forEach((type) -> hints.serialization()
.registerType(type, (hint) -> hint.onReachableType(
TypeReference.of("org.springframework.security.core.context.SecurityContextImpl"))));
}

private void registerOAuth2ResourceServerHintsIfNeeded(RuntimeHints hints) {
Arrays.asList(
TypeReference.of("org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken"),
TypeReference.of(
"org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken"),
TypeReference
.of("org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken"),
TypeReference.of("org.springframework.security.oauth2.core.OAuth2AuthenticationException"))
.forEach((type) -> hints.serialization().registerType(type, (hint) -> hint.onReachableType(TypeReference
.of("org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken"))));
.forEach((type) -> hints.serialization()
.registerType(type, (hint) -> hint.onReachableType(TypeReference
.of("org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken"))));
}

private void registerOAuth2ClientHintsIfNeeded(RuntimeHints hints) {
Arrays.asList(
TypeReference.of("org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken"),
TypeReference
.of("org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken"),
TypeReference.of(
"org.springframework.security.oauth2.client.authentication.OAuth2AuthorizationCodeAuthenticationToken"),
.of("org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken"),
TypeReference
.of("org.springframework.security.oauth2.client.authentication.OAuth2AuthorizationCodeAuthenticationToken"),
TypeReference.of("org.springframework.security.oauth2.core.OAuth2AuthenticationException"))
.forEach((type) -> hints.serialization().registerType(type, (hint) -> hint.onReachableType(TypeReference
.of("org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken"))));
.forEach((type) -> hints.serialization()
.registerType(type, (hint) -> hint.onReachableType(TypeReference
.of("org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken"))));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class WebSessionSecurityRuntimeHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
if (!ClassUtils.isPresent("org.springframework.web.server.WebSession", classLoader) || !ClassUtils
.isPresent("org.springframework.security.web.server.csrf.DefaultCsrfToken", classLoader)) {
.isPresent("org.springframework.security.web.server.csrf.DefaultCsrfToken", classLoader)) {
return;
}
hints.serialization().registerType(DefaultCsrfToken.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|| !ClassUtils.isPresent("org.springframework.security.web.csrf.DefaultCsrfToken", classLoader)) {
return;
}
Arrays.asList(TypeReference.of(TreeMap.class), TypeReference.of(Locale.class),
TypeReference.of(DefaultSavedRequest.class), TypeReference.of(DefaultCsrfToken.class),
TypeReference.of(WebAuthenticationDetails.class), TypeReference.of(SavedCookie.class),
TypeReference.of("java.lang.String$CaseInsensitiveComparator"))
.forEach(hints.serialization()::registerType);
Arrays
.asList(TypeReference.of(TreeMap.class), TypeReference.of(Locale.class),
TypeReference.of(DefaultSavedRequest.class), TypeReference.of(DefaultCsrfToken.class),
TypeReference.of(WebAuthenticationDetails.class), TypeReference.of(SavedCookie.class),
TypeReference.of("java.lang.String$CaseInsensitiveComparator"))
.forEach(hints.serialization()::registerType);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public <S extends Session> SessionRepositoryFilter<? extends Session> springSess
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
if (ClassUtils.isPresent("org.springframework.security.web.authentication.RememberMeServices", null)) {
this.usesSpringSessionRememberMeServices = !ObjectUtils
.isEmpty(applicationContext.getBeanNamesForType(SpringSessionRememberMeServices.class));
.isEmpty(applicationContext.getBeanNamesForType(SpringSessionRememberMeServices.class));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
public final class CookieHttpSessionIdResolver implements HttpSessionIdResolver {

private static final String WRITTEN_SESSION_ID_ATTR = CookieHttpSessionIdResolver.class.getName()
.concat(".WRITTEN_SESSION_ID_ATTR");
.concat(".WRITTEN_SESSION_ID_ATTR");

private CookieSerializer cookieSerializer = new DefaultCookieSerializer();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void setAttribute(String name, Object value) {
if (oldValue instanceof HttpSessionBindingListener) {
try {
((HttpSessionBindingListener) oldValue)
.valueUnbound(new HttpSessionBindingEvent(this, name, oldValue));
.valueUnbound(new HttpSessionBindingEvent(this, name, oldValue));
}
catch (Throwable th) {
logger.error("Error invoking session binding event listener", th);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public Mono<WebSession> updateLastAccessTime(WebSession session) {
@Override
public Mono<WebSession> retrieveSession(String sessionId) {
return this.sessions.findById(sessionId)
.doOnNext((session) -> session.setLastAccessedTime(this.clock.instant())).map(this::existingSession);
.doOnNext((session) -> session.setLastAccessedTime(this.clock.instant()))
.map(this::existingSession);
}

@Override
Expand Down Expand Up @@ -233,8 +234,9 @@ public boolean containsKey(Object key) {

@Override
public boolean containsValue(Object value) {
return this.session.getAttributeNames().stream()
.anyMatch((attrName) -> this.session.getAttribute(attrName) != null);
return this.session.getAttributeNames()
.stream()
.anyMatch((attrName) -> this.session.getAttribute(attrName) != null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ else if (event instanceof SessionConnectEvent) {
else if (event instanceof SessionDisconnectEvent) {
SessionDisconnectEvent e = (SessionDisconnectEvent) event;
Map<String, Object> sessionAttributes = SimpMessageHeaderAccessor
.getSessionAttributes(e.getMessage().getHeaders());
.getSessionAttributes(e.getMessage().getHeaders());
String httpSessionId = (sessionAttributes != null)
? SessionRepositoryMessageInterceptor.getSessionId(sessionAttributes) : null;
afterConnectionClosed(httpSessionId, e.getSessionId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void setup() {
@Test
void constructorNullSession() {
assertThatIllegalArgumentException().isThrownBy(() -> new MapSession((Session) null))
.withMessage("session cannot be null");
.withMessage("session cannot be null");
}

@Test
Expand Down Expand Up @@ -70,7 +70,7 @@ void getAttributeOrDefaultWhenNotNullThenDefaultValue() {
@Test
void getRequiredAttributeWhenNullThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.session.getRequiredAttribute("attrName"))
.withMessage("Required attribute 'attrName' is missing.");
.withMessage("Required attribute 'attrName' is missing.");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void constructorMapThenFound() {
@Test
void constructorMapWhenNullThenThrowsIllegalArgumentException() {
assertThatIllegalArgumentException().isThrownBy(() -> new ReactiveMapSessionRepository(null))
.withMessage("sessions cannot be null");
.withMessage("sessions cannot be null");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ void commonSessionTypesHasHints(TypeReference typeReference) {
@Test
void aotFactoriesContainsRegistrar() {
boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
.load(RuntimeHintsRegistrar.class).stream()
.anyMatch((registrar) -> registrar instanceof CommonSessionRuntimeHints);
.load(RuntimeHintsRegistrar.class)
.stream()
.anyMatch((registrar) -> registrar instanceof CommonSessionRuntimeHints);
assertThat(match).isTrue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ void commonSecurityTypesHasHints(TypeReference typeReference) {
@Test
void aotFactoriesContainsRegistrar() {
boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
.load(RuntimeHintsRegistrar.class).stream()
.anyMatch((registrar) -> registrar instanceof CommonSessionSecurityRuntimeHints);
.load(RuntimeHintsRegistrar.class)
.stream()
.anyMatch((registrar) -> registrar instanceof CommonSessionSecurityRuntimeHints);
assertThat(match).isTrue();
}

Expand All @@ -73,19 +74,19 @@ private static Stream<TypeReference> getSerializationHintTypes() {
TypeReference.of("org.springframework.security.authentication.CredentialsExpiredException"),
TypeReference.of("org.springframework.security.authentication.InsufficientAuthenticationException"),
TypeReference
.of("org.springframework.security.web.authentication.session.SessionAuthenticationException"),
TypeReference.of(
"org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationException"),
.of("org.springframework.security.web.authentication.session.SessionAuthenticationException"),
TypeReference
.of("org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationException"),
TypeReference.of("org.springframework.security.core.userdetails.User$AuthorityComparator"),
TypeReference.of("org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken"),
TypeReference.of(
"org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken"),
TypeReference
.of("org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken"),
TypeReference.of("org.springframework.security.oauth2.core.OAuth2AuthenticationException"),
TypeReference.of("org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken"),
TypeReference
.of("org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken"),
TypeReference.of(
"org.springframework.security.oauth2.client.authentication.OAuth2AuthorizationCodeAuthenticationToken"),
.of("org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken"),
TypeReference
.of("org.springframework.security.oauth2.client.authentication.OAuth2AuthorizationCodeAuthenticationToken"),
TypeReference.of("org.springframework.security.oauth2.core.OAuth2AuthenticationException"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void defaultCsrfTokenHasHints() {
void registerHintsWhenWebSessionMissingThenDoNotRegisterHints() {
try (MockedStatic<ClassUtils> classUtilsMock = mockStatic(ClassUtils.class)) {
classUtilsMock.when(() -> ClassUtils.isPresent(eq("org.springframework.web.server.WebSession"), any()))
.thenReturn(false);
.thenReturn(false);
this.webSessionSecurityRuntimeHints.registerHints(this.hints, getClass().getClassLoader());
assertThat(this.hints.serialization().javaSerializationHints()).isEmpty();
}
Expand All @@ -62,9 +62,9 @@ void registerHintsWhenWebSessionMissingThenDoNotRegisterHints() {
void registerHintsWhenDefaultCsrfTokenMissingThenDoNotRegisterHints() {
try (MockedStatic<ClassUtils> classUtilsMock = mockStatic(ClassUtils.class)) {
classUtilsMock
.when(() -> ClassUtils
.isPresent(eq("org.springframework.security.web.server.csrf.DefaultCsrfToken"), any()))
.thenReturn(false);
.when(() -> ClassUtils.isPresent(eq("org.springframework.security.web.server.csrf.DefaultCsrfToken"),
any()))
.thenReturn(false);
this.webSessionSecurityRuntimeHints.registerHints(this.hints, getClass().getClassLoader());
assertThat(this.hints.serialization().javaSerializationHints()).isEmpty();
}
Expand All @@ -73,8 +73,9 @@ void registerHintsWhenDefaultCsrfTokenMissingThenDoNotRegisterHints() {
@Test
void aotFactoriesContainsRegistrar() {
boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
.load(RuntimeHintsRegistrar.class).stream()
.anyMatch((registrar) -> registrar instanceof WebSessionSecurityRuntimeHints);
.load(RuntimeHintsRegistrar.class)
.stream()
.anyMatch((registrar) -> registrar instanceof WebSessionSecurityRuntimeHints);
assertThat(match).isTrue();
}

Expand Down
Loading

0 comments on commit 2b69cff

Please sign in to comment.