Commit Graph

2776 Commits

Author SHA1 Message Date
Stephane Nicoll ff9535ef15 Add file pattern resource hints registrar
This commit adds a utility method to register resources on the classpath
based on a location, name, and extension.

Closes gh-28626
2022-06-14 18:16:18 +02:00
Brian Clozel 7f7f458a59 Polish ResourceHintsPredicates
As of #28620, `ResourcePatternHint` exposes its `toRegex` method.
The predicates should use it directly and mirror the exact matching
behavior.

See gh-28555
2022-06-14 15:38:41 +02:00
Juergen Hoeller aa48dec697 Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java
2022-06-14 15:14:10 +02:00
Juergen Hoeller d7be1e0dab Polishing 2022-06-14 15:09:39 +02:00
Juergen Hoeller f8b41c1ad2 Consistent support for setContextClass in CGLIB beans package
Closes gh-28530
2022-06-14 15:08:44 +02:00
Sébastien Deleuze c235ad0b35 Introduce ResourcePatternHint#toRegex
This change is done for several reasons:
 - Move the logic where it is documented.
 - Test it with ResourcePatternHintTests.
 - Allow RuntimeHintsPredicates to leverage this logic.

Closes gh-28620
2022-06-14 15:07:12 +02:00
Stephane Nicoll 77ad4a1428 Polish 2022-06-14 14:15:29 +02:00
Stephane Nicoll d6d4b98780 Add ifPresent utility methods on RuntimeHints
This commit adds a utility method to register a type for reflection if
it is available on the classpath. It also adds a method to register a
resource pattern if a given location is available.

Closes gh-28617
2022-06-14 14:15:29 +02:00
Juergen Hoeller c4e8ffece1 Remove outdated NativeDetector check for Kotlin reflection
See gh-25179
2022-06-14 14:02:41 +02:00
Juergen Hoeller 4e1b9f1492 Replace deep exception message nesting with custom inclusion of cause messages
Includes deprecation of NestedServletException, whereas NestedCheckedException and NestedRuntimeException remain as base classes with several convenience methods.

Closes gh-25162
2022-06-14 14:00:28 +02:00
Arjen Poutsma bf9f261b95 Revert "Support recursive annotations in merged annotations"
This reverts commit 3ec612aaf8.
2022-06-14 13:03:29 +02:00
Arjen Poutsma df37e33105 Revert "Ensure fix for gh-28012 is actually tested"
This reverts commit 3188c0f7db.
2022-06-14 13:03:05 +02:00
Brian Clozel 7e8b1ed401 Polish
Move hints registration to spring-beans, where the actual behavior is
implemented. We chose not to move this to
`AutowiredAnnotationBeanPostProcessor` for now, as this would require it
to implement another AOT-related interface and add too much noise for
this.

See gh-28614
2022-06-14 10:08:06 +02:00
Brian Clozel bb952cb95e Register native hints for jakarta.inject annotations
Prior to this commit, native images would dynamically check for the
presence of `jakarta.inject.*` annotations and might fail at runtime or
miss them entirely.

This change ensures that if such classes are present during the AOT
build, relevant runtime hints are registered so that these annotations
can be read at runtime.

Closes gh-28614
2022-06-13 18:50:33 +02:00
Brian Clozel 15b69a3ede Polish RuntimeHintsPredicates
This commit adds a method variant checking that all `MemberCategory` are
supported by the `RuntimeHints` for a given type hint.

See gh-28555
2022-06-13 18:40:46 +02:00
Sam Brannen dc3ec5b665 Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java
2022-06-13 18:06:08 +02:00
Sam Brannen 97854d9fec Refactor ObjectToObjectConverter to use Executable instead of Member 2022-06-13 18:01:54 +02:00
Sam Brannen 73f3860bb7 Polish Javadoc for ObjectToObjectConverter 2022-06-13 18:01:05 +02:00
Sam Brannen f722dbe5a8 Polishing 2022-06-13 17:35:50 +02:00
Sam Brannen c3b29960ed Merge branch '5.3.x' 2022-06-13 17:23:14 +02:00
Sam Brannen 452f1b877c Consider return type of static methods in ObjectToObjectConverter
Prior to this commit, ObjectToObjectConverter considered the return
type of non-static `to[targetType.simpleName]()` methods but did not
consider the return type of static `valueOf(sourceType)`,
`of(sourceType)`, and `from(sourceType)` methods.

