codeconsole opened a new pull request, #16221:
URL: https://github.com/apache/grails-core/pull/16221
`@GrailsBeans(autoConfigurationName = "...")` sets only the *simple* name of
the generated sibling; the package is always the plugin descriptor's own. Its
documented purpose, though, is preserving the identity of an auto-configuration
class a descriptor is being converted from:
> Set this when converting an existing public `@AutoConfiguration` class
whose name doesn't follow that convention and **whose class identity must be
preserved** (e.g. for `exclude =` references, `before=`/`after=` ordering from
other modules, or tests that import it by name).
Every one of those references names the *qualified* name. And a plugin
descriptor conventionally sits in the package its implementation classes sit
**beneath** rather than alongside them, so the class being converted is usually
in a different package — which means identity changed anyway and the attribute
could not prevent it.
This came up converting `asset-pipeline`, whose descriptor is
`asset.pipeline.AssetPipelineGrailsPlugin` while its hand-written
auto-configuration is `asset.pipeline.grails.AssetPipelineAutoConfiguration`.
There is no value of `autoConfigurationName` that keeps that name today.
## The change
`siblingSimpleName()` becomes `siblingName()` and returns the qualified
name, so `createAutoConfigurationSibling` no longer prepends the descriptor's
package unconditionally. Validation moves from `SourceVersion.isIdentifier` to
`SourceVersion.isName`, which accepts a dotted sequence and rejects any part
that is a keyword.
```java
return name.indexOf('.') < 0 ? qualify(packageName, name) : name;
```
```groovy
package com.example
@GrailsBeans(autoConfigurationName =
'com.example.web.ExampleAutoConfiguration')
@AutoConfiguration
class ExampleGrailsPlugin extends Plugin { def beans = { /* ... */ } }
```
**Backward compatible.** A dot was rejected outright before this, so every
value that compiles today is a bare identifier and still resolves in the
plugin's package. The non-literal and blank error paths are untouched; only the
"is not a valid name" message extends to mention qualified names.
I deliberately did **not** restrict the package to one the plugin already
owns — that would block legitimate conversions such as a descriptor at
`com.foo.plugins.BarGrailsPlugin` replacing `com.foo.bar.BarAutoConfiguration`.
Instead the javadoc and the guide both warn that generating into a package the
plugin does not otherwise own splits that package across two jars, which
modular and native-image consumers pay for. Happy to enforce rather than
document it if you would prefer.
## Tests
Eight cases added to `GrailsBeansASTTransformationSpec`:
- a qualified name generates the sibling in the package it names, and
**not** in the plugin's
- a qualified name still carries the annotations that move to the sibling
(`@AutoConfiguration`, `@ConditionalOnWebApplication`), and they still leave
the plugin class
- a bare name still names the sibling in the plugin's own package
- five `@Unroll`ed rejections: keyword package part, leading dot, trailing
dot, empty part, space in a part
173 specs in `grails-beans-dsl`, 0 failures. Every module consuming the DSL
was also run: `grails-core`, `grails-i18n`, `grails-domain-class`,
`grails-sitemesh3`, and both `beans-dsl` test-example applications. `./gradlew
codeStyle` is clean.
## Docs
`GrailsBeans.java`'s javadoc no longer promises identity preservation it
could not deliver, and `hookingIntoRuntimeConfiguration.adoc` had an explicit
"(still generated in the plugin's own package)" that is replaced with the
qualified-name form and a worked example.
Targets `8.0.x`, where `@GrailsBeans` is new and unreleased. No ticket —
happy to file one if you want it for the change log.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]