Skip to content

Commit 9e621d6

Browse files
committed
Merge branch '3.4.x' into 3.5.x
Closes gh-47438
2 parents f3f17be + 3ba61c3 commit 9e621d6

File tree

9 files changed

+154
-22
lines changed

9 files changed

+154
-22
lines changed

buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureRules.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static List<ArchRule> standard() {
9393
rules.add(noClassesShouldCallStringToUpperCaseWithoutLocale());
9494
rules.add(noClassesShouldCallStringToLowerCaseWithoutLocale());
9595
rules.add(conditionalOnMissingBeanShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodReturnType());
96-
rules.add(enumSourceShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodParameterType());
96+
rules.add(enumSourceShouldNotHaveValueThatIsTheSameAsTypeOfMethodsFirstParameter());
9797
rules.add(classLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute());
9898
rules.add(methodLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute());
9999
rules.add(conditionsShouldNotBePublic());
@@ -240,7 +240,7 @@ private static ArchCondition<? super JavaMethod> notSpecifyOnlyATypeThatIsTheSam
240240
JavaAnnotation<JavaMethod> conditionalAnnotation = item
241241
.getAnnotationOfType("org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean");
242242
Map<String, Object> properties = conditionalAnnotation.getProperties();
243-
if (!properties.containsKey("type") && !properties.containsKey("name")) {
243+
if (!hasProperty("type", properties) && !hasProperty("name", properties)) {
244244
conditionalAnnotation.get("value").ifPresent((value) -> {
245245
if (containsOnlySingleType((JavaType[]) value, item.getReturnType())) {
246246
addViolation(events, item, conditionalAnnotation.getDescription()
@@ -251,32 +251,38 @@ private static ArchCondition<? super JavaMethod> notSpecifyOnlyATypeThatIsTheSam
251251
});
252252
}
253253

254-
private static ArchRule enumSourceShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodParameterType() {
254+
private static boolean hasProperty(String name, Map<String, Object> properties) {
255+
Object property = properties.get(name);
256+
if (property == null) {
257+
return false;
258+
}
259+
return !property.getClass().isArray() || ((Object[]) property).length > 0;
260+
}
261+
262+
private static ArchRule enumSourceShouldNotHaveValueThatIsTheSameAsTypeOfMethodsFirstParameter() {
255263
return ArchRuleDefinition.methods()
256264
.that()
257265
.areAnnotatedWith("org.junit.jupiter.params.provider.EnumSource")
258-
.should(notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType())
266+
.should(notHaveValueThatIsTheSameAsTheTypeOfTheMethodsFirstParameter())
259267
.allowEmptyShould(true);
260268
}
261269

262-
private static ArchCondition<? super JavaMethod> notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType() {
263-
return check("not specify only a type that is the same as the method's parameter type",
270+
private static ArchCondition<? super JavaMethod> notHaveValueThatIsTheSameAsTheTypeOfTheMethodsFirstParameter() {
271+
return check("not have a value that is the same as the type of the method's first parameter",
264272
ArchitectureRules::notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType);
265273
}
266274

267275
private static void notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType(JavaMethod item,
268276
ConditionEvents events) {
269277
JavaAnnotation<JavaMethod> enumSourceAnnotation = item
270278
.getAnnotationOfType("org.junit.jupiter.params.provider.EnumSource");
271-
Map<String, Object> properties = enumSourceAnnotation.getProperties();
272-
if (properties.size() == 1 && item.getParameterTypes().size() == 1) {
273-
enumSourceAnnotation.get("value").ifPresent((value) -> {
274-
if (value.equals(item.getParameterTypes().get(0))) {
275-
addViolation(events, item, enumSourceAnnotation.getDescription()
276-
+ " should not specify only a value that is the same as the method's parameter type");
277-
}
278-
});
279-
}
279+
enumSourceAnnotation.get("value").ifPresent((value) -> {
280+
JavaType parameterType = item.getParameterTypes().get(0);
281+
if (value.equals(parameterType)) {
282+
addViolation(events, item, enumSourceAnnotation.getDescription()
283+
+ " should not specify a value that is the same as the type of the method's first parameter");
284+
}
285+
});
280286
}
281287

282288
private static ArchRule classLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute() {

buildSrc/src/test/java/org/springframework/boot/build/architecture/ArchitectureCheckTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class ArchitectureCheckTests {
5757

5858
private static final String SPRING_CONTEXT = "org.springframework:spring-context:6.2.9";
5959

60+
private static final String JUNIT_JUPITER = "org.junit.jupiter:junit-jupiter:5.12.0";
61+
6062
private static final String SPRING_INTEGRATION_JMX = "org.springframework.integration:spring-integration-jmx:6.5.1";
6163

6264
private GradleBuild gradleBuild;
@@ -270,6 +272,29 @@ void whenBeanMethodExposesNonPrivateTypeShouldSucceedAndWriteEmptyReport(Task ta
270272
build(this.gradleBuild.withDependencies(SPRING_CONTEXT), task);
271273
}
272274

275+
@Test
276+
void whenEnumSourceValueIsInferredShouldSucceedAndWriteEmptyReport() throws IOException {
277+
prepareTask(Task.CHECK_ARCHITECTURE_TEST, "junit/enumsource/inferredfromparametertype");
278+
build(this.gradleBuild.withDependencies(JUNIT_JUPITER), Task.CHECK_ARCHITECTURE_TEST);
279+
}
280+
281+
@Test
282+
void whenEnumSourceValueIsNotTheSameAsTypeOfMethodsFirstParameterShouldSucceedAndWriteEmptyReport()
283+
throws IOException {
284+
prepareTask(Task.CHECK_ARCHITECTURE_TEST, "junit/enumsource/valuenecessary");
285+
build(this.gradleBuild.withDependencies(JUNIT_JUPITER), Task.CHECK_ARCHITECTURE_TEST);
286+
}
287+
288+
@Test
289+
void whenEnumSourceValueIsSameAsTypeOfMethodsFirstParameterShouldFailAndWriteReport() throws IOException {
290+
prepareTask(Task.CHECK_ARCHITECTURE_TEST, "junit/enumsource/sameasparametertype");
291+
buildAndFail(this.gradleBuild.withDependencies(JUNIT_JUPITER), Task.CHECK_ARCHITECTURE_TEST,
292+
"method <org.springframework.boot.build.architecture.junit.enumsource.sameasparametertype"
293+
+ ".EnumSourceSameAsParameterType.exampleMethod(org.springframework.boot.build."
294+
+ "architecture.junit.enumsource.sameasparametertype.EnumSourceSameAsParameterType$Example)>",
295+
"should not have a value that is the same as the type of the method's first parameter");
296+
}
297+
273298
private void prepareTask(Task task, String... sourceDirectories) throws IOException {
274299
for (String sourceDirectory : sourceDirectories) {
275300
FileSystemUtils.copyRecursively(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build.architecture.junit.enumsource.inferredfromparametertype;
18+
19+
import org.junit.jupiter.params.provider.EnumSource;
20+
21+
class EnumSourceInferredFromParameterType {
22+
23+
@EnumSource
24+
void exampleMethod(Example example) {
25+
26+
}
27+
28+
enum Example {
29+
30+
ONE, TWO, THREE
31+
32+
}
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build.architecture.junit.enumsource.sameasparametertype;
18+
19+
import org.junit.jupiter.params.provider.EnumSource;
20+
21+
class EnumSourceSameAsParameterType {
22+
23+
@EnumSource(Example.class)
24+
void exampleMethod(Example example) {
25+
26+
}
27+
28+
enum Example {
29+
30+
ONE, TWO, THREE
31+
32+
}
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build.architecture.junit.enumsource.valuenecessary;
18+
19+
import org.junit.jupiter.params.provider.EnumSource;
20+
21+
class EnumSourceValueNecessary {
22+
23+
@EnumSource(Example.class)
24+
void exampleMethod(String thing, Example example) {
25+
26+
}
27+
28+
enum Example {
29+
30+
ONE, TWO, THREE
31+
32+
}
33+
34+
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/sbom/SbomEndpointWebExtensionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void shouldUseContentTypeForAdditionalSbomsIfSet() {
112112
}
113113

114114
@ParameterizedTest
115-
@EnumSource(value = SbomType.class, names = "UNKNOWN", mode = Mode.EXCLUDE)
115+
@EnumSource(names = "UNKNOWN", mode = Mode.EXCLUDE)
116116
void shouldAutodetectFormats(SbomType type) throws IOException {
117117
String content = getSbomContent(type);
118118
assertThat(type.matches(content)).isTrue();

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/JacksonHttpMessageConvertersConfiguration.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ class JacksonHttpMessageConvertersConfiguration {
4444
static class MappingJackson2HttpMessageConverterConfiguration {
4545

4646
@Bean
47-
@ConditionalOnMissingBean(value = MappingJackson2HttpMessageConverter.class,
48-
ignoredType = {
49-
"org.springframework.hateoas.server.mvc.TypeConstrainedMappingJackson2HttpMessageConverter",
50-
"org.springframework.data.rest.webmvc.alps.AlpsJsonHttpMessageConverter" })
47+
@ConditionalOnMissingBean(ignoredType = {
48+
"org.springframework.hateoas.server.mvc.TypeConstrainedMappingJackson2HttpMessageConverter",
49+
"org.springframework.data.rest.webmvc.alps.AlpsJsonHttpMessageConverter" })
5150
MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(ObjectMapper objectMapper) {
5251
return new MappingJackson2HttpMessageConverter(objectMapper);
5352
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/ErrorWebFluxAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public ErrorWebFluxAutoConfiguration(ServerProperties serverProperties) {
5959
}
6060

6161
@Bean
62-
@ConditionalOnMissingBean(value = ErrorWebExceptionHandler.class, search = SearchStrategy.CURRENT)
62+
@ConditionalOnMissingBean(search = SearchStrategy.CURRENT)
6363
@Order(-1)
6464
public ErrorWebExceptionHandler errorWebExceptionHandler(ErrorAttributes errorAttributes,
6565
WebProperties webProperties, ObjectProvider<ViewResolver> viewResolvers,

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceScriptDatabaseInitializerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void getSettingsWithPlatformDoesNotTouchDataSource() {
6262
}
6363

6464
@ParameterizedTest
65-
@EnumSource(value = DatabaseDriver.class, mode = Mode.EXCLUDE, names = { "AWS_WRAPPER", "CLICKHOUSE", "FIREBIRD",
65+
@EnumSource(mode = Mode.EXCLUDE, names = { "AWS_WRAPPER", "CLICKHOUSE", "FIREBIRD",
6666
"INFORMIX", "JTDS", "PHOENIX", "REDSHIFT", "TERADATA", "TESTCONTAINERS", "UNKNOWN" })
6767
void batchSchemaCanBeLocated(DatabaseDriver driver) throws SQLException {
6868
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();

0 commit comments

Comments
 (0)