Permalink
Browse files

make plugin run properly in grails versions 2.0 and 2.1

 - remove GSP servlet profiling, since it wasn't workinganyway

 - some fixes to factor in different classes appearing in web.xml munging
  • Loading branch information...
1 parent 0cc9d93 commit 193cfd0ce7abcb8f6c8118a95aebbae9ea9f72c0 @tomdcc committed Dec 22, 2012
@@ -1,3 +1,5 @@
+import groovy.util.slurpersupport.GPathResult
+
import java.lang.reflect.Field
import java.lang.reflect.Modifier
@@ -13,7 +15,6 @@ import com.energizedwork.miniprofiler.MiniprofilerCondition
import com.energizedwork.miniprofiler.NullSpyLogDelegator
import com.energizedwork.miniprofiler.ProfilerProvider
import com.energizedwork.miniprofiler.ProfilingDataSource
-import com.energizedwork.miniprofiler.ProfilingGrailsViewResolver
import com.energizedwork.miniprofiler.ProfilingSpyLogDelegator
import com.energizedwork.miniprofiler.ServletRequestProfilerProvider
@@ -65,11 +66,14 @@ database and other performance problems.
// now the fun part - override the grails page filter with one which profiles layout rendering
def pageFilterMapping = webXml.'filter'.find { it.'filter-name'.text() == 'sitemesh' }
- pageFilterMapping.'filter-class'[0] = 'com.energizedwork.miniprofiler.ProfilingGrailsPageFilter'
+ def filterClassNode = pageFilterMapping.'filter-class'[0]
+ def newFilterClass = 'com.energizedwork.miniprofiler.ProfilingGrailsPageFilter'
+ if (filterClassNode instanceof GPathResult) {
+ filterClassNode.replaceBody(newFilterClass)
+ } else {
+ filterClassNode.setTextContent(newFilterClass)
+ }
- // and override the gsp servlet so we can see specific gsp timings
- def gspServlet = webXml.'servlet'.find { it.'servlet-name'.text() == 'gsp' }
- gspServlet.'servlet-class'[0] = 'com.energizedwork.miniprofiler.ProfilingGroovyPagesServlet'
}
private boolean isProfilingDisabled(application) {
@@ -111,12 +115,15 @@ database and other performance problems.
profilerProvider = ref('profilerProvider')
}
- BeanConfiguration viewResolverConfig = springConfig.getBeanConfig('jspViewResolver')
- springConfig.addBeanConfiguration("jspViewResolverOriginal", viewResolverConfig)
+ // commented out for now since this isn't working reliably yet
+ // just trying to get the gsp names
- jspViewResolver(ProfilingGrailsViewResolver) {
- wrapped = ref('jspViewResolverOriginal')
- }
+// BeanConfiguration viewResolverConfig = springConfig.getBeanConfig('jspViewResolver')
+// springConfig.addBeanConfiguration("jspViewResolverOriginal", viewResolverConfig)
+//
+// jspViewResolver(ProfilingGrailsViewResolver) {
+// wrapped = ref('jspViewResolverOriginal')
+// }
}
private void setuplLog4JdbcLogger(ProfilerProvider profilerProvider) {
@@ -1,48 +0,0 @@
-package com.energizedwork.miniprofiler;
-
-import groovy.text.Template;
-
-import java.io.IOException;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.lang.StringUtils;
-import org.codehaus.groovy.grails.web.pages.GroovyPagesServlet;
-import org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine;
-import org.codehaus.groovy.grails.web.pages.discovery.GroovyPageScriptSource;
-import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes;
-
-public class ProfilingGroovyPagesServlet extends GroovyPagesServlet {
-
- protected void renderPageWithEngine(GroovyPagesTemplateEngine engine, HttpServletRequest request,
- HttpServletResponse response, Template template) throws IOException {
-
- String pageName = determinePageName(request);
-// System.out.println(pageName);
-// super.renderPageWithEngine(engine, request, response, template);
- }
-
- protected void renderPageWithEngine(GroovyPagesTemplateEngine engine, HttpServletRequest request,
- HttpServletResponse response, GroovyPageScriptSource scriptSource) throws Exception {
-
- String pageName = determinePageName(request);
-// System.out.println(pageName);
- super.renderPageWithEngine(engine, request, response, scriptSource);
- }
-
- protected String determinePageName(HttpServletRequest request) {
-
- String pageName = (String)request.getAttribute(GrailsApplicationAttributes.GSP_TO_RENDER);
- if (StringUtils.isBlank(pageName)) {
- Object includePath = request.getAttribute("javax.servlet.include.servlet_path");
- if (includePath != null) {
- pageName = (String) includePath;
- } else {
- pageName = request.getServletPath();
- }
- }
-
- return pageName;
- }
-}

0 comments on commit 193cfd0

Please sign in to comment.