Skip to content

Commit 4143506

Browse files
authored
Merge pull request #1242 from rainboyan
* pr/1242: Cleanup dependencies Relocate `ErrorsViewStackTracePrinter` `GrailsWrappedRuntimeException` from `grace-web-common` to `grace-web-mvc` Remove `getPagesTemplateEngine()` of `GrailsApplicationAttributes` Update dependencies - `grace-web-gsp` no longer depends on `grace-web-taglib` - `grace-web-common` no longer depends on `grace-gsp` - `grace-plugin-fields` should depends on `grace-web-taglib` Closes gh-1242
2 parents e28ab80 + a62c8ce commit 4143506

File tree

11 files changed

+38
-46
lines changed

11 files changed

+38
-46
lines changed

grace-plugin-fields/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
dependencies {
2+
api project(":grace-plugin-validation")
23
api project(":grace-scaffolding-core")
34
api project(":grace-web-databinding")
45
api project(":grace-web-gsp")
5-
api project(":grace-plugin-validation")
6+
api project(":grace-web-taglib")
67
implementation libs.grace.datastore.core
78
implementation libs.grace.datastore.gorm
89
implementation libs.grace.datastore.gorm.support

grace-web-common/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ dependencies {
55
api project(":grace-encoder")
66
api project(":grace-util")
77

8-
api project(":grace-gsp")
9-
108
compileOnlyApi libs.jakarta.servlet
119
api libs.groovy.templates
1210
api libs.spring.contextSupport

grace-web-common/src/main/groovy/org/grails/web/servlet/DefaultGrailsApplicationAttributes.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2004-2023 the original author or authors.
2+
* Copyright 2004-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,7 +39,6 @@
3939
import grails.web.mvc.FlashScope;
4040
import grails.web.pages.GroovyPagesUriService;
4141

42-
import org.grails.gsp.ResourceAwareTemplateEngine;
4342
import org.grails.web.pages.DefaultGroovyPagesUriService;
4443
import org.grails.web.util.GrailsApplicationAttributes;
4544

@@ -64,9 +63,6 @@ public class DefaultGrailsApplicationAttributes implements GrailsApplicationAttr
6463

6564
private ApplicationContext appContext;
6665

67-
// Beans used very often
68-
private ResourceAwareTemplateEngine pagesTemplateEngine;
69-
7066
private GrailsApplication grailsApplication;
7167

7268
private GroovyPagesUriService groovyPagesUriService;
@@ -85,6 +81,7 @@ public DefaultGrailsApplicationAttributes(ServletContext context) {
8581
}
8682
}
8783

84+
@Override
8885
public ApplicationContext getApplicationContext() {
8986
return this.appContext;
9087
}
@@ -115,6 +112,7 @@ private <T> T fetchBeanFromAppCtx(String name) {
115112
}
116113
}
117114

