Skip to content

Commit

Permalink
Merge pull request #23 from kefirfromperm/master
Browse files Browse the repository at this point in the history
Merge all latest changes.
  • Loading branch information
rvanderwerf committed Nov 4, 2013
2 parents 9525905 + bb25546 commit fa6e876
Show file tree
Hide file tree
Showing 25 changed files with 230 additions and 371 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ target-eclipse

# Unused grails files
grails-app/i18n/

plugin.xml
64 changes: 37 additions & 27 deletions QuartzGrailsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,26 @@
* limitations under the License.
*/

import grails.plugins.quartz.*
import grails.plugins.quartz.GrailsJobClassConstants as Constants
import grails.plugins.quartz.CustomTriggerFactoryBean
import grails.plugins.quartz.GrailsJobClass
import grails.plugins.quartz.GrailsJobFactory
import grails.plugins.quartz.JobArtefactHandler
import grails.plugins.quartz.JobDetailFactoryBean
import grails.plugins.quartz.TriggerUtils
import grails.plugins.quartz.listeners.ExceptionPrinterJobListener
import grails.plugins.quartz.listeners.SessionBinderJobListener
import grails.spring.BeanBuilder
import grails.util.Environment

import org.codehaus.groovy.grails.commons.spring.GrailsApplicationContext
import org.quartz.*
import org.quartz.JobDataMap
import org.quartz.JobDetail
import org.quartz.JobKey
import org.quartz.ListenerManager
import org.quartz.Scheduler
import org.quartz.SimpleTrigger
import org.quartz.Trigger
import org.quartz.TriggerKey
import org.quartz.impl.matchers.KeyMatcher
import org.quartz.spi.MutableTrigger
import org.slf4j.Logger
Expand All @@ -30,11 +42,8 @@ import org.springframework.beans.factory.config.MethodInvokingFactoryBean
import org.springframework.context.ApplicationContext
import org.springframework.scheduling.quartz.SchedulerFactoryBean

import grails.plugins.quartz.TriggerUtils

