Skip to content

Commit

Permalink
Code reformat.
Browse files Browse the repository at this point in the history
  • Loading branch information
donbeave committed Mar 30, 2015
1 parent 757a932 commit 6a7d704
Show file tree
Hide file tree
Showing 13 changed files with 482 additions and 484 deletions.
237 changes: 117 additions & 120 deletions CacheRedisGrailsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,137 +12,134 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import grails.plugin.cache.redis.GrailsRedisCacheManager
import grails.plugin.cache.web.filter.redis.GrailsDeserializer
import grails.plugin.cache.web.filter.redis.GrailsDeserializingConverter
import grails.plugin.cache.web.filter.redis.GrailsRedisSerializer
import grails.plugin.cache.web.filter.redis.GrailsSerializer
import grails.plugin.cache.web.filter.redis.GrailsSerializingConverter
import grails.plugin.cache.web.filter.redis.GrailsRedisKeySerializer
import grails.plugin.cache.web.filter.redis.RedisPageFragmentCachingFilter

import grails.plugin.cache.redis.GrailsRedisCacheManager
import grails.plugin.cache.web.filter.redis.*
import org.codehaus.groovy.grails.commons.GrailsApplication
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.data.redis.cache.DefaultRedisCachePrefix
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory
import org.springframework.data.redis.core.RedisTemplate

import redis.clients.jedis.JedisPoolConfig
import redis.clients.jedis.JedisShardInfo
import redis.clients.jedis.Protocol