This led to scenarios in which `canConvert()` returned `true`, but a
subsequent `convert()` invocation resulted in a
ConverterNotFoundException, which violates the contract of the
converter.

This commit addresses this issue by taking into account the return type
of a static valueOf/of/from factory method when determining if the
ObjectToObjectConverter supports a particular conversion. Whereas the
existing check in `determineToMethod()` ensures that the method return
type is assignable to the `targetType`, the new check in
`determineFactoryMethod()` leniently ensures that the method return
type and `targetType` are "related" (i.e., reside in the same type
hierarchy).

Closes gh-28609
2022-06-13 17:20:18 +02:00
Sébastien Deleuze a57dead4be Add support for serialization in RequestMappingReflectiveProcessor
Support reflection-based serialization of parameters annotated
with @RequestBody and return values annotated with @ResponseBody.

It leverages a new BindingReflectionHintsRegistrar class that
is designed to register transitively the types usually needed
for binding and reflection-based serialization on fields,
constructors and properties. Generics are taken in account
as well.

Closes gh-28518
2022-06-13 15:25:44 +02:00
Sébastien Deleuze 2b76a12b86 Refine build time init configuration
For Spring MVC and RestTemplate.

See gh-28518
2022-06-13 14:54:57 +02:00
Brian Clozel 9c9b2356ce Add RuntimeHints predicates generator
The `RuntimeHints` API allows to describe hints for the reflection,
proxies and resources behavior at runtime. The need for a particular
behavior can be covered by several types of hints, at different levels.
This knowledge can be important in several cases:

* before contributing additional hints, infrastructure can check if an
  existing hint already covers the behavior
* this can be used in test suites and test infrastructure

This commit adds a new RuntimeHintsPredicates that generates `Predicate`
instances for testing `RuntimeHints` against a desired runtime behavior
for reflection, resources or proxies.

Closes gh-28555
2022-06-10 18:55:14 +02:00
Stephane Nicoll 100ce9642a Use TypeReference consistently in hints writer
Closes gh-28606
2022-06-10 15:28:24 +02:00
Stephane Nicoll 1e5f4f8b44 Polish 2022-06-09 15:12:38 +02:00
Sébastien Deleuze b9f85627a1 Improve ResourcePatternHint documentation
Closes gh-28598
2022-06-09 14:50:43 +02:00
Sébastien Deleuze 99ffd97a72 Fix ResourceHintsWriter for leading/trailing wildcards
Closes gh-28597
2022-06-09 14:50:43 +02:00
Stephane Nicoll 16eff68357 Fix package tangle between o.s.core and o.s.aot
Closes gh-28496
2022-06-08 11:53:51 +02:00
rstoyanchev 875ee546e5 Merge branch '5.3.x' 2022-06-08 10:43:36 +01:00
rstoyanchev 8fcc7ab9d1 CompositeLog respects log level changes at runtime
Closes gh-28477
2022-06-08 10:07:52 +01:00
Phillip Webb 4bd33cb6e0 Allow ApplicationContextAotGenerator to generated better class names
Update `ApplicationContextAotGenerator` so that it can generate class
names based on a `target` class and using the ID of the application
context. Prior to this commit, the generated class name was always
`__.BeanFactoryRegistrations`.

Closes gh-28565
2022-06-03 18:15:37 -07:00
Sébastien Deleuze 74c49c510a Use a single --initialize-at-build-time parameter per file
Closes gh-28563
2022-06-03 17:39:47 +02:00
Sam Brannen 92f8ab774f Stop initializing DataSize at build time for GraalVM
In light of gh-28560, this commit reverts the change made in gh-28328.

Closes gh-28562
2022-06-03 16:41:36 +02:00
Sam Brannen 73acab7635 Merge branch '5.3.x'
# Conflicts:
#	spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContextUtils.java
2022-06-03 13:35:22 +02:00
Sam Brannen e2767371b5 Lazily initialize DataSize.PATTERN
To avoid unnecessary eager initialization of DataSize.PATTERN, this
commit initializes it lazily in the first invocation of DataSize.parse
by moving PATTERN to a private static nested class.

