Commit Graph

643 Commits

Author SHA1 Message Date
Sam Brannen de07ad47f1 Polishing, suppression of deprecation warnings, copyright headers, etc. 2022-12-05 14:16:22 -05:00
Sam Brannen ad60164911 Update copyright headers for source code changed since August 2022
The changes in this commit were performed using the newly introduced
update_copyright_headers.sh script.
2022-11-29 19:38:42 +01:00
Sam Brannen 7fcd1de8e3 Use AssertJ's isEmpty() instead of hasSize(0)
Achieved via global search-and-replace.
2022-11-22 17:11:50 +01:00
Sam Brannen d5b0b2b1a1 User AssertJ's hasSize() for arrays
Achieved via global search-and-replace.
2022-11-22 17:03:45 +01:00
Sam Brannen 36f7597f25 Use AssertJ's hasSize() for collections and maps
Achieved via a global search-and-replace.
2022-11-22 16:50:10 +01:00
Sam Brannen 917c41fd52 Use Set.of() for constant sets where appropriate 2022-11-21 16:49:07 +01:00
Sam Brannen 3438c47744 Polishing 2022-11-08 11:48:13 +01:00
Stephane Nicoll affccba8f1 Simplify AOT contribution for scoped proxies
This commit makes sure that a `ScopedProxyFactoryBean` is exposed in the
container, rather than its underlying proxy. Previously, any lifecycle
method that the proxy target exposed were invoked in the container.

This is a complementary fix to gh-29335
2022-10-19 17:25:35 +02:00
Johnny Lim ced37d53b4 Polishing
Closes gh-29284
2022-10-08 13:43:09 +02:00
Sam Brannen 72307bbb20 Polish contribution
See gh-28549
2022-10-07 16:35:55 +02:00
hebo 2434470457 Optimize SpEL and property placeholder support for @Async qualifiers
See gh-27818
Closes gh-28549
2022-10-07 16:22:18 +02:00
Juergen Hoeller 3af0c232b7 ProxyFactoryBean determines actual proxy class in getObjectType()
AopProxy implementations accept empty Advisor chains for early proxy class creation.

Closes gh-29097
2022-10-06 11:54:06 +02:00
Stephane Nicoll e6aef11b09 Allow target to be a ClassName rather than an existing Class
See gh-29207
2022-09-27 10:33:14 +02:00
Stephane Nicoll c19cedede1 Revisit BeanRegistrationCodeFragments
This commit revisit BeanRegistrationCodeFragments to separate the
responsibility between the default implementation and the delegates. It
also reviews how customization are applied by improving the Javadoc and
the method name.

Closes gh-28865
2022-09-22 15:32:28 +02:00
Stephane Nicoll 4625e92eb8 Break dependency between TestCompiler and AOT
This commit improves `TestCompiler` with a `with` function that allows
to customize a test compiler instance. Rather than `TestCompiler`
knowing about `TestGenerationContext`, the latter implements the
function so that it can be passed as is.

See gh-29175
2022-09-20 15:07:51 +02:00
Phillip Webb 52bffbff76 Move `TestCompiler` and related classes to `core.test.tools` package
Closes gh-29175
2022-09-19 22:29:40 -07:00
Sam Brannen 8d92c57777 Merge branch '5.3.x'
# Conflicts:
#	spring-tx/src/main/java/org/springframework/jca/cci/core/support/CciDaoSupport.java
2022-09-14 16:52:55 +02:00
Marc Wrobel 92a231cf91 Fix typos in Javadoc, reference docs, and code
Closes gh-28822
2022-09-14 16:45:34 +02:00
Stephane Nicoll ae706f3954 Allow MethodReference to define a more flexible signature
This commit moves MethodReference to an interface with a default
implementation that relies on a MethodSpec. Such an arrangement avoid
the need of specifying attributes of the method such as whether it is
static or not.

The resolution of the invocation block now takes an
ArgumentCodeGenerator rather than the raw arguments. Doing so gives
the opportunity to create more flexible signatures.

See gh-29005
2022-09-12 10:07:31 +02:00
Stephane Nicoll 8a4a89b9d9 Allow a MethodReference to be produced from a GeneratedMethod
This commit updates GeneratedMethod and its underlying infrastructure
to be able to produce a MethodReference. This simplifies the need when
such a reference needs to be created manually and reuses more of what
MethodReference has to offer.

See gh-29005
2022-09-12 10:07:13 +02:00
Brian Clozel 2b5ca63339 Fix serialization compiler warnings with Java 18
As of Java 18, the serial lint warning in javac has been expanded to
check for class fields that are not marked as `Serializable`.
See https://www.oracle.com/java/technologies/javase/18all-relnotes.html#JDK-8202056

In the Spring Framework codebase, this can happen with `Map`, `Set` or
`List` attributes which are often assigned with an unmodifiable
implementation variant. Such implementations are `Serializable` but
cannot be used as field types.