/**
* A plug-in that configures Quartz job support for Grails.
*
* Configures Quartz job support.
*
* @author Graeme Rocher
* @author Marcel Overdijk
Expand All @@ -44,20 +53,22 @@ import grails.plugins.quartz.TriggerUtils
*/
class QuartzGrailsPlugin {

def version = "1.0-RC11"
def version = "1.0"
def grailsVersion = "2.0 > *"

def author = "Sergey Nebolsin, Graeme Rocher, Ryan Vanderwerf, Vitalii Samolovskikh"
def authorEmail = "[email protected]"
def title = "Quartz plugin for Grails"
def description = '''\
This plugin adds Quartz job scheduling features to Grails application.
'''
def description = 'Adds Quartz job scheduling features'
def documentation = "http://grails.org/plugin/quartz"
def pluginExcludes = ['grails-app/jobs/**']
def pluginExcludes = [
'grails-app/jobs/**',
'src/docs/**',
'web-app/**'
]

def license = "APACHE"
def issueManagement = [system: "GitHub Issues", url: "http://jira.grails.org/browse/GPQUARTZ"]
def issueManagement = [system: "JIRA", url: "http://jira.grails.org/browse/GPQUARTZ"]
def scm = [url: "http://github.com/grails-plugins/grails-quartz"]

def loadAfter = ['core', 'hibernate', 'datasources']
Expand Down Expand Up @@ -169,7 +180,7 @@ This plugin adds Quartz job scheduling features to Grails application.
* Adds schedule methods for job classes.
*/
private static void addMethods(tc, ctx) {
Scheduler quartzScheduler = ctx.getBean('quartzScheduler')
Scheduler quartzScheduler = ctx.quartzScheduler
def mc = tc.metaClass
String jobName = tc.getFullName()
String jobGroup = tc.getGroup()
Expand Down Expand Up @@ -243,23 +254,22 @@ This plugin adds Quartz job scheduling features to Grails application.
* Schedules jobs. Creates job details and trigger beans. And schedules them.
*/
def scheduleJob(GrailsJobClass jobClass, ApplicationContext ctx, boolean hasHibernate) {
Scheduler scheduler = ctx.getBean("quartzScheduler") as Scheduler
Scheduler scheduler = ctx.quartzScheduler
if (scheduler) {
def fullName = jobClass.fullName

// Creates job details
JobDetailFactoryBean jdfb = new JobDetailFactoryBean();
JobDetailFactoryBean jdfb = new JobDetailFactoryBean()
jdfb.jobClass = jobClass
jdfb.afterPropertiesSet()
JobDetail jobDetail = jdfb.object

// adds the job to the scheduler, and associates triggers with it
scheduler.addJob(jobDetail, true);
scheduler.addJob(jobDetail, true)

// The session listener if is needed
if (hasHibernate && jobClass.sessionRequired) {
SessionBinderJobListener listener =
ctx.getBean("${SessionBinderJobListener.NAME}") as SessionBinderJobListener
SessionBinderJobListener listener = ctx.getBean(SessionBinderJobListener.NAME)
if (listener != null) {
ListenerManager listenerManager = scheduler.getListenerManager()
KeyMatcher<JobKey> matcher = KeyMatcher.keyEquals(jobDetail.key)
Expand All @@ -275,7 +285,7 @@ This plugin adds Quartz job scheduling features to Grails application.

// Creates and schedules triggers
jobClass.triggers.each { name, Expando descriptor ->
CustomTriggerFactoryBean factory = new CustomTriggerFactoryBean();
CustomTriggerFactoryBean factory = new CustomTriggerFactoryBean()
factory.triggerClass = descriptor.triggerClass
factory.triggerAttributes = descriptor.triggerAttributes
factory.jobDetail = jobDetail
Expand Down Expand Up @@ -304,7 +314,7 @@ This plugin adds Quartz job scheduling features to Grails application.
log.debug("Job ${event.source} changed. Reloading...")

GrailsApplicationContext context = event.ctx
def scheduler = context?.getBean("quartzScheduler")
def scheduler = context?.quartzScheduler

GrailsJobClass jobClass = application.getJobClass(event.source?.name)

Expand All @@ -314,15 +324,15 @@ This plugin adds Quartz job scheduling features to Grails application.

// get quartz scheduler
if (context && scheduler) {
// if job already exists, delete it from scheduler
// if job already exists, delete it from scheduler
if (jobClass) {
def jobKey = new JobKey(jobClass.fullName, jobClass.group)
scheduler.deleteJob(jobKey)
log.debug("Job ${jobClass.fullName} deleted from the scheduler")
}

// add job artifact to application
jobClass = application.addArtefact(JobArtefactHandler.TYPE, event.source as Class) as GrailsJobClass
jobClass = application.addArtefact(JobArtefactHandler.TYPE, event.source as Class)

def fullName = jobClass.fullName
boolean hasHibernate = manager?.hasGrailsPlugin("hibernate")
Expand All @@ -337,25 +347,25 @@ This plugin adds Quartz job scheduling features to Grails application.
context.registerBeanDefinition("${fullName}", beans.getBeanDefinition("${fullName}"))

// Reschedule jobs
scheduleJob(jobClass as GrailsJobClass, event.ctx as ApplicationContext, hasHibernate)
scheduleJob(jobClass, event.ctx, hasHibernate)
} else {
log.error("Application context or Quartz Scheduler not found. Can't reload Quartz plugin.")
}
}
}

/*
* Load the various configs.
* Load the various configs.
* Order of priority has been "fixed" in 1.0-RC2 to be:
*
* 1. DefaultQuartzConfig is loaded
* 1. DefaultQuartzConfig is loaded
* 2. App's Config.groovy is loaded in and overwrites anything from DQC
* 3. QuartzConfig is loaded and overwrites anything from DQC or AppConfig
* 4. quartz.properties are loaded into config as quartz._props
*/
private ConfigObject loadQuartzConfig(ConfigObject config) {
def classLoader = new GroovyClassLoader(getClass().classLoader)
String environment = Environment.current.toString()
String environment = Environment.current.name

// Note here the order of objects when calling merge - merge OVERWRITES values in the target object
// Load default Quartz config as a basis
Expand Down
6 changes: 3 additions & 3 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
= Grails Quartz Plugin http://stillmaintained.com/nebolsin/grails-quartz.png

This plugin has been updated to run on Quartz 2.1.x and no longer runs on Quartz 1.8.x. The newer
This plugin has been updated to run on Quartz 2.2.x and no longer runs on Quartz 1.8.x. The newer
version of Quartz will also allow it to be used With Terrcotta 3.6 or later (I tested on 3.7) - Ryan

This is different than the quartz2 plugin others maintain, because it does not use JobDetailsImpl, that one will
Expand All @@ -13,9 +13,9 @@ configured via {Spring}[http://www.springsource.org/about], but is made simpler

== Installation

To install the latest stable version of the plugin run:
To install the latest stable version of the plugin add this to your BuildConfig.groovy in the plugins section (be sure to use the latest version):

grails install-plugin quartz
compile ':quartz:1.0-RC11'

== Using

Expand Down
3 changes: 0 additions & 3 deletions application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
#Grails Metadata file
#Tue Oct 01 23:31:25 CDT 2013
app.grails.version=2.3.0
app.name=quartz
app.servlet.version=2.5
15 changes: 7 additions & 8 deletions grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
grails.project.source.level = 1.6
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.work.dir = "target"

grails.project.dependency.resolution = {
inherits "global"
Expand All @@ -13,13 +10,15 @@ grails.project.dependency.resolution = {
mavenCentral()
}

plugins {
build ":release:3.0.1", { export = false }
}

dependencies {
compile("org.quartz-scheduler:quartz:2.2.0") {
excludes 'slf4j-api', 'c3p0'
}
}

plugins {
build ':release:3.0.1', ':rest-client-builder:1.0.3', {
export = false
}
}
}
26 changes: 0 additions & 26 deletions plugin.xml

This file was deleted.

49 changes: 15 additions & 34 deletions scripts/CreateJob.groovy
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2006-2008 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -22,39 +22,20 @@
* @since 0.2
*/

Ant.property(environment: "env")
grailsHome = Ant.antProject.properties."env.GRAILS_HOME"



if (grails.util.GrailsUtil.grailsVersion.startsWith("1.0")) {
includeTargets << new File("${grailsHome}/scripts/Init.groovy")
includeTargets << new File("${grailsHome}/scripts/CreateIntegrationTest.groovy")
includeTargets << grailsScript("_GrailsInit")
includeTargets << grailsScript("_GrailsCreateArtifacts")

target('default': "Creates a new Quartz scheduled job") {
depends(checkVersion)
target(createJob: "Creates a new Quartz scheduled job") {
depends(checkVersion, parseArguments)

typeName = "Job"
artifactName = "Job"
artifactPath = "grails-app/jobs"
def type = "Job"
promptForName(type: type)

createArtifact()
createTestSuite()
}
} else {
includeTargets << grailsScript("_GrailsInit")
includeTargets << grailsScript("_GrailsCreateArtifacts")

target('default': "Creates a new Quartz scheduled job") {
depends(checkVersion, parseArguments)

def type = "Job"
promptForName(type: type)

for (name in argsMap["params"]) {
name = purgeRedundantArtifactSuffix(name, type)
createArtifact(name: name, suffix: type, type: type, path: "grails-app/jobs")
createUnitTest(name: name, suffix: type)
}
for (name in argsMap["params"]) {
name = purgeRedundantArtifactSuffix(name, type)
createArtifact(name: name, suffix: type, type: type, path: "grails-app/jobs")
createUnitTest(name: name, suffix: type)
}
}

setDefaultTarget 'createJob'
24 changes: 8 additions & 16 deletions scripts/InstallQuartzConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,14 @@
* @since 0.3
*/

if(grails.util.GrailsUtil.grailsVersion.startsWith("1.0")) {
includeTargets << new File ( "${grailsHome}/scripts/Init.groovy" )
includeTargets << new File( "${grailsHome}/scripts/CreateIntegrationTest.groovy")
} else {
includeTargets << grailsScript("_GrailsInit")
includeTargets << grailsScript("_GrailsCreateArtifacts")
includeTargets << grailsScript("_GrailsInit")
includeTargets << grailsScript("_GrailsCreateArtifacts")

}

target('default': "Installs Quartz config in the /grails-app/conf/ directory") {
installQuartzConfig()
}

target(installQuartzConfig: "The implementation task") {
target(installQuartzConfig: "Installs Quartz config in the /grails-app/conf/ directory") {
depends(checkVersion)
def configFile = "${basedir}/grails-app/conf/QuartzConfig.groovy"
if(!(configFile as File).exists() || confirmInput("Quartz config file already exists in your project. Overwrite it?")) {
Ant.copy(
ant.copy(
file:"${quartzPluginDir}/grails-app/conf/DefaultQuartzConfig.groovy",
tofile:configFile,
overwrite: true
Expand All @@ -50,6 +40,8 @@ target(installQuartzConfig: "The implementation task") {
}

confirmInput = {String message ->
Ant.input(message: message, addproperty: "confirm.message", validargs: "y,n")
Ant.antProject.properties."confirm.message" == "y"
ant.input(message: message, addproperty: "confirm.message", validargs: "y,n")
ant.antProject.properties."confirm.message" == "y"
}

setDefaultTarget 'installQuartzConfig'
2 changes: 1 addition & 1 deletion scripts/_Install.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
* @since 0.2
*/

Ant.mkdir(dir:"${basedir}/grails-app/jobs")
ant.mkdir(dir:"${basedir}/grails-app/jobs")
2 changes: 1 addition & 1 deletion scripts/_Upgrade.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
*/

// ensure that there are 'jobs' directory under application 'grails-app'
Ant.mkdir(dir:"${basedir}/grails-app/jobs")
ant.mkdir(dir:"${basedir}/grails-app/jobs")
Loading

0 comments on commit fa6e876

Please sign in to comment.