Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
burtbeckwith committed Sep 13, 2013
1 parent 371d59e commit 8aeadbc
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,4 +1,3 @@
.gitignore
*.zip
*.sha1
*.iml
Expand All @@ -12,3 +11,4 @@ classes
plugin.xml
target
web-app
*.log
71 changes: 35 additions & 36 deletions RoutingGrailsPlugin.groovy
@@ -1,29 +1,24 @@
import grails.util.*

import org.apache.camel.spring.*
import org.apache.camel.model.*
import org.apache.camel.groovy.extend.CamelGroovyMethods
import org.springframework.beans.factory.config.MethodInvokingFactoryBean

import org.apache.camel.model.ChoiceDefinition
import org.apache.camel.model.ProcessorDefinition
import org.grails.plugins.routing.RouteArtefactHandler
import org.grails.plugins.routing.processor.ClosureProcessor
import org.springframework.beans.factory.config.MethodInvokingFactoryBean

class RoutingGrailsPlugin {
def version = '1.2.5'
def grailsVersion = '2.0.0 > *'
def dependsOn = [:]
def loadAfter = [ 'controllers', 'services' ]
def artefacts = [ new RouteArtefactHandler() ]
def loadAfter = ['controllers', 'services']
def artefacts = [new RouteArtefactHandler()]
def author = 'Matthias Hryniszak, Chris Navta'
def authorEmail = 'padcom@gmail.com, chris@ix-n.com'
def documentation = 'http://grails.org/plugin/routing'
def title = 'Routing capabilities using Apache Camel'
def title = 'Apache Camel Plugin'
def description = 'Provides message routing capabilities using Apache Camel'

def doWithSpring = {
def config = application.config.grails.routing
def camelContextId = config?.camelContextId ?: 'camelContext'
def useMDCLogging = config?.useMDCLogging ?: false
def useMDCLogging = config?.useMDCLogging ?: false
def routeClasses = application.routeClasses

initializeRouteBuilderHelpers()
Expand All @@ -34,7 +29,7 @@ class RoutingGrailsPlugin {
"${fullName}Class"(MethodInvokingFactoryBean) {
targetObject = ref("grailsApplication", true)
targetMethod = "getArtefact"
arguments = [ RouteArtefactHandler.ROUTE, fullName ]
arguments = [RouteArtefactHandler.ROUTE, fullName]
}

"${fullName}"(ref("${fullName}Class")) { bean ->
Expand All @@ -45,10 +40,10 @@ class RoutingGrailsPlugin {

xmlns camel:'http://camel.apache.org/schema/spring'

// we don't allow camel autostart regardless to autoStartup value
// this may cause problems if autostarted camel start invoking routes which calls service/controller
// methods, which use dynamically injected methods
// because doWithDynamicMethods is called after doWithSpring
// we don't allow camel autostart regardless to autoStartup value
// this may cause problems if autostarted camel start invoking routes which calls service/controller
// methods, which use dynamically injected methods
// because doWithDynamicMethods is called after doWithSpring
camel.camelContext(id: camelContextId, useMDCLogging: useMDCLogging, autoStartup: false) {
def threadPoolProfileConfig = config?.defaultThreadPoolProfile

Expand All @@ -70,16 +65,17 @@ class RoutingGrailsPlugin {
def doWithDynamicMethods = { ctx ->
def template = ctx.getBean('producerTemplate')

addDynamicMethods(application.controllerClasses, template);
addDynamicMethods(application.serviceClasses, template);
addDynamicMethods(application.controllerClasses, template)
addDynamicMethods(application.serviceClasses, template)

if (isQuartzPluginInstalled(application)) {
addDynamicMethods(application.taskClasses, template)
}

if (isQuartzPluginInstalled(application))
addDynamicMethods(application.taskClasses, template);

// otherwise we autostart camelContext here
if(application.config?.autoStartup ?: true)
application.mainContext('camelContext').start()

// otherwise we autostart camelContext here
if (application.config?.autoStartup ?: true) {
application.mainContext('camelContext').start()
}
}

def watchedResources = [
Expand All @@ -93,7 +89,7 @@ class RoutingGrailsPlugin {
if (artifactName.endsWith('Controller') || artifactName.endsWith('Service')) {
def artifactType = (artifactName.endsWith('Controller')) ? 'controller' : 'service'
def grailsClass = application."${artifactType}Classes".find { it.fullName == artifactName }
addDynamicMethods([ grailsClass ], event.ctx.getBean('producerTemplate'))
addDynamicMethods([grailsClass], event.ctx.getBean('producerTemplate'))
}
}

Expand All @@ -104,23 +100,26 @@ class RoutingGrailsPlugin {
private initializeRouteBuilderHelpers() {
ProcessorDefinition.metaClass.filter = { filter ->
if (filter instanceof Closure) {
CamelGroovyMethods.filter(delegate, filter)
} else
delegate.filter(filter);
CamelGroovyMethods.filter(delegate, filter)
} else {
delegate.filter(filter)
}
}

ChoiceDefinition.metaClass.when = { filter ->
if (filter instanceof Closure) {
CamelGroovyMethods.when(delegate, filter)
} else
delegate.when(filter);
CamelGroovyMethods.when(delegate, filter)
} else {
delegate.when(filter)
}
}

ProcessorDefinition.metaClass.process = { filter ->
if (filter instanceof Closure) {
CamelGroovyMethods.process(delegate, filter)
} else
delegate.process(filter);
CamelGroovyMethods.process(delegate, filter)
} else {
delegate.process(filter)
}
}
}

Expand Down
3 changes: 0 additions & 3 deletions application.properties
@@ -1,4 +1 @@
#Grails Metadata file
#Fri Jan 25 15:02:10 EET 2013
app.grails.version=2.2.3
app.name=routing
18 changes: 6 additions & 12 deletions grails-app/conf/BuildConfig.groovy
@@ -1,20 +1,14 @@
grails.project.work.dir = "target"
grails.project.work.dir = 'target'

def camelVersion = '2.11.1'

grails.project.dependency.resolution = {
inherits("global") {
excludes 'tomcat'
excludes 'hibernate'
}

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

repositories {
grailsPlugins()
grailsHome()
grailsCentral()

mavenLocal()
mavenCentral()
}
Expand All @@ -31,8 +25,8 @@ grails.project.dependency.resolution = {
}

plugins {
build ':release:2.2.1', ':rest-client-builder:1.0.3', {
export = false
}
build ':release:2.2.1', ':rest-client-builder:1.0.3', {
export = false
}
}
}
6 changes: 3 additions & 3 deletions scripts/CreateRoute.groovy
@@ -1,11 +1,11 @@
includeTargets << grailsScript("Init")
includeTargets << grailsScript("_GrailsInit")

target(main: "Creates a new Camel Route.") {
target(createRoute: "Creates a new Camel Route.") {
typeName = "Route"
artifactName = "Route"
artifactPath = "grails-app/routes"

createArtifact()
}

setDefaultTarget(main)
setDefaultTarget(createRoute)
15 changes: 2 additions & 13 deletions scripts/_Install.groovy
@@ -1,19 +1,8 @@
//
// This script is executed by Grails after plugin was installed to project.
// This script is a Gant script so you can use all special variables provided
// by Gant (such as 'baseDir' which points on project base dir). You can
// use 'ant' to access a global instance of AntBuilder
//
// For example you can create directory under project tree:
//
// ant.mkdir(dir:"${basedir}/grails-app/jobs")
//

def routeDir = "${basedir}/grails-app/routes"

if(!(routeDir as File).exists()) {
Ant.mkdir(dir:routeDir)
ant.mkdir(dir:routeDir)

event("CreatedFile", [routeDir])
event("StatusFinal", ["Camel Route directory was created."])
}
@@ -1,7 +1,6 @@
package org.grails.plugins.routing;

import org.codehaus.groovy.grails.commons.AbstractInjectableGrailsClass;
import groovy.lang.Closure;

@SuppressWarnings("rawtypes")
public class DefaultGrailsRouteClass extends AbstractInjectableGrailsClass implements GrailsRouteClass, GrailsRouteClassProperty {
Expand Down
1 change: 0 additions & 1 deletion src/java/org/grails/plugins/routing/GrailsRouteClass.java
@@ -1,7 +1,6 @@
package org.grails.plugins.routing;

import org.codehaus.groovy.grails.commons.InjectableGrailsClass;
import groovy.lang.Closure;

public interface GrailsRouteClass extends InjectableGrailsClass {
}
@@ -1,5 +1,5 @@
package org.grails.plugins.routing;

public interface GrailsRouteClassProperty {
public static final String ROUTE = "Route";
String ROUTE = "Route";
}
@@ -1,10 +1,7 @@
package org.grails.plugins.routing;

import java.lang.reflect.Field;

import org.codehaus.groovy.grails.commons.ArtefactHandlerAdapter;
import org.springframework.util.ReflectionUtils;
import org.apache.camel.builder.RouteBuilder;
import org.codehaus.groovy.grails.commons.ArtefactHandlerAdapter;

@SuppressWarnings("rawtypes")
public class RouteArtefactHandler extends ArtefactHandlerAdapter implements GrailsRouteClassProperty {
Expand Down

0 comments on commit 8aeadbc

Please sign in to comment.