Skip to content

Commit 937edd7

Browse files
committed
Merge remote-tracking branch 'upstream/3.1.x' into 3.1.x
2 parents b10f475 + 8de49e3 commit 937edd7

File tree

5 files changed

+45
-21
lines changed

5 files changed

+45
-21
lines changed

grails-gradle-plugin/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ class GrailsGradlePlugin extends GroovyPlugin {
155155
}
156156

157157
protected Task createBuildPropertiesTask(Project project) {
158-
159158
def buildInfoFile = project.file("${project.buildDir}/grails.build.info")
160159

161160
def buildPropertiesTask = project.tasks.create("buildProperties")
@@ -169,7 +168,7 @@ class GrailsGradlePlugin extends GroovyPlugin {
169168
buildPropertiesTask << {
170169
project.buildDir.mkdirs()
171170
ant.propertyfile(file: buildInfoFile) {
172-
for(me in buildPropertiesContents) {
171+
for(me in buildPropertiesTask.inputs.properties) {
173172
entry key: me.key, value: me.value
174173
}
175174
}

grails-plugin-interceptors/src/main/groovy/grails/artefact/Interceptor.groovy

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package grails.artefact
1818
import grails.artefact.controller.support.RequestForwarder
1919
import grails.artefact.controller.support.ResponseRedirector
2020
import grails.artefact.controller.support.ResponseRenderer
21+
import grails.core.GrailsApplication
2122
import grails.interceptors.Matcher
2223
import grails.util.GrailsNameUtils
2324
import grails.web.api.ServletAttributes
@@ -34,11 +35,12 @@ import org.grails.web.servlet.mvc.exceptions.ControllerExecutionException
3435
import org.grails.web.servlet.view.CompositeViewResolver
3536
import org.grails.web.util.GrailsApplicationAttributes
3637
import org.grails.web.util.WebUtils
38+
import org.springframework.beans.factory.annotation.Autowired
3739
import org.springframework.core.Ordered
3840
import org.springframework.web.servlet.ModelAndView
39-
import org.springframework.web.servlet.View
4041
import org.springframework.web.servlet.ViewResolver
4142

43+
import javax.annotation.PostConstruct
4244
import javax.servlet.http.HttpServletRequest
4345
import javax.servlet.http.HttpServletResponse
4446
import java.util.concurrent.ConcurrentLinkedQueue
@@ -81,13 +83,6 @@ trait Interceptor implements ResponseRenderer, ResponseRedirector, RequestForwar
8183
return (Boolean)existing
8284
}
8385

84-
if(matchers.isEmpty()) {
85-
// default to map just the controller by convention
86-
def matcher = new UrlMappingMatcher(this)
87-
matcher.matches(controller:Pattern.compile(GrailsNameUtils.getLogicalPropertyName(getClass().simpleName, "Interceptor")))
88-
matchers << matcher
89-
}
90-
9186
def req = request
9287
def uri = req.requestURI
9388

@@ -269,4 +264,17 @@ trait Interceptor implements ResponseRenderer, ResponseRedirector, RequestForwar
269264
}
270265
}
271266

267+
/**
268+
* Registers the default match strategy if non has been registered
269+
*/
270+
@Autowired
271+
void setGrailsApplication(GrailsApplication grailsApplication) {
272+
if(matchers.isEmpty()) {
273+
// default to map just the controller by convention
274+
def matcher = new UrlMappingMatcher(this)
275+
matcher.matches(controller:Pattern.compile(GrailsNameUtils.getLogicalPropertyName(getClass().simpleName, InterceptorArtefactHandler.TYPE)))
276+
matchers << matcher
277+
}
278+
279+
}
272280
}

grails-plugin-interceptors/src/main/groovy/org/grails/plugins/web/interceptors/InterceptorsGrailsPlugin.groovy

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import grails.plugins.Plugin
2222
import grails.util.GrailsUtil
2323
import groovy.transform.CompileDynamic
2424
import groovy.transform.CompileStatic
25+
import org.springframework.web.servlet.HandlerInterceptor
26+
import org.springframework.web.servlet.handler.MappedInterceptor
2527

2628

