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

   The `UrlMappingsAutoConfiguration` conversion attempted in the review above 
is now in the branch (5e9e162e99), in the same shape as the `grails-i18n` one. 
Imports and comments are trimmed here for brevity; each block's linked filename 
is the verbatim, commit-pinned source.
   
   Before, 
[`UrlMappingsAutoConfiguration.java`](https://github.com/codeconsole/grails-core/blob/32ead2bbc405c7b2d6fec097e05e0a04a375e374/grails-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java#L20-L102)
 (since deleted):
   
   ```java
   @AutoConfiguration
   @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
   @EnableConfigurationProperties({ GrailsCorsConfiguration.class })
   public class UrlMappingsAutoConfiguration {
       @Value("${" + Settings.WEB_LINK_GENERATOR_USE_CACHE + ":#{null}}")
       private Boolean cacheUrls;
   
       @Value("${" + Settings.SERVER_URL + ":#{null}}")
       private String serverURL;
   
       @Bean(UrlConverter.BEAN_NAME)
       @ConditionalOnMissingBean(name = UrlConverter.BEAN_NAME)
       @ConditionalOnProperty(name = Settings.WEB_URL_CONVERTER, havingValue = 
"camelCase", matchIfMissing = true)
       public UrlConverter camelCaseUrlConverter() {
           return new CamelCaseUrlConverter();
       }
   
       @Bean(UrlConverter.BEAN_NAME)
       @ConditionalOnMissingBean(name = UrlConverter.BEAN_NAME)
       @ConditionalOnProperty(name = Settings.WEB_URL_CONVERTER, havingValue = 
"hyphenated")
       public UrlConverter hyphenatedUrlConverter() {
           return new HyphenatedUrlConverter();
       }
   
       @Bean
       @ConditionalOnMissingBean(name = LinkGenerator.BEAN_NAME)
       public LinkGenerator grailsLinkGenerator() {
           if (cacheUrls == null) {
               cacheUrls = !Environment.isDevelopmentMode() && 
!Environment.getCurrent().isReloadEnabled();
           }
           return cacheUrls ? new CachingLinkGenerator(serverURL) : new 
DefaultLinkGenerator(serverURL);
       }
   
       @Bean
       @ConditionalOnMissingBean(CorsFilter.class)
       @ConditionalOnProperty(name = Settings.SETTING_CORS_FILTER, havingValue 
= "true", matchIfMissing = true)
       public GrailsCorsFilter grailsCorsFilter(GrailsCorsConfiguration 
grailsCorsConfiguration) {
           return new GrailsCorsFilter(grailsCorsConfiguration);
       }
   
       @Bean
       @ConditionalOnMissingBean(UrlMappingsErrorPageCustomizer.class)
       public UrlMappingsErrorPageCustomizer 
urlMappingsErrorPageCustomizer(ObjectProvider<UrlMappings> urlMappingsProvider) 
{
           UrlMappingsErrorPageCustomizer errorPageCustomizer = new 
UrlMappingsErrorPageCustomizer();
           
errorPageCustomizer.setUrlMappings(urlMappingsProvider.getIfAvailable());
           return errorPageCustomizer;
       }
   
       @Bean
       @ConditionalOnMissingBean(UrlMappingsInfoHandlerAdapter.class)
       public UrlMappingsInfoHandlerAdapter urlMappingsInfoHandlerAdapter() {
           return new UrlMappingsInfoHandlerAdapter();
       }
   }
   ```
   
   After — 
[`UrlMappingsGrailsPlugin.groovy`](https://github.com/codeconsole/grails-core/blob/5e9e162e998da4ae9acaf04bb85fc6445c84c755/grails-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsGrailsPlugin.groovy#L19-L114)'s
 class declaration and `beans` block (the rest of the file — `beanRegistrar()`, 
`onChange()`, `DefaultUrlMappings` — is pre-existing plugin logic, untouched by 
the conversion):
   
   ```groovy
   @CompileStatic
   @GrailsBeans
   @AutoConfiguration
   @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
   @EnableConfigurationProperties([GrailsCorsConfiguration])
   class UrlMappingsGrailsPlugin extends Plugin {
   
       def watchedResources = 
['file:./grails-app/controllers/*UrlMappings.groovy']
   
       def version = GrailsUtil.getGrailsVersion()
       def dependsOn = [core: version]
       def loadAfter = ['controllers']
   
       def beans = {
           field('cacheUrls', 
Boolean).value(Settings.WEB_LINK_GENERATOR_USE_CACHE, '#{null}')
           field('serverURL', String).value(Settings.SERVER_URL, '#{null}')
   
           bean('grailsUrlConverter', 
UrlConverter).conditionalOnMissingBeanName().annotate(ConditionalOnProperty, 
name: 'grails.web.url.converter', havingValue: 'camelCase', matchIfMissing: 
true) {
               new CamelCaseUrlConverter()
           }
   
           bean('grailsUrlConverter', 
UrlConverter).conditionalOnMissingBeanName().annotate(ConditionalOnProperty, 
name: 'grails.web.url.converter', havingValue: 'hyphenated') {
               new HyphenatedUrlConverter()
           }
   
           bean('grailsLinkGenerator', 
LinkGenerator).conditionalOnMissingBeanName() {
               if (cacheUrls == null) {
                   cacheUrls = !grails.util.Environment.isDevelopmentMode() &&
                           
!grails.util.Environment.getCurrent().isReloadEnabled()
               }
               cacheUrls ? new CachingLinkGenerator(serverURL) : new 
DefaultLinkGenerator(serverURL)
           }
   
           
bean(GrailsCorsFilter).conditionalOnMissingBean(CorsFilter).annotate(ConditionalOnProperty,
 name: 'grails.cors.filter', havingValue: 'true', matchIfMissing: true) { 
GrailsCorsConfiguration grailsCorsConfiguration ->
               new GrailsCorsFilter(grailsCorsConfiguration)
           }
   
           bean(UrlMappingsErrorPageCustomizer).conditionalOnMissingBean() { 
ObjectProvider<UrlMappings> urlMappingsProvider ->
               def errorPageCustomizer = new UrlMappingsErrorPageCustomizer()
               
errorPageCustomizer.setUrlMappings(urlMappingsProvider.getIfAvailable())
               errorPageCustomizer
           }
   
           bean(UrlMappingsInfoHandlerAdapter).conditionalOnMissingBean() {
               new UrlMappingsInfoHandlerAdapter()
           }
       }
   ```
   
   The two mutually exclusive `grailsUrlConverter` variants share one Spring 
bean name, selected by `@ConditionalOnProperty` — the pattern the compile error 
used to reject. The generated sibling regains the exact 
`UrlMappingsAutoConfiguration` class identity via the `*GrailsPlugin` naming 
convention, so the module's hand-maintained `AutoConfiguration.imports` entry 
is untouched, and the `ObjectProvider<UrlMappings>` parameter's generic 
signature survives into the bytecode (javap-verified). One fidelity note: the 
`@ConditionalOnProperty` `name:` attributes are literals mirroring 
`Settings.WEB_URL_CONVERTER`/`Settings.SETTING_CORS_FILTER` — an annotation 
attribute value must be an inline constant — while the two 
`field(...).value(...)` injections keep their bare `Settings` constant keys, 
which the DSL folds at transform time. The url-converter selection and 
link-generator configuration, previously untested, now have spec coverage 
(03209d1209).
   


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