/**
* @author Burt Beckwith
*/
class CacheRedisGrailsPlugin {

private final Logger log = LoggerFactory.getLogger('grails.plugin.cache.CacheRedisGrailsPlugin')

String version = '1.1.1-SNAPSHOT'
String grailsVersion = '2.5 > *'
def loadAfter = ['cache']
def pluginExcludes = [
'grails-app/conf/*CacheConfig.groovy',
'scripts/CreateCacheRedisTestApps.groovy',
'docs/**',
'src/docs/**'
]

String title = 'Redis Cache Plugin'
String author = 'Burt Beckwith'
String authorEmail = 'beckwithb@vmware.com'
String description = 'A Redis-based implementation of the Cache plugin'
String documentation = 'http://grails-plugins.github.io/grails-cache-redis/'

String license = 'APACHE'
def organization = [name: 'Pivotal', url: 'http://www.gopivotal.com/oss']
def issueManagement = [system: 'JIRA', url: 'http://jira.grails.org/browse/GPCACHEREDIS']
def scm = [url: 'https://github.com/grails-plugins/grails-cache-redis']

def doWithSpring = {
if (!isEnabled(application)) {
log.warn 'Redis Cache plugin is disabled'
return
}

def cacheConfig = application.config.grails.cache
def redisCacheConfig = cacheConfig.redis
int database = redisCacheConfig.database ?: 0
boolean usePool = (redisCacheConfig.usePool instanceof Boolean) ? redisCacheConfig.usePool : true
String hostName = redisCacheConfig.hostName ?: 'localhost'
int port = redisCacheConfig.port ?: Protocol.DEFAULT_PORT
int timeout = redisCacheConfig.timeout ?: Protocol.DEFAULT_TIMEOUT
String password = redisCacheConfig.password ?: null
Boolean isUsePrefix = (redisCacheConfig.usePrefix instanceof Boolean) ? redisCacheConfig.usePrefix : false
String keySerializerBean = redisCacheConfig.keySerializer instanceof String ?
redisCacheConfig.keySerializer : null
String hashKeySerializerBean = redisCacheConfig.hashKeySerializer instanceof String ?
redisCacheConfig.hashKeySerializer : null

grailsCacheJedisPoolConfig(JedisPoolConfig)

grailsCacheJedisShardInfo(JedisShardInfo, hostName, port) {
password = password
timeout = timeout
}

grailsCacheJedisConnectionFactory(JedisConnectionFactory) {
usePool = usePool
database = database
hostName = hostName
port = port
timeout = timeout
password = password
poolConfig = ref('grailsCacheJedisPoolConfig')
shardInfo = ref('grailsCacheJedisShardInfo')
}

grailsRedisCacheSerializer(GrailsSerializer)

grailsRedisCacheDeserializer(GrailsDeserializer)

grailsRedisCacheDeserializingConverter(GrailsDeserializingConverter) {
deserializer = ref('grailsRedisCacheDeserializer')
}

grailsRedisCacheSerializingConverter(GrailsSerializingConverter) {
serializer = ref('grailsRedisCacheSerializer')
}

grailsCacheRedisSerializer(GrailsRedisSerializer) {
serializer = ref('grailsRedisCacheSerializingConverter')
deserializer = ref('grailsRedisCacheDeserializingConverter')
}

grailsCacheRedisKeySerializer(GrailsRedisKeySerializer, ref('grailsCacheRedisSerializer'))

grailsCacheRedisTemplate(RedisTemplate) {
connectionFactory = ref('grailsCacheJedisConnectionFactory')
defaultSerializer = ref('grailsCacheRedisSerializer')
if (keySerializerBean)
keySerializer = ref(keySerializerBean)
if (hashKeySerializerBean)
hashKeySerializer = ref(hashKeySerializerBean)
}

String delimiter = redisCacheConfig.cachePrefixDelimiter ?: ':'
redisCachePrefix(DefaultRedisCachePrefix, delimiter)

grailsCacheManager(GrailsRedisCacheManager, ref('grailsCacheRedisTemplate')) {
cachePrefix = ref('redisCachePrefix')
usePrefix = isUsePrefix
}

grailsCacheFilter(RedisPageFragmentCachingFilter) {
cacheManager = ref('grailsCacheManager')
nativeCacheManager = ref('grailsCacheRedisTemplate')
// TODO this name might be brittle - perhaps do by type?
cacheOperationSource = ref('org.springframework.cache.annotation.AnnotationCacheOperationSource#0')
keyGenerator = ref('webCacheKeyGenerator')
expressionEvaluator = ref('webExpressionEvaluator')
}
}

private boolean isEnabled(GrailsApplication application) {
// TODO
true
}
private final Logger log = LoggerFactory.getLogger('grails.plugin.cache.CacheRedisGrailsPlugin')

String version = '1.1.1-SNAPSHOT'
String grailsVersion = '2.5 > *'
def loadAfter = ['cache']
def pluginExcludes = [
'grails-app/conf/*CacheConfig.groovy',
'scripts/CreateCacheRedisTestApps.groovy',
'docs/**',
'src/docs/**'
]

String title = 'Redis Cache Plugin'
String author = 'Burt Beckwith'
String authorEmail = 'beckwithb@vmware.com'
String description = 'A Redis-based implementation of the Cache plugin'
String documentation = 'http://grails-plugins.github.io/grails-cache-redis/'

String license = 'APACHE'
def organization = [name: 'Pivotal', url: 'http://www.gopivotal.com/oss']
def issueManagement = [system: 'JIRA', url: 'http://jira.grails.org/browse/GPCACHEREDIS']
def scm = [url: 'https://github.com/grails-plugins/grails-cache-redis']

def doWithSpring = {
if (!isEnabled(application)) {
log.warn 'Redis Cache plugin is disabled'
return
}

def cacheConfig = application.config.grails.cache
def redisCacheConfig = cacheConfig.redis
int database = redisCacheConfig.database ?: 0
boolean usePool = (redisCacheConfig.usePool instanceof Boolean) ? redisCacheConfig.usePool : true
String hostName = redisCacheConfig.hostName ?: 'localhost'
int port = redisCacheConfig.port ?: Protocol.DEFAULT_PORT
int timeout = redisCacheConfig.timeout ?: Protocol.DEFAULT_TIMEOUT
String password = redisCacheConfig.password ?: null
Boolean isUsePrefix = (redisCacheConfig.usePrefix instanceof Boolean) ? redisCacheConfig.usePrefix : false
String keySerializerBean = redisCacheConfig.keySerializer instanceof String ?
redisCacheConfig.keySerializer : null
String hashKeySerializerBean = redisCacheConfig.hashKeySerializer instanceof String ?
redisCacheConfig.hashKeySerializer : null

grailsCacheJedisPoolConfig(JedisPoolConfig)

grailsCacheJedisShardInfo(JedisShardInfo, hostName, port) {
password = password
timeout = timeout
}

grailsCacheJedisConnectionFactory(JedisConnectionFactory) {
usePool = usePool
database = database
hostName = hostName
port = port
timeout = timeout
password = password
poolConfig = ref('grailsCacheJedisPoolConfig')
shardInfo = ref('grailsCacheJedisShardInfo')
}

grailsRedisCacheSerializer(GrailsSerializer)

grailsRedisCacheDeserializer(GrailsDeserializer)

grailsRedisCacheDeserializingConverter(GrailsDeserializingConverter) {
deserializer = ref('grailsRedisCacheDeserializer')
}

grailsRedisCacheSerializingConverter(GrailsSerializingConverter) {
serializer = ref('grailsRedisCacheSerializer')
}

grailsCacheRedisSerializer(GrailsRedisSerializer) {
serializer = ref('grailsRedisCacheSerializingConverter')
deserializer = ref('grailsRedisCacheDeserializingConverter')
}

grailsCacheRedisKeySerializer(GrailsRedisKeySerializer, ref('grailsCacheRedisSerializer'))

grailsCacheRedisTemplate(RedisTemplate) {
connectionFactory = ref('grailsCacheJedisConnectionFactory')
defaultSerializer = ref('grailsCacheRedisSerializer')
if (keySerializerBean)
keySerializer = ref(keySerializerBean)
if (hashKeySerializerBean)
hashKeySerializer = ref(hashKeySerializerBean)
}

String delimiter = redisCacheConfig.cachePrefixDelimiter ?: ':'
redisCachePrefix(DefaultRedisCachePrefix, delimiter)

grailsCacheManager(GrailsRedisCacheManager, ref('grailsCacheRedisTemplate')) {
cachePrefix = ref('redisCachePrefix')
usePrefix = isUsePrefix
}

grailsCacheFilter(RedisPageFragmentCachingFilter) {
cacheManager = ref('grailsCacheManager')
nativeCacheManager = ref('grailsCacheRedisTemplate')
// TODO this name might be brittle - perhaps do by type?
cacheOperationSource = ref('org.springframework.cache.annotation.AnnotationCacheOperationSource#0')
keyGenerator = ref('webCacheKeyGenerator')
expressionEvaluator = ref('webExpressionEvaluator')
}
}

private boolean isEnabled(GrailsApplication application) {
// TODO
true
}

}
50 changes: 25 additions & 25 deletions grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if(System.getenv('TRAVIS_BRANCH')) {
if (System.getenv('TRAVIS_BRANCH')) {
grails.project.repos.grailsCentral.username = System.getenv("GRAILS_CENTRAL_USERNAME")
grails.project.repos.grailsCentral.password = System.getenv("GRAILS_CENTRAL_PASSWORD")
grails.project.repos.grailsCentral.password = System.getenv("GRAILS_CENTRAL_PASSWORD")
}

grails.project.work.dir = 'target'
Expand All @@ -11,30 +11,30 @@ grails.project.target.level = 1.7
grails.project.dependency.resolver = "maven" // or ivy
grails.project.dependency.resolution = {

inherits 'global'
log 'warn'
inherits 'global'
log 'warn'

repositories {
grailsCentral()
mavenLocal()
mavenCentral()
}
repositories {
grailsCentral()
mavenLocal()
mavenCentral()
}

dependencies {
compile 'redis.clients:jedis:2.5.1'
compile 'org.springframework:spring-expression:4.0.5.RELEASE'
compile 'org.springframework.data:spring-data-redis:1.3.0.RELEASE', {
exclude group:'org.springframework', name:'spring-aop'
exclude group:'org.springframework', name:'spring-context-support'
exclude group:'org.springframework', name:'spring-context'
}

}
dependencies {
compile 'redis.clients:jedis:2.5.1'
compile 'org.springframework:spring-expression:4.0.5.RELEASE'
compile 'org.springframework.data:spring-data-redis:1.3.0.RELEASE', {
exclude group: 'org.springframework', name: 'spring-aop'
exclude group: 'org.springframework', name: 'spring-context-support'
exclude group: 'org.springframework', name: 'spring-context'
}

plugins {
build(':release:3.0.1', ':rest-client-builder:2.0.1') {
export = false
}
compile ':cache:1.1.6'
}
}

plugins {
build(':release:3.0.1', ':rest-client-builder:2.0.1') {
export = false
}
compile ':cache:1.1.6'
}
}
20 changes: 10 additions & 10 deletions grails-app/conf/Config.groovy
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
log4j = {
error 'org.codehaus.groovy.grails',
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
error 'org.codehaus.groovy.grails',
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
}

// for tests
grails.cache.config = {
cache {
name 'fromConfigGroovy1'
}
cache {
name 'fromConfigGroovy2'
}
cache {
name 'fromConfigGroovy1'
}
cache {
name 'fromConfigGroovy2'
}
}
18 changes: 9 additions & 9 deletions grails-app/conf/DataSource.groovy
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
dataSource {
pooled = true
driverClassName = 'org.h2.Driver'
username = 'sa'
password = ''
dbCreate = 'update'
url = 'jdbc:h2:mem:testDb'
pooled = true
driverClassName = 'org.h2.Driver'
username = 'sa'
password = ''
dbCreate = 'update'
url = 'jdbc:h2:mem:testDb'
}

hibernate {
cache.use_second_level_cache = false
cache.use_query_cache = false
cache.provider_class = 'org.hibernate.cache.EhCacheProvider'
cache.use_second_level_cache = false
cache.use_query_cache = false
cache.provider_class = 'org.hibernate.cache.EhCacheProvider'
}
14 changes: 7 additions & 7 deletions grails-app/conf/TestCacheConfig.groovy
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
config = {
cache {
name 'basic'
eternal false
overflowToDisk true
maxElementsInMemory 10000
maxElementsOnDisk 10000000
}
cache {
name 'basic'
eternal false
overflowToDisk true
maxElementsInMemory 10000
maxElementsOnDisk 10000000
}
}
Loading

0 comments on commit 6a7d704

Please sign in to comment.