Skip to content

Commit

Permalink
group requests that share the same classpath
Browse files Browse the repository at this point in the history
  • Loading branch information
sheehan committed Mar 14, 2016
1 parent 6c4068f commit a3b7675
Showing 1 changed file with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,30 @@ class DslScriptLoader {

// Otherwise baseScript won't take effect
GroovyClassLoader groovyClassLoader = new GroovyClassLoader(parentClassLoader, config)
GroovyScriptEngine engine

try {
URL[] urlRoots = scriptRequests*.urlRoots.flatten().unique()
engine = new GroovyScriptEngine(urlRoots, groovyClassLoader)
engine.config = config
runScriptsWithClassLoader(scriptRequests, groovyClassLoader, config)
} finally {
if (groovyClassLoader instanceof Closeable) {
((Closeable) groovyClassLoader).close()
}
}
}

Binding binding = createBinding()
private GeneratedItems runScriptsWithClassLoader(Collection<ScriptRequest> scriptRequests,
GroovyClassLoader groovyClassLoader,
CompilerConfiguration config) {
GeneratedItems generatedItems = new GeneratedItems()

GeneratedItems generatedItems = new GeneratedItems()
scriptRequests.each { ScriptRequest scriptRequest ->
JobParent jobParent = runScript(scriptRequest, engine, binding)
// group requests that share the same classpath
scriptRequests.groupBy { it.urlRoots*.toString().sort() }.values().each { List<ScriptRequest> requestSet ->
GroovyScriptEngine engine
try {
engine = new GroovyScriptEngine(requestSet.first().urlRoots, groovyClassLoader)
engine.config = config

requestSet.each { ScriptRequest scriptRequest ->
JobParent jobParent = runScript(scriptRequest, engine)

boolean ignoreExisting = scriptRequest.ignoreExisting
generatedItems.configFiles.addAll(extractGeneratedConfigFiles(jobParent, ignoreExisting))
Expand All @@ -64,19 +77,19 @@ class DslScriptLoader {
scheduleJobsToRun(jobParent.queueToBuild)
}

return generatedItems
} finally {
if (engine?.groovyClassLoader instanceof Closeable) {
((Closeable) engine.groovyClassLoader).close()
}
if (groovyClassLoader instanceof Closeable) {
((Closeable) groovyClassLoader).close()
} finally {
if (engine?.groovyClassLoader instanceof Closeable) {
((Closeable) engine.groovyClassLoader).close()
}
}
}
generatedItems
}

private JobParent runScript(ScriptRequest scriptRequest, GroovyScriptEngine engine, Binding binding) {
private JobParent runScript(ScriptRequest scriptRequest, GroovyScriptEngine engine) {
LOGGER.log(Level.FINE, String.format("Request for ${scriptRequest.location}"))

Binding binding = createBinding()
try {
Script script
if (scriptRequest.body != null) {
Expand Down

0 comments on commit a3b7675

Please sign in to comment.