2729
/**
@@ -45,7 +47,7 @@ class InterceptorsGrailsPlugin extends Plugin {
4547
GrailsClass[] interceptors = grailsApplication.getArtefacts(InterceptorArtefactHandler.TYPE)
4648
if(interceptors.length == 0) return
4749

48-
grailsInterceptorHandlerInterceptorAdapter(GrailsInterceptorHandlerInterceptorAdapter)
50+
grailsInterceptorMappedInterceptor(MappedInterceptor, ['/**'] as String[], bean(GrailsInterceptorHandlerInterceptorAdapter))
4951

5052
def enableJsessionId = config.getProperty(Settings.GRAILS_VIEWS_ENABLE_JSESSIONID, Boolean, false)
5153
for(GrailsClass i in interceptors) {
@@ -61,8 +63,8 @@ class InterceptorsGrailsPlugin extends Plugin {
6163

6264
@Override
6365
void doWithApplicationContext() {
64-
if(applicationContext.containsBeanDefinition("grailsInterceptorHandlerInterceptorAdapter")) {
65-
interceptorAdapter = applicationContext.getBean("grailsInterceptorHandlerInterceptorAdapter", GrailsInterceptorHandlerInterceptorAdapter)
66+
if(applicationContext.containsBeanDefinition("grailsInterceptorMappedInterceptor")) {
67+
interceptorAdapter = (GrailsInterceptorHandlerInterceptorAdapter)applicationContext.getBean("grailsInterceptorMappedInterceptor", MappedInterceptor).getInterceptor()
6668
}
6769
}
6870

@@ -76,7 +78,7 @@ class InterceptorsGrailsPlugin extends Plugin {
7678
def interceptorClass = (Class) source
7779
def grailsClass = grailsApplication.addArtefact(InterceptorArtefactHandler.TYPE, interceptorClass)
7880

79-
def interceptorAdapter = this.interceptorAdapter ?: applicationContext.getBean(GrailsInterceptorHandlerInterceptorAdapter)
81+
def interceptorAdapter = this.interceptorAdapter ?: (GrailsInterceptorHandlerInterceptorAdapter)applicationContext.getBean("grailsInterceptorMappedInterceptor", MappedInterceptor).getInterceptor()
8082
defineInterceptorBean(grailsClass, interceptorClass, enableJsessionId)
8183
interceptorAdapter.setInterceptors(
8284
applicationContext.getBeansOfType(Interceptor).values() as Interceptor[]

grails-plugin-interceptors/src/test/groovy/grails/artefact/InterceptorSpec.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class InterceptorSpec extends Specification {
3939
void "Test the default interceptor mappings"() {
4040
given:"A test interceptor"
4141
def i = new TestInterceptor()
42+
i.setGrailsApplication(null)
4243
def webRequest = GrailsWebMockUtil.bindMockWebRequest()
4344
HttpServletRequest request = webRequest.request
4445
when:"The current request is for a controller called test"

grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/mvc/UrlMappingsHandlerMapping.groovy

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.grails.web.mapping.mvc
1717

18+
import groovy.transform.CompileDynamic
1819
import groovy.transform.CompileStatic
1920
import grails.web.mapping.UrlMapping
2021
import grails.web.mapping.UrlMappingInfo
@@ -63,7 +64,11 @@ class UrlMappingsHandlerMapping extends AbstractHandlerMapping {
6364

6465
@Autowired
6566
void setHandlerInterceptors(HandlerInterceptor[] handlerInterceptors) {
66-
setInterceptors(handlerInterceptors)
67+
for(hi in handlerInterceptors) {
68+
if(!(hi instanceof MappedInterceptor)) {
69+
setInterceptors(hi)
70+
}
71+
}
6772
}
6873

6974
@Autowired(required = false)
@@ -81,26 +86,35 @@ class UrlMappingsHandlerMapping extends AbstractHandlerMapping {
8186
@Override
8287
protected HandlerExecutionChain getHandlerExecutionChain(Object handler, HttpServletRequest request) {
8388
HandlerExecutionChain chain = (handler instanceof HandlerExecutionChain ?
84-
(HandlerExecutionChain) handler : new HandlerExecutionChain(handler));
89+
(HandlerExecutionChain) handler : new HandlerExecutionChain(handler))
8590

8691
// WebRequestInterceptor need to come first, as these include things like Hibernate OSIV
8792
if(webRequestHandlerInterceptors) {
8893
chain.addInterceptors webRequestHandlerInterceptors
8994
}
9095

91-
chain.addInterceptors getAdaptedInterceptors()
92-
9396
String lookupPath = this.urlPathHelper.getLookupPathForRequest(request)
94-
for (MappedInterceptor mappedInterceptor in getMappedInterceptors()) {
95-
if (mappedInterceptor.matches(lookupPath, this.pathMatcher)) {
96-
chain.addInterceptor(mappedInterceptor.interceptor)
97+
for (HandlerInterceptor interceptor in this.adaptedInterceptors) {
98+
if (interceptor instanceof MappedInterceptor) {
99+
MappedInterceptor mappedInterceptor = mappedInterceptor(interceptor)
100+
if (mappedInterceptor.matches(lookupPath, this.pathMatcher)) {
101+
chain.addInterceptor(mappedInterceptor.getInterceptor())
102+
}
103+
}
104+
else {
105+
chain.addInterceptor(interceptor)
97106
}
98107
}
99108

100109
chain.addInterceptor(new ErrorHandlingHandler())
101110
return chain
102111
}
103112

113+
@CompileDynamic
114+
protected MappedInterceptor mappedInterceptor(HandlerInterceptor interceptor) {
115+
(MappedInterceptor) interceptor
116+
}
117+
104118
@Override
105119
protected Object getHandlerInternal(HttpServletRequest request) throws Exception {
106120

0 commit comments

Comments
 (0)