115+
@Override
118116
public String getPluginContextPath(HttpServletRequest request) {
119117
GroovyObject controller = getController(request);
120118
if (controller != null && getPluginManager() != null) {
@@ -125,10 +123,12 @@ public String getPluginContextPath(HttpServletRequest request) {
125123
return "";
126124
}
127125

126+
@Override
128127
public GroovyObject getController(ServletRequest request) {
129128
return (GroovyObject) request.getAttribute(CONTROLLER);
130129
}
131130

131+
@Override
132132
public String getControllerUri(ServletRequest request) {
133133
return "/" + getControllerName(request);
134134
}
@@ -166,10 +166,12 @@ public String getApplicationUri(ServletRequest request) {
166166
return appUri;
167167
}
168168

169+
@Override
169170
public ServletContext getServletContext() {
170171
return this.context;
171172
}
172173

174+
@Override
173175
public FlashScope getFlashScope(ServletRequest request) {
174176
if (!(request instanceof HttpServletRequest)) {
175177
return null;
@@ -196,35 +198,30 @@ public FlashScope getFlashScope(ServletRequest request) {
196198
return fs;
197199
}
198200

201+
@Override
199202
public String getTemplateUri(CharSequence templateName, ServletRequest request) {
200203
Assert.notNull(templateName, "Argument [template] cannot be null");
201204
return getGroovyPagesUriService().getTemplateURI(getControllerName(request), templateName.toString());
202205
}
203206

207+
@Override
204208
public String getViewUri(String viewName, HttpServletRequest request) {
205209
Assert.notNull(viewName, "Argument [view] cannot be null");
206210
return getGroovyPagesUriService().getDeployedViewURI(getControllerName(request), viewName);
207211
}
208212

213+
@Override
209214
public String getControllerActionUri(ServletRequest request) {
210215
GroovyObject controller = getController(request);
211216
return (String) controller.getProperty("actionUri");
212217
}
213218

219+
@Override
214220
public Errors getErrors(ServletRequest request) {
215221
return (Errors) request.getAttribute(ERRORS);
216222
}
217223

218-
public ResourceAwareTemplateEngine getPagesTemplateEngine() {
219-
if (this.pagesTemplateEngine == null) {
220-
this.pagesTemplateEngine = fetchBeanFromAppCtx(ResourceAwareTemplateEngine.BEAN_ID);
221-
}
222-
if (this.pagesTemplateEngine == null && logger.isWarnEnabled()) {
223-
logger.warn("No bean named [" + ResourceAwareTemplateEngine.BEAN_ID + "] defined in Spring application context!");
224-
}
225-
return this.pagesTemplateEngine;
226-
}
227-
224+
@Override
228225
public GrailsApplication getGrailsApplication() {
229226
if (this.grailsApplication == null) {
230227
this.grailsApplication = fetchBeanFromAppCtx(GrailsApplication.APPLICATION_ID);
@@ -235,18 +232,22 @@ public GrailsApplication getGrailsApplication() {
235232
return this.grailsApplication;
236233
}
237234

235+
@Override
238236
public Writer getOut(HttpServletRequest request) {
239237
return (Writer) request.getAttribute(OUT);
240238
}
241239

240+
@Override
242241
public void setOut(HttpServletRequest request, Writer out2) {
243242
request.setAttribute(OUT, out2);
244243
}
245244

245+
@Override
246246
public String getNoSuffixViewURI(GroovyObject controller, String viewName) {
247247
return getGroovyPagesUriService().getNoSuffixViewURI(controller, viewName);
248248
}
249249

250+
@Override
250251
public String getTemplateURI(GroovyObject controller, String templateName) {
251252
return getGroovyPagesUriService().getTemplateURI(controller, templateName);
252253
}
@@ -256,6 +257,7 @@ public String getTemplateURI(GroovyObject controller, String templateName, boole
256257
return getGroovyPagesUriService().getTemplateURI(controller, templateName, includeExtension);
257258
}
258259

260+
@Override
259261
public GroovyPagesUriService getGroovyPagesUriService() {
260262
if (this.groovyPagesUriService == null) {
261263
this.groovyPagesUriService = fetchBeanFromAppCtx(GroovyPagesUriService.BEAN_ID);
@@ -266,6 +268,7 @@ public GroovyPagesUriService getGroovyPagesUriService() {
266268
return this.groovyPagesUriService;
267269
}
268270

271+
@Override
269272
public MessageSource getMessageSource() {
270273
if (this.messageSource == null) {
271274
this.messageSource = fetchBeanFromAppCtx("messageSource");

grace-web-common/src/main/groovy/org/grails/web/util/GrailsApplicationAttributes.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2004-2023 the original author or authors.
2+
* Copyright 2004-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,8 +29,6 @@
2929
import grails.web.mvc.FlashScope;
3030
import grails.web.pages.GroovyPagesUriService;
3131

32-
import org.grails.gsp.ResourceAwareTemplateEngine;
33-
3432
/**
3533
* Defines the names of and methods to retrieve Grails specific request and servlet attributes.
3634
*
@@ -200,11 +198,6 @@ public interface GrailsApplicationAttributes extends ApplicationAttributes {
200198
*/
201199
Errors getErrors(ServletRequest request);
202200

203-
/**
204-
* @return Retrieves the shared GSP template engine
205-
*/
206-
ResourceAwareTemplateEngine getPagesTemplateEngine();
207-
208201
/**
209202
* Holds the current response write for the request
210203
* @return The held response writer

grace-web-gsp/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ dependencies {
33
compileOnlyApi libs.jakarta.servlet
44
api project(":grace-gsp")
55
api project(":grace-web-common")
6-
api project(":grace-web-taglib")
76
api project(":grace-web-sitemesh")
87

98
testImplementation libs.jakarta.servlet

grace-web-mvc/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
dependencies {
22
api project(":grace-web-common")
3+
api project(":grace-gsp")
4+
api project(":grace-web-sitemesh")
35
api project(":grace-web-url-mappings")
46

5-
api project(":grace-web-sitemesh")
67
compileOnlyApi libs.jakarta.servlet
78

89
testImplementation libs.jakarta.servlet

grace-web-common/src/main/groovy/org/grails/web/errors/ErrorsViewStackTracePrinter.groovy renamed to grace-web-mvc/src/main/groovy/org/grails/web/errors/ErrorsViewStackTracePrinter.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2022 the original author or authors.
2+
* Copyright 2011-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

grace-web-mvc/src/main/groovy/org/grails/web/errors/GrailsExceptionResolver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2004-2023 the original author or authors.
2+
* Copyright 2004-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -107,10 +107,12 @@ public String getRequestLogMessage(HttpServletRequest request) {
107107
return getRequestLogMessage("Exception", request, null);
108108
}
109109

110+
@Override
110111
public void setServletContext(ServletContext servletContext) {
111112
this.servletContext = servletContext;
112113
}
113114

115+
@Override
114116
public void setGrailsApplication(GrailsApplication grailsApplication) {
115117
this.grailsApplication = grailsApplication;
116118
createStackFilterer();

grace-web-common/src/main/groovy/org/grails/web/errors/GrailsWrappedRuntimeException.java renamed to grace-web-mvc/src/main/groovy/org/grails/web/errors/GrailsWrappedRuntimeException.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
3434
import org.springframework.util.ClassUtils;
3535
import org.springframework.util.ReflectionUtils;
36+
import org.springframework.web.context.WebApplicationContext;
3637
import org.springframework.web.context.support.WebApplicationContextUtils;
3738

3839
import grails.artefact.ArtefactTypes;
@@ -193,15 +194,17 @@ else if (application.isArtefactOfType(ArtefactTypes.SERVICE, this.className)) {
193194
}
194195
else {
195196
url = this.gspFile;
196-
GrailsApplicationAttributes attrs = null;
197197
try {
198-
attrs = grailsApplicationAttributesConstructor.newInstance(servletContext);
198+
WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
199+
if (webApplicationContext != null) {
200+
ResourceAwareTemplateEngine engine =
201+
webApplicationContext.getBean(ResourceAwareTemplateEngine.BEAN_ID, ResourceAwareTemplateEngine.class);
202+
this.lineNumber = engine.mapStackLineNumber(url, this.lineNumber);
203+
}
199204
}
200205
catch (Exception e) {
201206
ReflectionUtils.rethrowRuntimeException(e);
202207
}
203-
ResourceAwareTemplateEngine engine = attrs.getPagesTemplateEngine();
204-
this.lineNumber = engine.mapStackLineNumber(url, this.lineNumber);
205208
}
206209
fileLocation = "grails-app" + urlPrefix + this.fileName;
207210
}

grace-web-taglib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
dependencies {
22
compileOnly libs.jakarta.annotation.api
33
compileOnlyApi libs.jakarta.servlet
4-
api project(":grace-web-common")
54
api project(":grace-taglib")
5+
api project(":grace-web-common")
66

77
testImplementation libs.jakarta.servlet
88
testImplementation libs.spring.test

0 commit comments

Comments
 (0)