Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to work with 2.3.5 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.svn/
docs/
target/
.idea/
*.iml
.directory
24 changes: 9 additions & 15 deletions Perf4jGrailsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.codehaus.groovy.grails.commons.GrailsClassUtils as GCU
import grails.util.GrailsNameUtils as GNU
import org.codehaus.groovy.grails.plugins.support.GrailsPluginUtils
import grails.util.GrailsUtil

import org.grails.plugins.perf4j.SharedOptions
import org.perf4j.log4j.Log4JStopWatch

import org.grails.plugins.perf4j.ProfiledOptionsBuilder
Expand Down Expand Up @@ -35,17 +35,11 @@ ways to profile individual code blocks and automatic, customizable profiling of
// URL to the plugin's documentation
def documentation = "http://www.grails.org/plugin/perf4j"


// the name of the config property in services
static final String PROFILED_PROPERTY = "profiled"
// indicates whether profiling is enabled AT ALL (according to config option or implicitly by environment)
static Boolean profilingEnabled = false
// indicates whether profiling is CURRENTLY enabled (as set via "profilingEnabled" property during runtime)
static Boolean profilingCurrentlyEnabled = true

private static dummyObjectInstance = new DummyObject()


def doWithSpring = {
// register controller options cache as spring bean
controllerProfiledOptionsCache(ControllerProfiledOptionsCache)
Expand Down Expand Up @@ -120,10 +114,10 @@ ways to profile individual code blocks and automatic, customizable profiling of
}

