You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by ja...@apache.org on 2026/07/17 21:52:21 UTC

(grails-core) branch test/plugin-registry-contract created (now 44d5cfafe0)

This is an automated email from the ASF dual-hosted git repository.

jamesfredley pushed a change to branch test/plugin-registry-contract
in repository https://gitbox.apache.org/repos/asf/grails-core.git


      at 44d5cfafe0 Characterize plugin registry load order and lookup contract

This branch includes the following new commits:

     new 44d5cfafe0 Characterize plugin registry load order and lookup contract

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(grails-core) 01/01: Characterize plugin registry load order and lookup contract

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jamesfredley pushed a commit to branch test/plugin-registry-contract
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 44d5cfafe0d6e9d5cb6cf9e56e09011622aa94cb
Author: James Fredley <ja...@users.noreply.github.com>
AuthorDate: Fri Jul 17 17:51:44 2026 -0400

    Characterize plugin registry load order and lookup contract
    
    Assisted-by: opencode:gpt-5.6-sol
---
 ...tGrailsPluginManagerRegistryContractSpec.groovy | 152 +++++++++++++++++++++
 1 file changed, 152 insertions(+)

diff --git a/grails-core/src/test/groovy/grails/plugins/DefaultGrailsPluginManagerRegistryContractSpec.groovy b/grails-core/src/test/groovy/grails/plugins/DefaultGrailsPluginManagerRegistryContractSpec.groovy
new file mode 100644
index 0000000000..ca9a6443da
--- /dev/null
+++ b/grails-core/src/test/groovy/grails/plugins/DefaultGrailsPluginManagerRegistryContractSpec.groovy
@@ -0,0 +1,152 @@
+/*
+ *  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 grails.plugins
+
+import grails.core.DefaultGrailsApplication
+import org.apache.grails.core.plugins.DefaultPluginDiscovery
+import org.springframework.core.env.StandardEnvironment
+import spock.lang.Specification
+
+class DefaultGrailsPluginManagerRegistryContractSpec extends Specification {
+
+    void 'the discovery load order consumed by the manager is deterministic for a combined ordering graph'() {
+        given:
+        def pluginClasses = orderingPluginClasses()
+        def expectedLoadOrder = [
+                'registryOrderingRoot',
+                'registryOrderingBefore',
+                'registryOrderingRight',
+                'registryOrderingLeft',
+                'registryOrderingJoin',
+                'registryOrderingTail'
+        ]
+
+        when:
+        def loadOrders = (1..3).collect {
+            def discovery = createDiscovery(pluginClasses)
+            createManager(discovery)
+            discovery.getPluginsInLoadOrder()*.name
+        }
+
+        then:
+        loadOrders == [expectedLoadOrder, expectedLoadOrder, expectedLoadOrder]
+    }
+
+    void 'the loaded registry exposes a deterministic topological order for a combined ordering graph'() {
+        given:
+        def pluginClasses = orderingPluginClasses()
+        def expectedTopologicalOrder = [
+                'registryOrderingBefore',
+                'registryOrderingRoot',
+                'registryOrderingRight',
+                'registryOrderingLeft',
+                'registryOrderingJoin',
+                'registryOrderingTail'
+        ]
+
+        when:
+        def topologicalOrders = (1..3).collect {
+            def discovery = createDiscovery(pluginClasses)
+            createManager(discovery).getAllPlugins()*.name
+        }
+
+        then:
+        topologicalOrders == [expectedTopologicalOrder, expectedTopologicalOrder, expectedTopologicalOrder]
+    }
+
+    void 'the loaded registry de-duplicates plugins and resolves each plugin consistently'() {
+        given:
+        def pluginClasses = orderingPluginClasses()
+        def tailPluginClass = pluginClasses.find { it.name == 'RegistryOrderingTailGrailsPlugin' }
+        def discovery = createDiscovery(pluginClasses + tailPluginClass)
+        def manager = createManager(discovery)
+
+        when:
+        def tailPlugins = manager.getAllPlugins().findAll { it.name == 'registryOrderingTail' }
+        def expectedTailPlugin = tailPlugins.first()
+        def pluginByName = manager.getGrailsPlugin('registryOrderingTail')
+        def pluginByClassName = manager.getGrailsPluginForClassName(tailPluginClass.name)
+        def pluginByVersion = manager.getGrailsPlugin('registryOrderingTail', '1.0.0')
+
+        then:
+        tailPlugins.size() == 1
+        expectedTailPlugin != null
+        manager.hasGrailsPlugin('registryOrderingTail')
+        pluginByName != null
+        pluginByClassName != null
+        pluginByVersion != null
+        pluginByName.is(expectedTailPlugin)
+        pluginByClassName.is(expectedTailPlugin)
+        pluginByVersion.is(expectedTailPlugin)
+    }
+
+    private static DefaultPluginDiscovery createDiscovery(List<Class<?>> pluginClasses) {
+        def discovery = new DefaultPluginDiscovery(pluginClasses as Class<?>[])
+        discovery.loadPluginsFromClasspath = false
+        discovery.init(new StandardEnvironment())
+        discovery
+    }
+
+    private static DefaultGrailsPluginManager createManager(DefaultPluginDiscovery discovery) {
+        def manager = new DefaultGrailsPluginManager(new DefaultGrailsApplication(), discovery)
+        manager.loadPlugins()
+        manager
+    }
+
+    private static List<Class<?>> orderingPluginClasses() {
+        def classLoader = new GroovyClassLoader()
+        [
+                classLoader.parseClass('''
+class RegistryOrderingTailGrailsPlugin {
+    def version = '1.0.0'
+    def loadAfter = ['registryOrderingJoin']
+}
+'''),
+                classLoader.parseClass('''
+class RegistryOrderingJoinGrailsPlugin {
+    def version = '1.0.0'
+    def loadAfter = ['registryOrderingLeft', 'registryOrderingRight']
+}
+'''),
+                classLoader.parseClass('''
+class RegistryOrderingRightGrailsPlugin {
+    def version = '1.0.0'
+    def loadAfter = ['registryOrderingRoot']
+}
+'''),
+                classLoader.parseClass('''
+class RegistryOrderingLeftGrailsPlugin {
+    def version = '1.0.0'
+    def loadAfter = ['registryOrderingRoot']
+}
+'''),
+                classLoader.parseClass('''
+class RegistryOrderingRootGrailsPlugin {
+    def version = '1.0.0'
+}
+'''),
+                classLoader.parseClass('''
+class RegistryOrderingBeforeGrailsPlugin {
+    def version = '1.0.0'
+    def loadBefore = ['registryOrderingRoot']
+}
+''')
+        ]
+    }
+}