diff --git a/grace-plugin-fields/build.gradle b/grace-plugin-fields/build.gradle index 5164dfbb2d..c7eff9b2c0 100644 --- a/grace-plugin-fields/build.gradle +++ b/grace-plugin-fields/build.gradle @@ -1,8 +1,9 @@ dependencies { + api project(":grace-plugin-validation") api project(":grace-scaffolding-core") api project(":grace-web-databinding") api project(":grace-web-gsp") - api project(":grace-plugin-validation") + api project(":grace-web-taglib") implementation libs.grace.datastore.core implementation libs.grace.datastore.gorm implementation libs.grace.datastore.gorm.support diff --git a/grace-web-common/build.gradle b/grace-web-common/build.gradle index 2494c660b2..89c00d3641 100644 --- a/grace-web-common/build.gradle +++ b/grace-web-common/build.gradle @@ -5,8 +5,6 @@ dependencies { api project(":grace-encoder") api project(":grace-util") - api project(":grace-gsp") - compileOnlyApi libs.jakarta.servlet api libs.groovy.templates api libs.spring.contextSupport diff --git a/grace-web-common/src/main/groovy/org/grails/web/servlet/DefaultGrailsApplicationAttributes.java b/grace-web-common/src/main/groovy/org/grails/web/servlet/DefaultGrailsApplicationAttributes.java index 3baf9375a6..0e21722173 100644 --- a/grace-web-common/src/main/groovy/org/grails/web/servlet/DefaultGrailsApplicationAttributes.java +++ b/grace-web-common/src/main/groovy/org/grails/web/servlet/DefaultGrailsApplicationAttributes.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2023 the original author or authors. + * Copyright 2004-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,6 @@ import grails.web.mvc.FlashScope; import grails.web.pages.GroovyPagesUriService; -import org.grails.gsp.ResourceAwareTemplateEngine; import org.grails.web.pages.DefaultGroovyPagesUriService; import org.grails.web.util.GrailsApplicationAttributes; @@ -64,9 +63,6 @@ public class DefaultGrailsApplicationAttributes implements GrailsApplicationAttr private ApplicationContext appContext; - // Beans used very often - private ResourceAwareTemplateEngine pagesTemplateEngine; - private GrailsApplication grailsApplication; private GroovyPagesUriService groovyPagesUriService; @@ -85,6 +81,7 @@ public DefaultGrailsApplicationAttributes(ServletContext context) { } } + @Override public ApplicationContext getApplicationContext() { return this.appContext; } @@ -115,6 +112,7 @@ private T fetchBeanFromAppCtx(String name) { } } + @Override public String getPluginContextPath(HttpServletRequest request) { GroovyObject controller = getController(request); if (controller != null && getPluginManager() != null) { @@ -125,10 +123,12 @@ public String getPluginContextPath(HttpServletRequest request) { return ""; } + @Override public GroovyObject getController(ServletRequest request) { return (GroovyObject) request.getAttribute(CONTROLLER); } + @Override public String getControllerUri(ServletRequest request) { return "/" + getControllerName(request); } @@ -166,10 +166,12 @@ public String getApplicationUri(ServletRequest request) { return appUri; } + @Override public ServletContext getServletContext() { return this.context; } + @Override public FlashScope getFlashScope(ServletRequest request) { if (!(request instanceof HttpServletRequest)) { return null; @@ -196,35 +198,30 @@ public FlashScope getFlashScope(ServletRequest request) { return fs; } + @Override public String getTemplateUri(CharSequence templateName, ServletRequest request) { Assert.notNull(templateName, "Argument [template] cannot be null"); return getGroovyPagesUriService().getTemplateURI(getControllerName(request), templateName.toString()); } + @Override public String getViewUri(String viewName, HttpServletRequest request) { Assert.notNull(viewName, "Argument [view] cannot be null"); return getGroovyPagesUriService().getDeployedViewURI(getControllerName(request), viewName); } + @Override public String getControllerActionUri(ServletRequest request) { GroovyObject controller = getController(request); return (String) controller.getProperty("actionUri"); } + @Override public Errors getErrors(ServletRequest request) { return (Errors) request.getAttribute(ERRORS); } - public ResourceAwareTemplateEngine getPagesTemplateEngine() { - if (this.pagesTemplateEngine == null) { - this.pagesTemplateEngine = fetchBeanFromAppCtx(ResourceAwareTemplateEngine.BEAN_ID); - } - if (this.pagesTemplateEngine == null && logger.isWarnEnabled()) { - logger.warn("No bean named [" + ResourceAwareTemplateEngine.BEAN_ID + "] defined in Spring application context!"); - } - return this.pagesTemplateEngine; - } - + @Override public GrailsApplication getGrailsApplication() { if (this.grailsApplication == null) { this.grailsApplication = fetchBeanFromAppCtx(GrailsApplication.APPLICATION_ID); @@ -235,18 +232,22 @@ public GrailsApplication getGrailsApplication() { return this.grailsApplication; } + @Override public Writer getOut(HttpServletRequest request) { return (Writer) request.getAttribute(OUT); } + @Override public void setOut(HttpServletRequest request, Writer out2) { request.setAttribute(OUT, out2); } + @Override public String getNoSuffixViewURI(GroovyObject controller, String viewName) { return getGroovyPagesUriService().getNoSuffixViewURI(controller, viewName); } + @Override public String getTemplateURI(GroovyObject controller, String templateName) { return getGroovyPagesUriService().getTemplateURI(controller, templateName); } @@ -256,6 +257,7 @@ public String getTemplateURI(GroovyObject controller, String templateName, boole return getGroovyPagesUriService().getTemplateURI(controller, templateName, includeExtension); } + @Override public GroovyPagesUriService getGroovyPagesUriService() { if (this.groovyPagesUriService == null) { this.groovyPagesUriService = fetchBeanFromAppCtx(GroovyPagesUriService.BEAN_ID); @@ -266,6 +268,7 @@ public GroovyPagesUriService getGroovyPagesUriService() { return this.groovyPagesUriService; } + @Override public MessageSource getMessageSource() { if (this.messageSource == null) { this.messageSource = fetchBeanFromAppCtx("messageSource"); diff --git a/grace-web-common/src/main/groovy/org/grails/web/util/GrailsApplicationAttributes.java b/grace-web-common/src/main/groovy/org/grails/web/util/GrailsApplicationAttributes.java index 4c4631b59c..d117cf7b24 100644 --- a/grace-web-common/src/main/groovy/org/grails/web/util/GrailsApplicationAttributes.java +++ b/grace-web-common/src/main/groovy/org/grails/web/util/GrailsApplicationAttributes.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2023 the original author or authors. + * Copyright 2004-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,8 +29,6 @@ import grails.web.mvc.FlashScope; import grails.web.pages.GroovyPagesUriService; -import org.grails.gsp.ResourceAwareTemplateEngine; - /** * Defines the names of and methods to retrieve Grails specific request and servlet attributes. * @@ -200,11 +198,6 @@ public interface GrailsApplicationAttributes extends ApplicationAttributes { */ Errors getErrors(ServletRequest request); - /** - * @return Retrieves the shared GSP template engine - */ - ResourceAwareTemplateEngine getPagesTemplateEngine(); - /** * Holds the current response write for the request * @return The held response writer diff --git a/grace-web-gsp/build.gradle b/grace-web-gsp/build.gradle index 120e9c2ed4..129ca1f837 100644 --- a/grace-web-gsp/build.gradle +++ b/grace-web-gsp/build.gradle @@ -3,7 +3,6 @@ dependencies { compileOnlyApi libs.jakarta.servlet api project(":grace-gsp") api project(":grace-web-common") - api project(":grace-web-taglib") api project(":grace-web-sitemesh") testImplementation libs.jakarta.servlet diff --git a/grace-web-mvc/build.gradle b/grace-web-mvc/build.gradle index f3ebba7421..60a4cf1eff 100644 --- a/grace-web-mvc/build.gradle +++ b/grace-web-mvc/build.gradle @@ -1,8 +1,9 @@ dependencies { api project(":grace-web-common") + api project(":grace-gsp") + api project(":grace-web-sitemesh") api project(":grace-web-url-mappings") - api project(":grace-web-sitemesh") compileOnlyApi libs.jakarta.servlet testImplementation libs.jakarta.servlet diff --git a/grace-web-common/src/main/groovy/org/grails/web/errors/ErrorsViewStackTracePrinter.groovy b/grace-web-mvc/src/main/groovy/org/grails/web/errors/ErrorsViewStackTracePrinter.groovy similarity index 98% rename from grace-web-common/src/main/groovy/org/grails/web/errors/ErrorsViewStackTracePrinter.groovy rename to grace-web-mvc/src/main/groovy/org/grails/web/errors/ErrorsViewStackTracePrinter.groovy index 994be0e073..1ca7cd7498 100644 --- a/grace-web-common/src/main/groovy/org/grails/web/errors/ErrorsViewStackTracePrinter.groovy +++ b/grace-web-mvc/src/main/groovy/org/grails/web/errors/ErrorsViewStackTracePrinter.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2011-2022 the original author or authors. + * Copyright 2011-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/grace-web-mvc/src/main/groovy/org/grails/web/errors/GrailsExceptionResolver.java b/grace-web-mvc/src/main/groovy/org/grails/web/errors/GrailsExceptionResolver.java index 50f6aab164..614d036a02 100644 --- a/grace-web-mvc/src/main/groovy/org/grails/web/errors/GrailsExceptionResolver.java +++ b/grace-web-mvc/src/main/groovy/org/grails/web/errors/GrailsExceptionResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2023 the original author or authors. + * Copyright 2004-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -107,10 +107,12 @@ public String getRequestLogMessage(HttpServletRequest request) { return getRequestLogMessage("Exception", request, null); } + @Override public void setServletContext(ServletContext servletContext) { this.servletContext = servletContext; } + @Override public void setGrailsApplication(GrailsApplication grailsApplication) { this.grailsApplication = grailsApplication; createStackFilterer(); diff --git a/grace-web-common/src/main/groovy/org/grails/web/errors/GrailsWrappedRuntimeException.java b/grace-web-mvc/src/main/groovy/org/grails/web/errors/GrailsWrappedRuntimeException.java similarity index 95% rename from grace-web-common/src/main/groovy/org/grails/web/errors/GrailsWrappedRuntimeException.java rename to grace-web-mvc/src/main/groovy/org/grails/web/errors/GrailsWrappedRuntimeException.java index 4f293c37a8..5d4454de68 100644 --- a/grace-web-common/src/main/groovy/org/grails/web/errors/GrailsWrappedRuntimeException.java +++ b/grace-web-mvc/src/main/groovy/org/grails/web/errors/GrailsWrappedRuntimeException.java @@ -33,6 +33,7 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; +import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; import grails.artefact.ArtefactTypes; @@ -193,15 +194,17 @@ else if (application.isArtefactOfType(ArtefactTypes.SERVICE, this.className)) { } else { url = this.gspFile; - GrailsApplicationAttributes attrs = null; try { - attrs = grailsApplicationAttributesConstructor.newInstance(servletContext); + WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); + if (webApplicationContext != null) { + ResourceAwareTemplateEngine engine = + webApplicationContext.getBean(ResourceAwareTemplateEngine.BEAN_ID, ResourceAwareTemplateEngine.class); + this.lineNumber = engine.mapStackLineNumber(url, this.lineNumber); + } } catch (Exception e) { ReflectionUtils.rethrowRuntimeException(e); } - ResourceAwareTemplateEngine engine = attrs.getPagesTemplateEngine(); - this.lineNumber = engine.mapStackLineNumber(url, this.lineNumber); } fileLocation = "grails-app" + urlPrefix + this.fileName; } diff --git a/grace-web-taglib/build.gradle b/grace-web-taglib/build.gradle index e7ff5768bc..f64d38a947 100644 --- a/grace-web-taglib/build.gradle +++ b/grace-web-taglib/build.gradle @@ -1,8 +1,8 @@ dependencies { compileOnly libs.jakarta.annotation.api compileOnlyApi libs.jakarta.servlet - api project(":grace-web-common") api project(":grace-taglib") + api project(":grace-web-common") testImplementation libs.jakarta.servlet testImplementation libs.spring.test diff --git a/grace-web/build.gradle b/grace-web/build.gradle index fb98ddd717..e10a8b37a6 100644 --- a/grace-web/build.gradle +++ b/grace-web/build.gradle @@ -3,20 +3,12 @@ dependencies { api project(":grace-plugin-api") api project(":grace-web-common") api project(":grace-web-databinding") + api project(":grace-web-gsp") api project(":grace-web-mvc") + api project(":grace-web-sitemesh") + api project(":grace-web-taglib") api project(":grace-web-url-mappings") - api project(":grace-web-gsp"), { - exclude group:'org.graceframework', module:'grace-core' - exclude group:'org.graceframework', module:'grace-encoder' - exclude group:'org.graceframework', module:'grace-web-common' - } - api project(":grace-web-sitemesh"), { - exclude group:'org.graceframework', module:'grace-core' - exclude group:'org.graceframework', module:'grace-encoder' - exclude group:'org.graceframework', module:'grace-web-common' - } - compileOnlyApi libs.jakarta.servlet compileOnly libs.grace.datastore.gorm.support