def onConfigChange = { event ->
def oldEnabled = profilingEnabled
def oldEnabled = SharedOptions.profilingEnabled
evaluateConfigSettings(application, log)

if(oldEnabled != profilingEnabled) {
if(oldEnabled != SharedOptions.profilingEnabled) {
// re-register all methods
addPerf4jFeaturesToAllArtefacts(application, log)
}
Expand All @@ -135,7 +129,7 @@ ways to profile individual code blocks and automatic, customizable profiling of
*/
def evaluateConfigSettings(application, log) {
log.info "Evaluating new Perf4j config settings..."
profilingEnabled = (application.config.flatten().containsKey("perf4j.enabled") ? application.config.perf4j.enabled : GrailsUtil.isDevelopmentEnv())
SharedOptions.profilingEnabled = (application.config.flatten().containsKey("perf4j.enabled") ? application.config.perf4j.enabled : GrailsUtil.isDevelopmentEnv())
}

def addPerf4jFeaturesToAllArtefacts(application, log) {
Expand Down Expand Up @@ -175,7 +169,7 @@ ways to profile individual code blocks and automatic, customizable profiling of
}

artefactClass.metaClass.withStopwatch << { String tag, String message, Closure callable ->
if(this.profilingEnabled && this.profilingCurrentlyEnabled) {
if(SharedOptions.profilingEnabled && SharedOptions.profilingCurrentlyEnabled) {
def stopWatch = new Log4JStopWatch()
def retVal
try {
Expand All @@ -198,11 +192,11 @@ ways to profile individual code blocks and automatic, customizable profiling of
}

artefactClass.metaClass.setProfilingEnabled << { Boolean enabled ->
this.profilingCurrentlyEnabled = enabled
SharedOptions.profilingCurrentlyEnabled = enabled
}

artefactClass.metaClass.getProfilingEnabled << { ->
this.profilingCurrentlyEnabled
SharedOptions.profilingCurrentlyEnabled
}
}

Expand All @@ -216,7 +210,7 @@ ways to profile individual code blocks and automatic, customizable profiling of
* because otherwise we would not be able to "hot enable" it upon config change (adding methods via ExpandoMetaClass is only
* allowed within doWithDynamicMethods()).
*/
if(profilingEnabled || GrailsUtil.isDevelopmentEnv()) {
if(SharedOptions.profilingEnabled || GrailsUtil.isDevelopmentEnv()) {
log.info "Adding Per4j interception code: ${artefactClass}..."

def profiled = GCU.getStaticPropertyValue(artefactClass, PROFILED_PROPERTY)
Expand Down Expand Up @@ -268,7 +262,7 @@ ways to profile individual code blocks and automatic, customizable profiling of
artefactClass.metaClass.invokeMethod = { String name, args ->
def metaMethod = artefactClass.metaClass.getMetaMethod(name, args)
if(metaMethod) {
if(this.profilingEnabled && this.profilingCurrentlyEnabled && profilingOptions.containsKey(name)) {
if(SharedOptions.profilingEnabled && SharedOptions.profilingCurrentlyEnabled && profilingOptions.containsKey(name)) {
def tag = profilingOptions[name]?.tag ?: ""
def message = profilingOptions[name]?.message ?: null
def stopWatch = new Log4JStopWatch(tag, message)
Expand Down
6 changes: 2 additions & 4 deletions application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#Grails Metadata file
#Sun Nov 08 17:08:11 CET 2009
app.grails.version=1.2-M4
#Thu Feb 13 09:15:35 CET 2014
app.grails.version=2.3.5
app.name=perf4j
plugins.hibernate=1.2-M4
plugins.tomcat=1.2-M4
49 changes: 49 additions & 0 deletions grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"

grails.project.fork = [
// configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
// compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],

// configure settings for the test-app JVM, uses the daemon by default
test: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the run-app JVM
run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
// configure settings for the run-war JVM
war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
// configure settings for the Console UI JVM
console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]

grails.project.dependency.resolver = "maven" // or ivy
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// uncomment to disable ehcache
// excludes 'ehcache'
}
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
repositories {
grailsCentral()
mavenLocal()
mavenCentral()
// uncomment the below to enable remote dependency resolution
// from public Maven repositories
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
// runtime 'mysql:mysql-connector-java:5.1.27'
compile 'org.perf4j:perf4j:0.9.16'
}

plugins {
build(":release:3.0.1",
":rest-client-builder:1.0.3") {
export = false
}
}
}
22 changes: 22 additions & 0 deletions grails-app/conf/Config.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// configuration for plugin testing - will not be included in the plugin zip

log4j = {
// Example of changing the log pattern for the default console
// appender:
//
//appenders {
// console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
//}

error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
}
9 changes: 5 additions & 4 deletions grails-app/conf/Perf4jFilters.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.codehaus.groovy.grails.commons.GrailsClassUtils as GCU
import grails.util.GrailsNameUtils as GNU
import org.grails.plugins.perf4j.SharedOptions
import org.perf4j.log4j.Log4JStopWatch
import org.apache.log4j.Logger

Expand All @@ -11,7 +12,7 @@ public class Perf4jFilters {
static final String STOPWATCH_REQUEST_KEY = 'perf4jplugin.stopwatch'
// the key used to store the includeView flag in the request
static final String INCLUDE_VIEW_REQUEST_KEY = 'perf4jplugin.includeView'

def log = Logger.getLogger(Perf4jFilters)

def controllerProfiledOptionsCache
Expand All @@ -22,7 +23,7 @@ public class Perf4jFilters {

all(controller:'*', action: '*') {
before = {
if(Perf4jGrailsPlugin.profilingEnabled && Perf4jGrailsPlugin.profilingCurrentlyEnabled) {
if(SharedOptions.profilingEnabled && SharedOptions.profilingCurrentlyEnabled) {
if(controllerName) {
def action = actionName ?: 'index'
def controller = GNU.getClassName(controllerName, "Controller")
Expand Down Expand Up @@ -62,7 +63,7 @@ public class Perf4jFilters {


after = {
if(Perf4jGrailsPlugin.profilingEnabled && Perf4jGrailsPlugin.profilingCurrentlyEnabled) {
if(SharedOptions.profilingEnabled && SharedOptions.profilingCurrentlyEnabled) {
def includeView = request[INCLUDE_VIEW_REQUEST_KEY]

if(!includeView) {
Expand All @@ -73,7 +74,7 @@ public class Perf4jFilters {


afterView = {
if(Perf4jGrailsPlugin.profilingEnabled && Perf4jGrailsPlugin.profilingCurrentlyEnabled) {
if(SharedOptions.profilingEnabled && SharedOptions.profilingCurrentlyEnabled) {
def includeView = request[INCLUDE_VIEW_REQUEST_KEY]

if(includeView) {
Expand Down
Binary file removed lib/perf4j-0.9.12-log4jonly.jar
Binary file not shown.
13 changes: 13 additions & 0 deletions src/groovy/org/grails/plugins/perf4j/SharedOptions.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.grails.plugins.perf4j

/**
* Share values between Perf4jGrailsPlugin, Perf4jFilters and maybe other classes
* TODO isn't there risk with multithreading ?
*/
class SharedOptions {
// indicates whether profiling is enabled AT ALL (according to config option or implicitly by environment)
static Boolean profilingEnabled = false
// indicates whether profiling is CURRENTLY enabled (as set via "profilingEnabled" property during runtime)
static Boolean profilingCurrentlyEnabled = true

}
25 changes: 17 additions & 8 deletions web-app/WEB-INF/tld/c.tld
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
<taglib xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>JSTL 1.1 core library</description>
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">

<description>JSTL 1.2 core library</description>
<display-name>JSTL core</display-name>
<tlib-version>1.1</tlib-version>
<tlib-version>1.2</tlib-version>
<short-name>c</short-name>
<uri>http://java.sun.com/jsp/jstl/core</uri>

Expand Down Expand Up @@ -74,7 +74,7 @@ not the body content should be processed.
<description>
Name of the exported scoped variable for the
resulting value of the test condition. The type
of the scoped variable is Boolean.
of the scoped variable is Boolean.
</description>
<name>var</name>
<required>false</required>
Expand Down Expand Up @@ -174,6 +174,9 @@ Collection of items to iterate over.
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.Object</type>
<deferred-value>
<type>java.lang.Object</type>
</deferred-value>
</attribute>
<attribute>
<description>
Expand Down Expand Up @@ -253,6 +256,9 @@ String of tokens to iterate over.
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
<attribute>
<description>
Expand Down Expand Up @@ -322,7 +328,7 @@ visibility.
<tag>
<description>
Like &lt;%= ... &gt;, but for expressions.
</description>
</description>
<name>out</name>
<tag-class>org.apache.taglibs.standard.tag.rt.core.OutTag</tag-class>
<body-content>JSP</body-content>
Expand Down Expand Up @@ -467,6 +473,9 @@ Expression to be evaluated.
<name>value</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<deferred-value>
<type>java.lang.Object</type>
</deferred-value>
</attribute>
<attribute>
<description>
Expand Down
16 changes: 8 additions & 8 deletions web-app/WEB-INF/tld/fmt.tld
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
<taglib xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>JSTL 1.1 i18n-capable formatting library</description>
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">

<description>JSTL 1.2 i18n-capable formatting library</description>
<display-name>JSTL fmt</display-name>
<tlib-version>1.1</tlib-version>
<tlib-version>1.2</tlib-version>
<short-name>fmt</short-name>
<uri>http://java.sun.com/jsp/jstl/fmt</uri>

Expand Down Expand Up @@ -55,7 +55,7 @@ and may contain a two-letter (upper-case)
country code (as defined by ISO-3166).
Language and country codes must be
separated by hyphen (-) or underscore
(_).
(_).
</description>
<name>value</name>
<required>true</required>
Expand Down Expand Up @@ -496,7 +496,7 @@ Date and/or time to be formatted.
<description>
Specifies whether the time, the date, or both
the time and date components of the given
date are to be formatted.
date are to be formatted.
</description>
<name>type</name>
<required>false</required>
Expand Down