/src/main/groovy/com/onresolve/jira/groovy/JiraGroovyResourceLoader.groovy
Groovy | 48 lines | 32 code | 10 blank | 6 comment | 5 complexity | 316b607f3f329a16f713755f2f6e87d3 MD5 | raw file
- package com.onresolve.jira.groovy;
-
-
- import com.atlassian.jira.util.BuildUtils
- import java.util.regex.Matcher
- import org.apache.log4j.Category
-
- public class JiraGroovyResourceLoader implements GroovyResourceLoader {
-
- ClassLoader gcl
- ScriptManager scriptManager
- Category log = Category.getInstance(this.class)
-
- JiraGroovyResourceLoader(ClassLoader gcl, ScriptManager scriptManager) {
- this.gcl = gcl
- this.scriptManager = scriptManager
- }
-
- public URL loadGroovySource(String filename) throws MalformedURLException {
- // log.debug "load class with name $filename"
-
- // the way to make this whole process a bit faster is not to use strong typing, I think
-
- Properties props = scriptManager.getProperties()
- Long currentBuildNumber = BuildUtils.getCurrentBuildNumber() as Long
- String origFilename = filename
- props.each {
- Matcher matcher = (it.key =~ /${filename}\.(\d+)\.to\.(\d+)$/)
- if (matcher.matches()) {
- // log.debug ("Matched ${it.key}")
- Long minVersion = matcher[0][1] as Long
- Long maxVersion = matcher[0][2] as Long
-
- // todo: check the timestamp for files that don't match their class against cls.getField(Verifier.__TIMESTAMP);
- // see GroovyClassLoader.java
- // or write a custom classloader
- if (currentBuildNumber >= minVersion && (maxVersion == 0 || currentBuildNumber <= maxVersion)) {
- filename = it.value.replaceAll(/\.groovy$/, "").replaceAll("/", ".")
- log.debug ("Modifying resource from $origFilename to $filename for current build $currentBuildNumber - has range min: $minVersion max: $maxVersion")
- }
- }
- }
-
- def convertedName = filename.replaceAll(/\./, "/") + ".groovy"
- URL resource = gcl.getResource(convertedName)
- return resource;
- }
- }