Skip to content

Commit

Permalink
Merge pull request #1 from marcpalmer/182e760915365cebfb57b4a137775d5…
Browse files Browse the repository at this point in the history
…3cb417799

Fix for DefaultQuartzConfig values not being overridden by app Config
  • Loading branch information
graemerocher committed May 24, 2012
2 parents 2a78759 + 182e760 commit 32734a4
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions QuartzGrailsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -274,20 +274,37 @@ This plugin adds Quartz job scheduling features to Grails application.
}
}

/*
* Load the various configs.
* Order of priority has been "fixed" in 1.0-RC2 to be:
*
* 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() {
def config = ConfigurationHolder.config
def classLoader = new GroovyClassLoader(getClass().classLoader)

// merging default Quartz config into main application config
config.merge(new ConfigSlurper(GrailsUtil.environment).parse(classLoader.loadClass('DefaultQuartzConfig')))
// Note here the order of objects when calling merge - merge OVERWRITES values in the target object
// Load default Quartz config as a basis
def newConfig = new ConfigSlurper(GrailsUtil.environment).parse(classLoader.loadClass('DefaultQuartzConfig'))

// merging user-defined Quartz config into main application config if provided
// Overwrite defaults with what Config.groovy has supplied, perhaps from external files
newConfig.merge(config)

// Overwrite with contents of QuartzConfig
try {
config.merge(new ConfigSlurper(GrailsUtil.environment).parse(classLoader.loadClass('QuartzConfig')))
newConfig.merge(new ConfigSlurper(GrailsUtil.environment).parse(classLoader.loadClass('QuartzConfig')))
} catch (Exception ignored) {
// ignore, just use the defaults
}

// Now merge our correctly merged DefaultQuartzConfig and QuartzConfig into the main config
config.merge(newConfig)

// And now load quartz properties into main config
def properties = new Properties()
def resource = classLoader.getResourceAsStream("quartz.properties")
if (resource != null) {
Expand Down

0 comments on commit 32734a4

Please sign in to comment.