codeconsole commented on PR #16019:
URL: https://github.com/apache/grails-core/pull/16019#issuecomment-5094650830

   The `grails-cache` conversion (311fb9a959), same pattern. This is the first 
one where the generated sibling is deliberately **not** given the deleted 
class's name: `CacheGrailsPlugin` derives `CacheAutoConfiguration`, and pinning 
the old `GrailsCacheAutoConfiguration` with `@GrailsBeans(autoConfigurationName 
= ...)` would have baked in a naming inconsistency the rest of the framework 
does not share — `UrlMappingsAutoConfiguration`, `Sitemesh3AutoConfiguration`, 
`MailAutoConfiguration`, `I18nAutoConfiguration` and 
`ControllersAutoConfiguration` all already follow the `*GrailsPlugin` -> 
`*AutoConfiguration` convention, and the redundant `Grails` prefix is the 
outlier. That attribute is for a name that genuinely cannot move, not for 
preserving legacy naming. Imports and comments are trimmed here; each linked 
filename is the verbatim, commit-pinned source.
   
   Before, 
[`GrailsCacheAutoConfiguration.groovy`](https://github.com/codeconsole/grails-core/blob/100b9dbf77d65a32cef2f1698113052fa9f59ac7/grails-cache/src/main/groovy/grails/plugin/cache/GrailsCacheAutoConfiguration.groovy#L45-L69)
 (since deleted):
   
   ```groovy
   @AutoConfiguration
   @ConditionalOnBooleanProperty(name = 'grails.cache.enabled', matchIfMissing 
= true)
   @ConditionalOnBean(CachePluginConfiguration)
   @CompileStatic
   class GrailsCacheAutoConfiguration {
   
       @Value('${grails.cache.cacheManager:}')
       String cacheManagerType
   
       @Bean
       @ConditionalOnMissingBean(name = 'customCacheKeyGenerator')
       CustomCacheKeyGenerator customCacheKeyGenerator() {
           new CustomCacheKeyGenerator()
       }
   
       @Bean
       @ConditionalOnMissingBean(name = 'grailsCacheManager')
       GrailsCacheManager grailsCacheManager(CachePluginConfiguration 
grailsCacheConfiguration) {
           if (cacheManagerType == 'GrailsConcurrentLinkedMapCacheManager') {
               return new GrailsConcurrentLinkedMapCacheManager(configuration: 
grailsCacheConfiguration)
           }
           new GrailsConcurrentMapCacheManager(configuration: 
grailsCacheConfiguration)
       }
   
   }
   ```
   
   After — 
[`CacheGrailsPlugin.groovy`](https://github.com/codeconsole/grails-core/blob/311fb9a959e646469432ba8983ee02319fffbd6c/grails-cache/src/main/groovy/grails/plugin/cache/CacheGrailsPlugin.groovy#L50-L87)'s
 class declaration and `beans` block (the plugin's metadata properties between 
them are elided below, unchanged by the conversion; `beanRegistrar()` and 
`doWithApplicationContext()` further down the file are pre-existing plugin 
logic, untouched):
   
   ```groovy
   @Slf4j
   @CompileStatic
   @GrailsBeans
   @AutoConfiguration
   @ConditionalOnBooleanProperty(name = 'grails.cache.enabled', matchIfMissing 
= true)
   @ConditionalOnBean(CachePluginConfiguration)
   class CacheGrailsPlugin extends Plugin {
   
       // ... pre-existing plugin metadata properties and isCachingEnabled(), 
unchanged ...
   
       def beans = {
           field('cacheManagerType', String).value('grails.cache.cacheManager', 
'')
   
           bean('customCacheKeyGenerator', 
CustomCacheKeyGenerator).conditionalOnMissingBeanName() {
               new CustomCacheKeyGenerator()
           }
   
           bean('grailsCacheManager', 
GrailsCacheManager).conditionalOnMissingBeanName() { CachePluginConfiguration 
grailsCacheConfiguration ->
               if (cacheManagerType == 'GrailsConcurrentLinkedMapCacheManager') 
{
                   return new 
GrailsConcurrentLinkedMapCacheManager(configuration: grailsCacheConfiguration)
               }
               new GrailsConcurrentMapCacheManager(configuration: 
grailsCacheConfiguration)
           }
       }
   ```
   
   This conversion sits next to a `beanRegistrar()` that the two 
auto-configured beans are gated on: 
`@ConditionalOnBean(CachePluginConfiguration)` refers to the 
`grailsCacheConfiguration` definition the registrar contributes, and the 
registrar runs before auto-configuration conditions are evaluated, so the pair 
backs off entirely when the plugin is inactive — the jar on the classpath but 
the plugin excluded. The deleted class's design documentation now lives on the 
plugin, next to the registrar it describes. `@AutoConfiguration`, 
`@ConditionalOnBooleanProperty` and `@ConditionalOnBean` all move onto the 
sibling at compile time, and `@CompileStatic` is copied onto it so the 
generated configuration keeps the deleted class's static compilation.
   
   The rename is contained: the only references were the module's own tests, so 
`GrailsCacheAutoConfigurationSpec` becomes `CacheAutoConfigurationSpec` and 
`CacheGrailsPluginSpec`'s description is updated. It remains a public FQCN 
change for anyone excluding the auto-configuration through 
`@EnableAutoConfiguration(exclude = ...)` or `spring.autoconfigure.exclude`, 
which a major release is the right place to take. The full `grails-cache` suite 
passes unmodified against the generated class, including 
`CacheAutoConfigurationSpec`'s direct 
`context.register(CacheAutoConfiguration)`.
   


-- 
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]

Reply via email to