matrei commented on code in PR #14953:
URL: https://github.com/apache/grails-core/pull/14953#discussion_r2291050312


##########
grails-micronaut/src/main/groovy/org/apache/grails/micronaut/GrailsMicronautGrailsPlugin.groovy:
##########
@@ -0,0 +1,74 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.grails.micronaut
+
+import grails.plugins.GrailsPlugin
+import grails.plugins.GrailsPluginManager
+import grails.plugins.Plugin
+import groovy.util.logging.Slf4j
+import io.micronaut.context.ConfigurableApplicationContext
+import io.micronaut.context.env.AbstractPropertySourceLoader
+import io.micronaut.context.env.Environment
+import io.micronaut.context.env.PropertySource
+
+@Slf4j
+class GrailsMicronautGrailsPlugin extends Plugin {
+
+    def grailsVersion = '7.0.0-SNAPSHOT > *'
+    def title = 'Grails Micronaut Plugin'
+
+    @Override
+    void doWithApplicationContext() {
+        String[] beanNames = 
applicationContext.getBeanNamesForType(GrailsPluginManager)
+        GrailsPluginManager pluginManagerFromContext = beanNames.length ?
+                applicationContext.getBean(GrailsPluginManager) :
+                null
+
+        if (!pluginManagerFromContext && !pluginManager) {
+            // No plugin managers to search for plugin configurations
+            return
+        }
+
+        if (!applicationContext.containsBean('micronautApplicationContext')) {
+            throw new IllegalStateException("A Micronaut Application Context 
should exist prior to the loading of the Grails Micronaut plugin.")
+        }
+
+        ConfigurableApplicationContext micronautContext = 
applicationContext.getBean('micronautApplicationContext', 
ConfigurableApplicationContext)
+        Environment micronautEnv = micronautContext.getEnvironment()
+
+        log.debug("Loading configurations from the plugins to the parent 
Micronaut context")

Review Comment:
   Single quotes?



##########
grails-doc/src/en/guide/conf/micronaut.adoc:
##########
@@ -0,0 +1,44 @@
+////
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+https://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+////
+
+=== Micronaut Integration
+
+Grails supports using the Micronaut framework via the `grails-micronaut` 
plugin. The `grails-micronaut` plugin uses the 
https://micronaut-projects.github.io/micronaut-spring/latest/guide/#springBootStarter[Micronaut
 Spring Boot Starter] so that both the Micronaut Application Context & Grails 
Application Context exist side by side.
+
+To enable Micronaut in your Grails application, two steps must be completed.  
First, the `grails-micronaut` plugin needs added to the build file.  Second, 
the property `micronautPlatformVersion` needs set to your desired version. Only 
Micronaut 4.9.2 or higher is supported for Grails.

Review Comment:
   Is a third step, to add `@EnableMicronaut` to the `Application` class, also 
necessary?



##########
grails-micronaut/src/main/groovy/org/apache/grails/micronaut/GrailsMicronautGrailsPlugin.groovy:
##########
@@ -0,0 +1,74 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.grails.micronaut
+
+import grails.plugins.GrailsPlugin
+import grails.plugins.GrailsPluginManager
+import grails.plugins.Plugin
+import groovy.util.logging.Slf4j
+import io.micronaut.context.ConfigurableApplicationContext
+import io.micronaut.context.env.AbstractPropertySourceLoader
+import io.micronaut.context.env.Environment
+import io.micronaut.context.env.PropertySource
+
+@Slf4j
+class GrailsMicronautGrailsPlugin extends Plugin {
+
+    def grailsVersion = '7.0.0-SNAPSHOT > *'
+    def title = 'Grails Micronaut Plugin'
+
+    @Override
+    void doWithApplicationContext() {
+        String[] beanNames = 
applicationContext.getBeanNamesForType(GrailsPluginManager)
+        GrailsPluginManager pluginManagerFromContext = beanNames.length ?
+                applicationContext.getBean(GrailsPluginManager) :
+                null
+
+        if (!pluginManagerFromContext && !pluginManager) {
+            // No plugin managers to search for plugin configurations
+            return
+        }
+
+        if (!applicationContext.containsBean('micronautApplicationContext')) {
+            throw new IllegalStateException("A Micronaut Application Context 
should exist prior to the loading of the Grails Micronaut plugin.")
+        }
+
+        ConfigurableApplicationContext micronautContext = 
applicationContext.getBean('micronautApplicationContext', 
ConfigurableApplicationContext)
+        Environment micronautEnv = micronautContext.getEnvironment()
+
+        log.debug("Loading configurations from the plugins to the parent 
Micronaut context")
+        final GrailsPlugin[] plugins = pluginManager.allPlugins
+        final GrailsPlugin[] pluginsFromContext = pluginManagerFromContext ? 
pluginManagerFromContext.allPlugins : new GrailsPlugin[]{}
+        Integer priority = AbstractPropertySourceLoader.DEFAULT_POSITION
+        [plugins, pluginsFromContext].each { GrailsPlugin[] pluginsToProcess ->
+            Arrays.stream(pluginsToProcess)
+                    .filter({ GrailsPlugin plugin -> plugin.propertySource != 
null })
+                    .forEach({ GrailsPlugin plugin ->
+                        if (log.isDebugEnabled()) {
+                            log.debug("Loading configurations from {} plugin 
to the parent Micronaut context", plugin.name)

Review Comment:
   Single quotes?



##########
grails-micronaut/src/main/groovy/org/apache/grails/micronaut/GrailsMicronautGrailsPlugin.groovy:
##########
@@ -0,0 +1,74 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.grails.micronaut
+
+import grails.plugins.GrailsPlugin
+import grails.plugins.GrailsPluginManager
+import grails.plugins.Plugin
+import groovy.util.logging.Slf4j
+import io.micronaut.context.ConfigurableApplicationContext
+import io.micronaut.context.env.AbstractPropertySourceLoader
+import io.micronaut.context.env.Environment
+import io.micronaut.context.env.PropertySource
+
+@Slf4j
+class GrailsMicronautGrailsPlugin extends Plugin {
+
+    def grailsVersion = '7.0.0-SNAPSHOT > *'
+    def title = 'Grails Micronaut Plugin'
+
+    @Override
+    void doWithApplicationContext() {
+        String[] beanNames = 
applicationContext.getBeanNamesForType(GrailsPluginManager)
+        GrailsPluginManager pluginManagerFromContext = beanNames.length ?
+                applicationContext.getBean(GrailsPluginManager) :
+                null
+
+        if (!pluginManagerFromContext && !pluginManager) {
+            // No plugin managers to search for plugin configurations
+            return
+        }
+
+        if (!applicationContext.containsBean('micronautApplicationContext')) {
+            throw new IllegalStateException("A Micronaut Application Context 
should exist prior to the loading of the Grails Micronaut plugin.")
+        }
+
+        ConfigurableApplicationContext micronautContext = 
applicationContext.getBean('micronautApplicationContext', 
ConfigurableApplicationContext)
+        Environment micronautEnv = micronautContext.getEnvironment()
+
+        log.debug("Loading configurations from the plugins to the parent 
Micronaut context")
+        final GrailsPlugin[] plugins = pluginManager.allPlugins
+        final GrailsPlugin[] pluginsFromContext = pluginManagerFromContext ? 
pluginManagerFromContext.allPlugins : new GrailsPlugin[]{}
+        Integer priority = AbstractPropertySourceLoader.DEFAULT_POSITION
+        [plugins, pluginsFromContext].each { GrailsPlugin[] pluginsToProcess ->
+            Arrays.stream(pluginsToProcess)
+                    .filter({ GrailsPlugin plugin -> plugin.propertySource != 
null })
+                    .forEach({ GrailsPlugin plugin ->
+                        if (log.isDebugEnabled()) {

Review Comment:
   Remove redundant logging guard?



##########
grails-micronaut/src/main/groovy/org/apache/grails/micronaut/GrailsMicronautGrailsPlugin.groovy:
##########
@@ -0,0 +1,74 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.grails.micronaut
+
+import grails.plugins.GrailsPlugin
+import grails.plugins.GrailsPluginManager
+import grails.plugins.Plugin
+import groovy.util.logging.Slf4j
+import io.micronaut.context.ConfigurableApplicationContext
+import io.micronaut.context.env.AbstractPropertySourceLoader
+import io.micronaut.context.env.Environment
+import io.micronaut.context.env.PropertySource
+
+@Slf4j
+class GrailsMicronautGrailsPlugin extends Plugin {
+
+    def grailsVersion = '7.0.0-SNAPSHOT > *'
+    def title = 'Grails Micronaut Plugin'
+
+    @Override
+    void doWithApplicationContext() {
+        String[] beanNames = 
applicationContext.getBeanNamesForType(GrailsPluginManager)
+        GrailsPluginManager pluginManagerFromContext = beanNames.length ?
+                applicationContext.getBean(GrailsPluginManager) :
+                null
+
+        if (!pluginManagerFromContext && !pluginManager) {
+            // No plugin managers to search for plugin configurations
+            return
+        }
+
+        if (!applicationContext.containsBean('micronautApplicationContext')) {
+            throw new IllegalStateException("A Micronaut Application Context 
should exist prior to the loading of the Grails Micronaut plugin.")
+        }
+
+        ConfigurableApplicationContext micronautContext = 
applicationContext.getBean('micronautApplicationContext', 
ConfigurableApplicationContext)
+        Environment micronautEnv = micronautContext.getEnvironment()
+
+        log.debug("Loading configurations from the plugins to the parent 
Micronaut context")
+        final GrailsPlugin[] plugins = pluginManager.allPlugins
+        final GrailsPlugin[] pluginsFromContext = pluginManagerFromContext ? 
pluginManagerFromContext.allPlugins : new GrailsPlugin[]{}

Review Comment:
   Do we need `final`?



##########
grails-micronaut/src/main/groovy/org/apache/grails/micronaut/GrailsMicronautGrailsPlugin.groovy:
##########
@@ -0,0 +1,74 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.grails.micronaut
+
+import grails.plugins.GrailsPlugin
+import grails.plugins.GrailsPluginManager
+import grails.plugins.Plugin
+import groovy.util.logging.Slf4j
+import io.micronaut.context.ConfigurableApplicationContext
+import io.micronaut.context.env.AbstractPropertySourceLoader
+import io.micronaut.context.env.Environment
+import io.micronaut.context.env.PropertySource
+
+@Slf4j
+class GrailsMicronautGrailsPlugin extends Plugin {
+
+    def grailsVersion = '7.0.0-SNAPSHOT > *'
+    def title = 'Grails Micronaut Plugin'
+
+    @Override
+    void doWithApplicationContext() {
+        String[] beanNames = 
applicationContext.getBeanNamesForType(GrailsPluginManager)
+        GrailsPluginManager pluginManagerFromContext = beanNames.length ?
+                applicationContext.getBean(GrailsPluginManager) :
+                null
+
+        if (!pluginManagerFromContext && !pluginManager) {
+            // No plugin managers to search for plugin configurations
+            return
+        }
+
+        if (!applicationContext.containsBean('micronautApplicationContext')) {
+            throw new IllegalStateException("A Micronaut Application Context 
should exist prior to the loading of the Grails Micronaut plugin.")
+        }
+
+        ConfigurableApplicationContext micronautContext = 
applicationContext.getBean('micronautApplicationContext', 
ConfigurableApplicationContext)
+        Environment micronautEnv = micronautContext.getEnvironment()
+
+        log.debug("Loading configurations from the plugins to the parent 
Micronaut context")
+        final GrailsPlugin[] plugins = pluginManager.allPlugins
+        final GrailsPlugin[] pluginsFromContext = pluginManagerFromContext ? 
pluginManagerFromContext.allPlugins : new GrailsPlugin[]{}
+        Integer priority = AbstractPropertySourceLoader.DEFAULT_POSITION

Review Comment:
   `int`?



##########
grails-doc/src/en/guide/upgrading/upgrading60x.adoc:
##########
@@ -256,14 +250,28 @@ jakartaeeMigration {
 6. `grails.beans.util.LazyBeanMap` -> `grails.beans.util.LazyMetaPropertyMap`
 7. `org.grails.plugins.databinding.DataBindingGrailsPlugin` -> 
`DataBindingConfiguration`
 
-===== 12.4 Micronaut in Grails is now supported via the Micronaut Spring Boot 
Starter
-- This change was made based on community input: 
https://github.com/orgs/grails/discussions/13517
-- The removal of Micronaut enabled simplification of the Grails codebase and 
the return of Live Reload via https://github.com/HotswapProjects/HotswapAgent
-- The Micronaut Parent Context is no longer in Grails by default.
-- The following dependencies are no longer included in Grails or grails-bom: 
io.micronaut:micronaut-\*, io.micronaut.cache:micronaut-cache-core, 
io.micronaut.groovy:micronaut-runtime-groovy and 
io.micronaut.spring:micronaut-spring-*
-- Micronaut can be added via the Micronaut Spring Boot Starter: 
https://micronaut-projects.github.io/micronaut-spring/latest/guide/#springBootStarter.
-- Using Micronaut Parent Context: 
https://micronaut-projects.github.io/micronaut-spring/latest/guide/#springParentContext
-- Using a Bean Post Processor: 
https://micronaut-projects.github.io/micronaut-spring/latest/guide/#beanPostProcessor
+===== 12.4 Micronaut in Grails is now supported via the plugin 
`grails-micronaut`
+In Grails 4 to Grails 6, Micronaut was integrated by making Micronaut the 
parent context of the Grails application. As of Grails 7, Micronaut is set up 
via the 
https://micronaut-projects.github.io/micronaut-spring/latest/guide/#springBootStarter[micronaut-spring-starter]
 using the `grails-micronaut` plugin. Discussion around this change can be 
found https://github.com/apache/grails-core/discussions/13517[here].
+
+To enable Micronaut in your Grails application, two steps must be completed.  
First, the `grails-micronaut` plugin needs added to the build file.  Second, 
the property `micronautPlatformVersion` needs set to your desired version. Only 
Micronaut 4.9.2 or higher is supported for Grails.

Review Comment:
   Is a third step, to add `@EnableMicronaut` to the `Application` class, also 
necessary?



##########
grails-micronaut/src/main/groovy/org/apache/grails/micronaut/GrailsMicronautGrailsPlugin.groovy:
##########
@@ -0,0 +1,74 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.grails.micronaut
+
+import grails.plugins.GrailsPlugin
+import grails.plugins.GrailsPluginManager
+import grails.plugins.Plugin
+import groovy.util.logging.Slf4j
+import io.micronaut.context.ConfigurableApplicationContext
+import io.micronaut.context.env.AbstractPropertySourceLoader
+import io.micronaut.context.env.Environment
+import io.micronaut.context.env.PropertySource
+
+@Slf4j
+class GrailsMicronautGrailsPlugin extends Plugin {
+
+    def grailsVersion = '7.0.0-SNAPSHOT > *'
+    def title = 'Grails Micronaut Plugin'
+
+    @Override
+    void doWithApplicationContext() {
+        String[] beanNames = 
applicationContext.getBeanNamesForType(GrailsPluginManager)
+        GrailsPluginManager pluginManagerFromContext = beanNames.length ?
+                applicationContext.getBean(GrailsPluginManager) :
+                null
+
+        if (!pluginManagerFromContext && !pluginManager) {
+            // No plugin managers to search for plugin configurations
+            return
+        }
+
+        if (!applicationContext.containsBean('micronautApplicationContext')) {
+            throw new IllegalStateException("A Micronaut Application Context 
should exist prior to the loading of the Grails Micronaut plugin.")
+        }
+
+        ConfigurableApplicationContext micronautContext = 
applicationContext.getBean('micronautApplicationContext', 
ConfigurableApplicationContext)
+        Environment micronautEnv = micronautContext.getEnvironment()

Review Comment:
   Use Groovy property getter?



##########
grails-micronaut/src/main/groovy/org/apache/grails/micronaut/GrailsMicronautGrailsPlugin.groovy:
##########
@@ -0,0 +1,74 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.grails.micronaut
+
+import grails.plugins.GrailsPlugin
+import grails.plugins.GrailsPluginManager
+import grails.plugins.Plugin
+import groovy.util.logging.Slf4j
+import io.micronaut.context.ConfigurableApplicationContext
+import io.micronaut.context.env.AbstractPropertySourceLoader
+import io.micronaut.context.env.Environment
+import io.micronaut.context.env.PropertySource
+
+@Slf4j
+class GrailsMicronautGrailsPlugin extends Plugin {
+
+    def grailsVersion = '7.0.0-SNAPSHOT > *'
+    def title = 'Grails Micronaut Plugin'
+
+    @Override
+    void doWithApplicationContext() {
+        String[] beanNames = 
applicationContext.getBeanNamesForType(GrailsPluginManager)
+        GrailsPluginManager pluginManagerFromContext = beanNames.length ?
+                applicationContext.getBean(GrailsPluginManager) :
+                null
+
+        if (!pluginManagerFromContext && !pluginManager) {
+            // No plugin managers to search for plugin configurations
+            return
+        }
+
+        if (!applicationContext.containsBean('micronautApplicationContext')) {
+            throw new IllegalStateException("A Micronaut Application Context 
should exist prior to the loading of the Grails Micronaut plugin.")

Review Comment:
   Single quotes?



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