From 2d1d14b145e60b2d4067364daf7c11bb728e0189 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 2 Sep 2023 18:28:24 +0200 Subject: [PATCH 1/2] Add `/framework-*/build` to .gitignore Due to the introduction of the `framework-api` project in the main branch, we now have 3 `framework-*` projects that should be ignored. I have therefore removed `/framework-bom/build` and `/framework-docs/build` and added `/framework-*/build` to ignore all 3 framework projects. See gh-31049 --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 211080d88ab..14252754d45 100644 --- a/.gitignore +++ b/.gitignore @@ -21,8 +21,7 @@ derby.log /build buildSrc/build /spring-*/build -/framework-bom/build -/framework-docs/build +/framework-*/build /integration-tests/build /src/asciidoc/build spring-test/test-output/ From 3e3f05109fa20199721d16a2bb6813e0e8082b47 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 2 Sep 2023 18:39:03 +0200 Subject: [PATCH 2/2] Polishing --- .../ConfigurationClassPostProcessor.java | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java index f68c34ef0c4..fd8d0f92a1e 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java @@ -344,8 +344,8 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo @Nullable private Resource resolvePropertySourceLocation(String location) { try { - String resolvedLocation = (this.environment != null - ? this.environment.resolveRequiredPlaceholders(location) : location); + String resolvedLocation = (this.environment != null ? + this.environment.resolveRequiredPlaceholders(location) : location); return this.resourceLoader.getResource(resolvedLocation); } catch (Exception ex) { @@ -598,15 +598,11 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo Map mappings = buildImportAwareMappings(); if (!mappings.isEmpty()) { - GeneratedMethod generatedMethod = beanFactoryInitializationCode - .getMethods() - .add("addImportAwareBeanPostProcessors", method -> - generateAddPostProcessorMethod(method, mappings)); - beanFactoryInitializationCode - .addInitializer(generatedMethod.toMethodReference()); + GeneratedMethod generatedMethod = beanFactoryInitializationCode.getMethods().add( + "addImportAwareBeanPostProcessors", method -> generateAddPostProcessorMethod(method, mappings)); + beanFactoryInitializationCode.addInitializer(generatedMethod.toMethodReference()); ResourceHints hints = generationContext.getRuntimeHints().resources(); - mappings.forEach( - (target, from) -> hints.registerType(TypeReference.of(from))); + mappings.forEach((target, from) -> hints.registerType(TypeReference.of(from))); } } @@ -635,8 +631,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo } private Map buildImportAwareMappings() { - ImportRegistry importRegistry = this.beanFactory - .getBean(IMPORT_REGISTRY_BEAN_NAME, ImportRegistry.class); + ImportRegistry importRegistry = this.beanFactory.getBean(IMPORT_REGISTRY_BEAN_NAME, ImportRegistry.class); Map mappings = new LinkedHashMap<>(); for (String name : this.beanFactory.getBeanDefinitionNames()) { Class beanType = this.beanFactory.getType(name); @@ -671,11 +666,9 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo @Override public void applyTo(GenerationContext generationContext, BeanFactoryInitializationCode beanFactoryInitializationCode) { registerRuntimeHints(generationContext.getRuntimeHints()); - GeneratedMethod generatedMethod = beanFactoryInitializationCode - .getMethods() + GeneratedMethod generatedMethod = beanFactoryInitializationCode.getMethods() .add("processPropertySources", this::generateAddPropertySourceProcessorMethod); - beanFactoryInitializationCode - .addInitializer(generatedMethod.toMethodReference()); + beanFactoryInitializationCode.addInitializer(generatedMethod.toMethodReference()); } private void registerRuntimeHints(RuntimeHints hints) { @@ -686,8 +679,8 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo } for (String location : descriptor.locations()) { Resource resource = this.resourceResolver.apply(location); - if (resource != null && resource.exists() && resource instanceof ClassPathResource classpathResource) { - hints.resources().registerPattern(classpathResource.getPath()); + if (resource instanceof ClassPathResource classPathResource && classPathResource.exists()) { + hints.resources().registerPattern(classPathResource.getPath()); } } } @@ -723,8 +716,8 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo code.add("new $T(", PropertySourceDescriptor.class); CodeBlock values = descriptor.locations().stream() .map(value -> CodeBlock.of("$S", value)).collect(CodeBlock.joining(", ")); - if (descriptor.name() == null && descriptor.propertySourceFactory() == null - && descriptor.encoding() == null && !descriptor.ignoreResourceNotFound()) { + if (descriptor.name() == null && descriptor.propertySourceFactory() == null && + descriptor.encoding() == null && !descriptor.ignoreResourceNotFound()) { code.add("$L)", values); } else {