From 074fca8178d9b7cb068042064bd9b3902cdfa102 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Thu, 5 Sep 2024 22:37:52 -0700 Subject: [PATCH] Decouple grails-plugin-controllers from Sitemesh --- grails-plugin-controllers/build.gradle | 1 - .../controller/support/ResponseRenderer.groovy | 10 +++++----- .../web/controllers/ControllersGrailsPlugin.groovy | 5 +++++ .../web/servlet/mvc/RenderDynamicMethodTests.groovy | 4 ++-- grails-web-mvc/build.gradle | 6 +----- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/grails-plugin-controllers/build.gradle b/grails-plugin-controllers/build.gradle index c4be5c868e8..16cef8bcbcf 100644 --- a/grails-plugin-controllers/build.gradle +++ b/grails-plugin-controllers/build.gradle @@ -6,7 +6,6 @@ dependencies { project(':grails-plugin-domain-class') api("org.springframework.boot:spring-boot-autoconfigure:$springBootVersion") - api "org.grails:grails-web-sitemesh:$gspVersion" runtimeOnly project(':grails-plugin-i18n') testRuntimeOnly "jline:jline:$jlineVersion" diff --git a/grails-plugin-controllers/src/main/groovy/grails/artefact/controller/support/ResponseRenderer.groovy b/grails-plugin-controllers/src/main/groovy/grails/artefact/controller/support/ResponseRenderer.groovy index 0ed91ed0811..9c30cb18b80 100644 --- a/grails-plugin-controllers/src/main/groovy/grails/artefact/controller/support/ResponseRenderer.groovy +++ b/grails-plugin-controllers/src/main/groovy/grails/artefact/controller/support/ResponseRenderer.groovy @@ -37,7 +37,7 @@ import org.grails.web.servlet.mvc.GrailsWebRequest import org.grails.web.servlet.mvc.exceptions.ControllerExecutionException import org.grails.web.servlet.view.CompositeViewResolver import org.grails.web.servlet.view.GroovyPageView -import org.grails.web.sitemesh.GroovyPageLayoutFinder +import org.grails.plugins.web.controllers.ControllersGrailsPlugin import org.grails.web.util.GrailsApplicationAttributes import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Qualifier @@ -296,7 +296,7 @@ trait ResponseRenderer extends WebAttributes { } - boolean renderWithLayout = (explicitSiteMeshLayout || webRequest.getCurrentRequest().getAttribute(GroovyPageLayoutFinder.LAYOUT_ATTRIBUTE)) + boolean renderWithLayout = (explicitSiteMeshLayout || webRequest.getCurrentRequest().getAttribute(ControllersGrailsPlugin.LAYOUT_ATTRIBUTE)) // if automatic decoration occurred unwrap, since this is a partial if (renderWithLayout) { @@ -533,13 +533,13 @@ trait ResponseRenderer extends WebAttributes { } private void applySiteMeshLayout(HttpServletRequest request, boolean renderView, String explicitSiteMeshLayout) { - if(explicitSiteMeshLayout == null && request.getAttribute(GroovyPageLayoutFinder.LAYOUT_ATTRIBUTE) != null) { + if(explicitSiteMeshLayout == null && request.getAttribute(ControllersGrailsPlugin.LAYOUT_ATTRIBUTE) != null) { // layout has been set already return } - String siteMeshLayout = explicitSiteMeshLayout != null ? explicitSiteMeshLayout : (renderView ? null : GroovyPageLayoutFinder.NONE_LAYOUT) + String siteMeshLayout = explicitSiteMeshLayout != null ? explicitSiteMeshLayout : (renderView ? null : ControllersGrailsPlugin.NONE_LAYOUT) if(siteMeshLayout != null) { - request.setAttribute GroovyPageLayoutFinder.LAYOUT_ATTRIBUTE, siteMeshLayout + request.setAttribute ControllersGrailsPlugin.LAYOUT_ATTRIBUTE, siteMeshLayout } } diff --git a/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersGrailsPlugin.groovy b/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersGrailsPlugin.groovy index e4ab1875d38..5bd61c27a9b 100644 --- a/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersGrailsPlugin.groovy +++ b/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersGrailsPlugin.groovy @@ -63,6 +63,11 @@ class ControllersGrailsPlugin extends Plugin { def observe = ['domainClass'] def dependsOn = [core: version, i18n: version, urlMappings: version] + // Although they are specific to Sitemesh, these properties need + // a new home that is not coupled to any sitemesh dependency + static final String LAYOUT_ATTRIBUTE = "org.grails.layout.name"; + static final String NONE_LAYOUT = "_none_"; + @Override Closure doWithSpring(){ { -> def application = grailsApplication diff --git a/grails-test-suite-uber/src/test/groovy/org/grails/web/servlet/mvc/RenderDynamicMethodTests.groovy b/grails-test-suite-uber/src/test/groovy/org/grails/web/servlet/mvc/RenderDynamicMethodTests.groovy index d315b4c92e2..f3c8216ae3b 100644 --- a/grails-test-suite-uber/src/test/groovy/org/grails/web/servlet/mvc/RenderDynamicMethodTests.groovy +++ b/grails-test-suite-uber/src/test/groovy/org/grails/web/servlet/mvc/RenderDynamicMethodTests.groovy @@ -1,7 +1,7 @@ package org.grails.web.servlet.mvc +import org.grails.plugins.web.controllers.ControllersGrailsPlugin import grails.testing.web.controllers.ControllerUnitTest -import org.grails.web.sitemesh.GroovyPageLayoutFinder import spock.lang.Specification import grails.artefact.Artefact import org.grails.buffer.FastStringWriter @@ -15,7 +15,7 @@ class RenderDynamicMethodTests extends Specification implements ControllerUnitTe then: response.contentType == response.contentType response.contentAsString == response.contentAsString - request.getAttribute(GroovyPageLayoutFinder.LAYOUT_ATTRIBUTE) == "bar" + request.getAttribute(ControllersGrailsPlugin.LAYOUT_ATTRIBUTE) == "bar" } void testRenderView() { diff --git a/grails-web-mvc/build.gradle b/grails-web-mvc/build.gradle index 7fa0ce3f366..916a313d905 100644 --- a/grails-web-mvc/build.gradle +++ b/grails-web-mvc/build.gradle @@ -1,8 +1,4 @@ dependencies { api project(":grails-web-common"), - project(":grails-web-url-mappings") - - compileOnly "org.grails:grails-web-sitemesh:$gspVersion", { - exclude group:'org.grails', module:'grails-web-common' - } + project(":grails-web-url-mappings") }