This commit ensures that the following changes are applied:
* fields are marked as transient if they can't be serialized
* classes are marked as `Serializable` if this was missing
* `@SuppressWarnings("serial")` is applied where relevant
2022-09-09 20:24:26 +02:00
Stephane Nicoll 6e93f1187c Move TestCompiler from generator to generate
This commit harmonizes the package space by moving the TestCompiler
infrastructure from the now outdated "generator" package to "generate".

Closes gh-29082
2022-09-05 16:30:19 +02:00
Stephane Nicoll 58b0251af1 Relocate TestGenerationContext to spring-core-test
This commit moves the test implementation for GenerationContext in
spring-core-test. This also removes the copy we had in testfixtures

See gh-28877
2022-09-05 16:21:17 +02:00
Juergen Hoeller 38c9e7f629 Polishing 2022-08-10 23:30:27 +02:00
Juergen Hoeller b31a15851e Support for pre-generated CGLIB proxy classes (in AOT scenarios)
Includes runtime storing of generated classes to a directory specified by the "cglib.generatedClasses" system property. Avoids lazy CGLIB fast-class generation and replaces generated Enhancer and MethodWrapper key classes with equivalent record types. Introduces support for early type determination in InstantiationStrategy, AopProxy and SmartInstantiationAwareBeanPostProcessor - in order to trigger CGLIB class generation in refreshForAotProcessing (through early determineBeanType calls for bean definitions).

Closes gh-28115
2022-08-10 23:30:19 +02:00
Sam Brannen e4395f2f8b Clean up warnings and polishing 2022-07-31 14:14:56 +03:00
Phillip Webb 472c23455a Add AotServices class to replace AotFactoriesLoader
Add an `AotServices` class to replace `AotFactoriesLoader`. The
replacement class allow instances to be loaded from just the
`aot.factories` file if required. It also retains a link to the bean
names so that a `findByBeanName(...)` method can be provided.

See gh-28833
2022-07-27 19:25:28 +01:00
Arjen Poutsma 2aa74c9121 Deprecate ListenableFuture in favor of CompletableFuture
This commit deprecates ListenableFuture in favor of CompletableFuture.
ListenableFuture was introduced in Spring Framework 4.0, when
CompletableFuture was not yet available. Spring now requires JDK 17, so
having our own type no longer seems necessary.

Major changes in this commit include:
- Deprecation of ListenableFuture and related types
  (ListenableFutureCallback, SettableListenableFuture, etc.)
- Deprecation of AsyncListenableTaskExecutor in favor of default methods
  in AsyncTaskExecutor (submitCompletable).
- AsyncHandlerMethodReturnValueHandler now has toCompletableFuture
  instead of toListenableFuture.
- WebSocketClient now has execute methods, which do the same as
  doHandshake, but return CompletableFutures (cf. the reactive
  WebSocketClient).

All other changes
- add an overloaded method that takes a CompletableFuture parameter
  instead of ListenableFuture, and/or
- add a method with a 'Async' suffix that returns a CompletableFuture
  instead of a ListenableFuture (connectAsync, sendAsync).

Closes gh-27780
2022-07-27 12:41:35 +02:00
Stephane Nicoll 3d5003ad63 Introduce TestGenerationContext
This commit polishes DefaultGenerationContext to make the method
that flushes generated classes more explicit. It now throws an
IOException and TestGenerationContext has been updated to handle
that to ease its use in code that can't throw such an exception.

As this use case is likely to happen outside the Spring Framework,
this commit adds such a convenience to spring-test as well.

Closes gh-28877
2022-07-26 17:56:17 +02:00
Phillip Webb f2d31b7a20 Migrate AOT tests to use GeneratedClasses and refine/polish AOT APIs
Migrate all AOT tests to make use of `GeneratedClasses` rather than
directly generating Java files. This commit also refines and polishes
AOT APIs to being greater consistency.

Specifically:

	- The `MethodGenerator` interface has been removed in favor of
	  working directly with `GeneratedMethods`.
	- The visibility of several constructors and methods has been
	  reduced to package-private.
	- The `using(...)` and `builder` methods have been removed in
	  favor of setting the `Consumer` callbacks directly as
	  constructor arguments.
	- Variable names for builders are now named `type` or `method`
	  depending on what they're building.

Closes gh-28831
2022-07-18 08:40:59 +01:00
Juergen Hoeller a426f87a5f Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java
2022-07-13 17:08:21 +02:00
Juergen Hoeller 8e5c4903d4 Avoid synchronization in AbstractAspectJAdvice#calculateArgumentBindings
Aligned with the early calculateArgumentBindings call in ReflectiveAspectJAdvisorFactory.

Closes gh-26377
2022-07-13 16:47:35 +02:00
Sam Brannen 8242897c81 Merge branch '5.3.x' 2022-07-13 16:13:49 +02:00
Sam Brannen 2e4d7e4ef9 Polishing 2022-07-13 16:13:09 +02:00
Marc Wrobel c6be3b33c9 Fix and improve Javadoc in spring-aop
Closes gh-28803
2022-07-13 16:13:02 +02:00
Sam Brannen 49dfcad447 Remove AopProxyUtils.completeJdkProxyInterfaces(String...)
Since gh-28781 is still open for team discussion, this commit removes
the `String...` variant for AopProxyUtils.completeJdkProxyInterfaces.