Closes gh-28560
2022-06-03 13:30:45 +02:00
Stephane Nicoll da8c4de263 Add AotDetector to reliably opt-in for optimizations
This commit adds a central utility to figure out if the application
must run with Ahead-Of-Time optimizations. This is mandatory for running
in a native image but can be selected on the JVM using the
"spring.aot.enabled" property.

This commit also introduces a utility that can be used to initialize a
context with generated artifacts. This represents the runtime
counterpart of ApplicationContextAotGenerator.

Closes gh-28474
2022-06-02 14:52:11 +02:00
Brian Clozel 8af1496b37 Expand hints conditions support in RuntimeHints
Prior to this commit, the hints conditions were only supported for the
`TypeHint` case. GraalVM generally expanded this concept to all hints
and we should do the same.

Right now, only the `typeReachable` condition is available but we should
design for possible future additions.

This commit introduces a new `ConditionalHint` contract implemented by
all hints compatible with this approach. The condition information is
also used in all configuration writers as a result.

Closes gh-28126
2022-06-02 11:35:03 +02:00
Arjen Poutsma d9d45cc0b1 Treat Reactive Publishers the same as Kotlin Flows
This commit makes sure that CoroutinesUtils::invokeSuspendingFunction
treats Reactive Publisher instances the same as Kotlin Flows, i.e.
it flatmaps them.

Closes gh-27011
2022-06-01 14:30:40 +02:00
Sam Brannen ee209de9cf Merge branch '5.3.x'
# Conflicts:
#	spring-beans/src/test/java/org/springframework/beans/factory/support/security/CallbacksSecurityTests.java
#	spring-context/src/test/java/org/springframework/ejb/access/LocalSlsbInvokerInterceptorTests.java
#	spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteSlsbInvokerInterceptorTests.java
#	spring-web/src/test/java/org/springframework/remoting/jaxws/JaxWsSupportTests.java
#	spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolutionIntegrationTests.java
2022-05-31 14:15:36 +02:00
Sam Brannen 1beb7068f6 Use new AssertJ exception assertions 2022-05-31 14:08:28 +02:00
Sam Brannen b79f981510 Document Checkstyle issue regarding instanceof pattern variables
See https://github.com/checkstyle/checkstyle/issues/10969
2022-05-30 19:58:21 +02:00
Sam Brannen 16f65e59b4 Polish contribution
See gh-28188
2022-05-30 19:35:28 +02:00
Sam Brannen 43dd813ee6 Temporary workaround for Checkstyle bug
Attempting to name a variable in an "instanceof pattern" the same as
a field results in a Checkstyle violation similar to the following if
the "instanceof pattern matching" is located within a constructor.

Reference to instance variable 'document' needs "this.". [RequireThis]

See gh-28188
2022-05-30 19:35:28 +02:00
diguage bbaf7578b2 Apply "instanceof pattern matching" in spring-core
Closes gh-28188
2022-05-30 19:29:48 +02:00
Sam Brannen 720261db26 Use List.of() and Set.of() where feasible 2022-05-30 18:42:48 +02:00
Sam Brannen ad46f0295c Apply "instanceof pattern matching" 2022-05-30 18:41:25 +02:00
Phillip Webb 718ef42d68 Exclude @Reflective from @AliasFor collection
Update `RuntimeHintsUtils` to skip `@Reflective` annotations when
checking for `@AliasFor`. Since the `@Reflective` annotation is only
used at AOT processing time, we shouldn't need a hint for it.

See gh-28528
2022-05-26 20:56:06 -07:00
Stephane Nicoll 86a85f558c Fix introspection of annotations that use local aliased attributes
Closes gh-28528
2022-05-26 15:50:41 +02:00
Stephane Nicoll 059b66bf26 Register annotation based on its type
This commit improves registerAnnotation to use the annotation type
rather than a `MergedAnnotation` attribute.

See gh-28497
2022-05-25 10:30:43 +02:00