Depending on the outcome of gh-28781, this method may be reintroduced
in 6.0 M6.

Closes gh-28745
2022-07-11 17:48:38 +02:00
Sam Brannen 7bfcb4c753 Reject sealed interfaces in AopProxyUtils.completeJdkProxyInterfaces()
See gh-28745
2022-07-11 17:47:41 +02:00
Sam Brannen 5178e9c28e Simplify hint registration for Spring AOP proxies
Prior to this commit, when users wished to register proxy hints for a
Spring AOP JDK dynamic proxy, they were required to explicitly specify
SpringProxy, Advised, and DecoratingProxy along with user interfaces.

This commit simplifies hint registration for Spring AOP proxies by
introducing two completeJdkProxyInterfaces() methods in AopProxyUtils,
one that accepts strings and one that accepts classes that represent
the user-specified interfaces implemented the user component to be
proxied. The SpringProxy, Advised, and DecoratingProxy interfaces are
appended to the user-specified interfaces and returned as the complete
set of interfaces that the proxy will implement.

Closes gh-28745
2022-07-10 20:10:12 +02:00
Sam Brannen 2a0b3c1af9 Polish AopProxyUtilsTests 2022-07-10 20:10:12 +02:00
Sam Brannen 2af08cf163 Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/test/java/org/springframework/core/annotation/TypeMappedAnnotationTests.java
#	spring-test/src/test/java/org/springframework/test/context/junit4/TimedSpringRunnerTests.java
#	spring-test/src/test/java/org/springframework/test/util/MetaAnnotationUtilsTests.java
#	spring-test/src/test/java/org/springframework/test/util/OverriddenMetaAnnotationAttributesTests.java
2022-07-09 16:24:04 +02:00
Sam Brannen d274e893a6 Remove superfluous static declaration for enum, annotation, & interface 2022-07-09 16:16:13 +02:00
Sébastien Deleuze 1458d5f39f Add support for @Transactional in native images
This commit introduces a TransactionBeanRegistrationAotProcessor
in charge of creating the required proxy and reflection hints
when @Transactional is detected on beans.

It also refines DefaultAopProxyFactory to throw an exception
when a subclass-based proxy is created in native images
since that's unsupported for now (see gh-28115 related issue).

Closes gh-28717
2022-07-08 16:47:35 +02:00
Sébastien Deleuze 8ccf05adee Remove SpringProxyRuntimeHintsRegistrar
A dynamic mechanism to register proxy and reflection
hints for classes annotated by @Transactional is needed
instead.

See gh-28717
2022-07-07 18:10:53 +02:00
Sébastien Deleuze 0387d54607 Add support for Transactional in native-image
This commit annotates @Transactional with @Reflective
and registers proxy hints for SpringProxy.

Injection of proxied beans via their interfaces still fails
in native images with a
"No qualifying bean of type MyInterface" error.

See gh-28717
2022-07-07 10:30:34 +02:00
Sam Brannen 36cf1ac1ef Apply "instanceof pattern matching" in AopProxyUtils 2022-07-05 14:55:58 +02:00
Stephane Nicoll 6199835d6e Harmonize generated class name conventions
This commit moves the responsibility of naming classes to the
GenerationContext. This was already largely the case before, except that
the concept of a "mainTarget" and "featureNamePrefix" was specific
to bean factory initialization contributors.

ClassNameGenerator should now be instantiated with a default target
and an optional feature name prefix. As a result, it does no longer
generate class names in the "__" package.

GeneratedClasses can now provide a new, unique, GeneratedClass or
offer a container for retrieving the same GeneratedClass based on an
identifier. This lets all contributors use this facility rather than
creating JavaFile manually. This also means that ClassNameGenerator
is no longer exposed.

Because the naming conventions are now part of the GenerationContext, it
is required to be able to retrieve a specialized version of it if a
code generation round needs to use different naming conventions. A new
withName method has been added to that effect.

Closes gh-28585
2022-06-23 16:05:23 +02:00
Stephane Nicoll 90759fb38f Relocate duplicated mock implementations to test fixtures
Closes gh-28659
2022-06-20 08:55:52 +02:00
Stephane Nicoll 92961d75f0 Polish tests 2022-06-07 12:03:50 +02:00
Stephane Nicoll 176ea5e9a7 Fix registration of ScopedProxyBeanRegistrationAotProcessor
Closes gh-28561
2022-06-03 14:28:08 +02:00
Phillip Webb 8d79ec0b67 Allow AOT contributions to customize code fragments.
Update the `BeanRegistrationAotContribution` interface to allow
it to customize `BeanRegistrationCodeFragments`. This change
allows us to drop the `BeanRegistrationCodeFragmentsCustomizer`
interface since an `BeanRegistrationAotProcessor` can now be
used instead.

Closes gh-28557
2022-06-02 18:07:47 -07:00