From c9602c99535966400ffc9afa43b68b5019299e4b Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Sun, 7 Jul 2013 11:59:13 -1000 Subject: [PATCH] #58: handle different state machine --- .../packaging/setup/AgentCliPackager.groovy | 3 + .../setup/AgentServerPackager.groovy | 4 ++ .../glu/packaging/setup/BasePackager.groovy | 40 +++++++++++++ .../setup/ConsoleServerPackager.groovy | 5 +- .../groovy/test/setup/BasePackagerTest.groovy | 13 ++++- .../test/setup/TestAgentCliPackager.groovy | 34 +++++++++++ .../metamodel/impl/GluMetaModelImpl.groovy | 5 ++ .../impl/StateMachineMetaModelImpl.groovy | 37 ++++++++++++ .../impl/builder/GluMetaModelBuilder.groovy | 20 +++++++ .../builder/GluMetaModelJsonGroovyDsl.groovy | 2 + .../core/metamodel/GluMetaModel.java | 5 ++ .../core/metamodel/StateMachineMetaModel.java | 29 ++++++++++ .../core/metamodel/TestMetaModel.groovy | 56 +++++++++++++++++++ .../groovy/utils/io/GluGroovyIOUtils.groovy | 29 +++++----- 14 files changed, 265 insertions(+), 17 deletions(-) create mode 100644 provisioner/org.linkedin.glu.provisioner-core/src/main/groovy/org/pongasoft/glu/provisioner/core/metamodel/impl/StateMachineMetaModelImpl.groovy create mode 100644 provisioner/org.linkedin.glu.provisioner-core/src/main/java/org/pongasoft/glu/provisioner/core/metamodel/StateMachineMetaModel.java diff --git a/packaging/org.pongasoft.glu.packaging-setup-impl/src/main/groovy/org/pongasoft/glu/packaging/setup/AgentCliPackager.groovy b/packaging/org.pongasoft.glu.packaging-setup-impl/src/main/groovy/org/pongasoft/glu/packaging/setup/AgentCliPackager.groovy index 82b96fe5..91f54bba 100644 --- a/packaging/org.pongasoft.glu.packaging-setup-impl/src/main/groovy/org/pongasoft/glu/packaging/setup/AgentCliPackager.groovy +++ b/packaging/org.pongasoft.glu.packaging-setup-impl/src/main/groovy/org/pongasoft/glu/packaging/setup/AgentCliPackager.groovy @@ -40,6 +40,9 @@ public class AgentCliPackager extends BasePackager { copyInputPackage(packagePath) configure(packagePath, tokens) + if(metaModel.stateMachine) + generateStateMachineJarFile(metaModel.stateMachine, + packagePath.createRelative('lib')) } return new PackagedArtifact(location: packagePath) diff --git a/packaging/org.pongasoft.glu.packaging-setup-impl/src/main/groovy/org/pongasoft/glu/packaging/setup/AgentServerPackager.groovy b/packaging/org.pongasoft.glu.packaging-setup-impl/src/main/groovy/org/pongasoft/glu/packaging/setup/AgentServerPackager.groovy index b1de1a36..4c075913 100644 --- a/packaging/org.pongasoft.glu.packaging-setup-impl/src/main/groovy/org/pongasoft/glu/packaging/setup/AgentServerPackager.groovy +++ b/packaging/org.pongasoft.glu.packaging-setup-impl/src/main/groovy/org/pongasoft/glu/packaging/setup/AgentServerPackager.groovy @@ -161,6 +161,10 @@ public class AgentServerPackager extends BasePackager copyInputPackage(packagedArtifacts.agentServer.location) Resource serverRoot = configure(packagedArtifacts.agentServer.location, tokens) + if(metaModel.gluMetaModel.stateMachine) + generateStateMachineJarFile(metaModel.gluMetaModel.stateMachine, + serverRoot.createRelative('lib')) + shell.delete(packagedArtifacts.agentServerUpgrade.location) shell.cp(serverRoot, packagedArtifacts.agentServerUpgrade.location) } diff --git a/packaging/org.pongasoft.glu.packaging-setup-impl/src/main/groovy/org/pongasoft/glu/packaging/setup/BasePackager.groovy b/packaging/org.pongasoft.glu.packaging-setup-impl/src/main/groovy/org/pongasoft/glu/packaging/setup/BasePackager.groovy index a74a119c..652e882e 100644 --- a/packaging/org.pongasoft.glu.packaging-setup-impl/src/main/groovy/org/pongasoft/glu/packaging/setup/BasePackager.groovy +++ b/packaging/org.pongasoft.glu.packaging-setup-impl/src/main/groovy/org/pongasoft/glu/packaging/setup/BasePackager.groovy @@ -2,8 +2,10 @@ package org.pongasoft.glu.packaging.setup import org.linkedin.glu.groovy.utils.io.GluGroovyIOUtils import org.linkedin.glu.groovy.utils.shell.Shell +import org.linkedin.groovy.util.ant.AntUtils import org.linkedin.groovy.util.io.GroovyIOUtils import org.linkedin.util.io.resource.Resource +import org.pongasoft.glu.provisioner.core.metamodel.StateMachineMetaModel import org.slf4j.Logger import org.slf4j.LoggerFactory @@ -149,4 +151,42 @@ ${out.join('\n')} } } } + + protected Resource generateStateMachineJarFile(StateMachineMetaModel stateMachineMetaModel, + Resource toFolder) + { + shell.withTempFile { Resource r -> + + def lines = [] + + stateMachineMetaModel.defaultTransitions.transitions.each { state, transitions -> + transitions = transitions + .collect { transition -> "[to: '${transition.to}', action: '${transition.action}']"} + .join(', ') + lines << " '${state}': [${transitions}]" + } + + def content = """ +defaultTransitions = +[ +${lines.join(',\n')} +] + +defaultEntryState = '${stateMachineMetaModel.defaultEntryState}' +""" + + shell.saveContent(r.createRelative('glu/DefaultStateMachine.groovy'), content) + + shell.mkdirs(toFolder) + + Resource jarFile = toFolder.createRelative('glu-state-machine.jar') + + shell.ant { ant -> + ant.jar(destfile: jarFile.file, + basedir: r.file) + } + + return jarFile + } + } } \ No newline at end of file diff --git a/packaging/org.pongasoft.glu.packaging-setup-impl/src/main/groovy/org/pongasoft/glu/packaging/setup/ConsoleServerPackager.groovy b/packaging/org.pongasoft.glu.packaging-setup-impl/src/main/groovy/org/pongasoft/glu/packaging/setup/ConsoleServerPackager.groovy index 87a7d506..8a346ab5 100644 --- a/packaging/org.pongasoft.glu.packaging-setup-impl/src/main/groovy/org/pongasoft/glu/packaging/setup/ConsoleServerPackager.groovy +++ b/packaging/org.pongasoft.glu.packaging-setup-impl/src/main/groovy/org/pongasoft/glu/packaging/setup/ConsoleServerPackager.groovy @@ -78,11 +78,14 @@ public class ConsoleServerPackager extends BasePackager parts << metaModel.version - Resource packagePath =outputFolder.createRelative(parts.join('-')) + Resource packagePath = outputFolder.createRelative(parts.join('-')) if(!dryMode) { copyInputPackage(packagePath) configure(packagePath, tokens) + if(metaModel.gluMetaModel.stateMachine) + generateStateMachineJarFile(metaModel.gluMetaModel.stateMachine, + packagePath.createRelative('glu/repository/plugins')) } return new PackagedArtifact(location: packagePath, host: metaModel.host.resolveHostAddress(), diff --git a/packaging/org.pongasoft.glu.packaging-setup-impl/src/test/groovy/test/setup/BasePackagerTest.groovy b/packaging/org.pongasoft.glu.packaging-setup-impl/src/test/groovy/test/setup/BasePackagerTest.groovy index 9210b620..4371eac0 100644 --- a/packaging/org.pongasoft.glu.packaging-setup-impl/src/test/groovy/test/setup/BasePackagerTest.groovy +++ b/packaging/org.pongasoft.glu.packaging-setup-impl/src/test/groovy/test/setup/BasePackagerTest.groovy @@ -32,6 +32,7 @@ import java.nio.file.Files public abstract class BasePackagerTest extends GroovyTestCase { public static final Object DIRECTORY = new Object() + public static final Object FILE = new Object() public static class BinaryResource { @@ -182,7 +183,17 @@ public abstract class BasePackagerTest extends GroovyTestCase assertEquals("binary content differ for ${r}", rootShell.sha1(expectedValue.resource), rootShell.sha1(r)) else - assertEquals("mismatch content for ${r}", expectedValue, r.file.text) + if(expectedValue instanceof Closure) + { + expectedValue(r) + } + else + { + if(expectedValue.is(FILE)) + assertTrue("${r} is file", !r.isDirectory()) + else + assertEquals("mismatch content for ${r}", expectedValue, r.file.text) + } if(r.path.endsWith('.sh')) assertTrue("${r} is executable", Files.isExecutable(r.file.toPath())) diff --git a/packaging/org.pongasoft.glu.packaging-setup-impl/src/test/groovy/test/setup/TestAgentCliPackager.groovy b/packaging/org.pongasoft.glu.packaging-setup-impl/src/test/groovy/test/setup/TestAgentCliPackager.groovy index 61bc2faa..6f4e7b61 100644 --- a/packaging/org.pongasoft.glu.packaging-setup-impl/src/test/groovy/test/setup/TestAgentCliPackager.groovy +++ b/packaging/org.pongasoft.glu.packaging-setup-impl/src/test/groovy/test/setup/TestAgentCliPackager.groovy @@ -18,6 +18,7 @@ package test.setup import org.linkedin.glu.groovy.utils.shell.Shell import org.linkedin.glu.groovy.utils.shell.ShellImpl +import org.linkedin.util.io.resource.Resource import org.pongasoft.glu.packaging.setup.AgentCliPackager import org.pongasoft.glu.packaging.setup.PackagedArtifact @@ -102,6 +103,16 @@ truststorePassword=nacEn92x8-1 def metaModel = """ fabrics['f1'] = [ : ] +stateMachine = [ + defaultTransitions: [ + NONE: [[to: 's1', action: 'noneTOs1']], + s1: [[to: 'NONE', action: 's1TOnone'], [to: 's2', action: 's1TOs2']], + s2: [[to: 's1', action: 's2TOs1']] + ], + + defaultEntryState: 's2' +] + """ def inputPackage = shell.mkdirs("/dist/org.linkedin.glu.agent-cli-${GLU_VERSION}") @@ -126,6 +137,27 @@ fabrics['f1'] = [ : ] "/README.md": 'this is the readme', "/lib": DIRECTORY, "/lib/acme.jar": 'this is the jar', + "/lib/glu-state-machine.jar": { Resource r -> + shell.withTempFile { Resource t -> + shell.unzip(r, t) + def er2 = [ + '/META-INF': DIRECTORY, + '/META-INF/MANIFEST.MF': FILE, + '/glu': DIRECTORY, + '/glu/DefaultStateMachine.groovy': """ +defaultTransitions = +[ + 'NONE': [[to: 's1', action: 'noneTOs1']], + 's1': [[to: 'NONE', action: 's1TOnone'], [to: 's2', action: 's1TOs2']], + 's2': [[to: 's1', action: 's2TOs1']] +] + +defaultEntryState = 's2' +""" + ] + checkPackageContent(er2, t) + } + }, "/conf": DIRECTORY, "/conf/clientConfig.properties": """# # Copyright (c) 2010-2010 LinkedIn, Inc @@ -159,4 +191,6 @@ sslEnabled=false checkPackageContent(expectedResources, artifact.location) } } + + } \ No newline at end of file diff --git a/provisioner/org.linkedin.glu.provisioner-core/src/main/groovy/org/pongasoft/glu/provisioner/core/metamodel/impl/GluMetaModelImpl.groovy b/provisioner/org.linkedin.glu.provisioner-core/src/main/groovy/org/pongasoft/glu/provisioner/core/metamodel/impl/GluMetaModelImpl.groovy index 7102d7d2..c7f4c6a1 100644 --- a/provisioner/org.linkedin.glu.provisioner-core/src/main/groovy/org/pongasoft/glu/provisioner/core/metamodel/impl/GluMetaModelImpl.groovy +++ b/provisioner/org.linkedin.glu.provisioner-core/src/main/groovy/org/pongasoft/glu/provisioner/core/metamodel/impl/GluMetaModelImpl.groovy @@ -21,6 +21,7 @@ import org.pongasoft.glu.provisioner.core.metamodel.AgentMetaModel import org.pongasoft.glu.provisioner.core.metamodel.ConsoleMetaModel import org.pongasoft.glu.provisioner.core.metamodel.FabricMetaModel import org.pongasoft.glu.provisioner.core.metamodel.GluMetaModel +import org.pongasoft.glu.provisioner.core.metamodel.StateMachineMetaModel import org.pongasoft.glu.provisioner.core.metamodel.ZooKeeperClusterMetaModel /** @@ -30,6 +31,7 @@ public class GluMetaModelImpl implements GluMetaModel public static final String META_MODEL_VERSION = '1.0.0' Map fabrics + StateMachineMetaModel stateMachine String gluVersion String metaModelVersion = META_MODEL_VERSION String zooKeeperRoot = DEFAULT_ZOOKEEPER_ROOT @@ -102,6 +104,9 @@ public class GluMetaModelImpl implements GluMetaModel gluVersion: gluVersion ] + if(stateMachine) + res.stateMachine = stateMachine.toExternalRepresentation() + if(fabrics) res.fabrics = fabrics.collectEntries { k, v -> [k, GluGroovyCollectionUtils.xorMap(v.toExternalRepresentation(), ['name'])] } diff --git a/provisioner/org.linkedin.glu.provisioner-core/src/main/groovy/org/pongasoft/glu/provisioner/core/metamodel/impl/StateMachineMetaModelImpl.groovy b/provisioner/org.linkedin.glu.provisioner-core/src/main/groovy/org/pongasoft/glu/provisioner/core/metamodel/impl/StateMachineMetaModelImpl.groovy new file mode 100644 index 00000000..1513ae7f --- /dev/null +++ b/provisioner/org.linkedin.glu.provisioner-core/src/main/groovy/org/pongasoft/glu/provisioner/core/metamodel/impl/StateMachineMetaModelImpl.groovy @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013 Yan Pujante + * + * 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. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.pongasoft.glu.provisioner.core.metamodel.impl + +import org.linkedin.groovy.util.state.StateMachine +import org.pongasoft.glu.provisioner.core.metamodel.StateMachineMetaModel + +/** + * @author yan@pongasoft.com */ +public class StateMachineMetaModelImpl implements StateMachineMetaModel +{ + StateMachine defaultTransitions + String defaultEntryState + + @Override + def toExternalRepresentation() + { + [ + defaultTransitions: defaultTransitions.transitions, + defaultEntryState: defaultEntryState, + ] + } +} \ No newline at end of file diff --git a/provisioner/org.linkedin.glu.provisioner-core/src/main/groovy/org/pongasoft/glu/provisioner/core/metamodel/impl/builder/GluMetaModelBuilder.groovy b/provisioner/org.linkedin.glu.provisioner-core/src/main/groovy/org/pongasoft/glu/provisioner/core/metamodel/impl/builder/GluMetaModelBuilder.groovy index fc118035..2eb4f33a 100644 --- a/provisioner/org.linkedin.glu.provisioner-core/src/main/groovy/org/pongasoft/glu/provisioner/core/metamodel/impl/builder/GluMetaModelBuilder.groovy +++ b/provisioner/org.linkedin.glu.provisioner-core/src/main/groovy/org/pongasoft/glu/provisioner/core/metamodel/impl/builder/GluMetaModelBuilder.groovy @@ -20,6 +20,7 @@ import com.fasterxml.jackson.core.JsonParseException import org.codehaus.groovy.control.CompilationFailedException import org.linkedin.groovy.util.io.GroovyIOUtils import org.linkedin.groovy.util.json.JsonUtils +import org.linkedin.groovy.util.state.StateMachineImpl import org.linkedin.util.io.resource.Resource import org.pongasoft.glu.provisioner.core.metamodel.GluMetaModel import org.pongasoft.glu.provisioner.core.metamodel.KeysMetaModel @@ -32,6 +33,7 @@ import org.pongasoft.glu.provisioner.core.metamodel.impl.KeyStoreMetaModelImpl import org.pongasoft.glu.provisioner.core.metamodel.impl.KeysMetaModelImpl import org.pongasoft.glu.provisioner.core.metamodel.impl.PhysicalHostMetaModelImpl import org.pongasoft.glu.provisioner.core.metamodel.impl.ServerMetaModelImpl +import org.pongasoft.glu.provisioner.core.metamodel.impl.StateMachineMetaModelImpl import org.pongasoft.glu.provisioner.core.metamodel.impl.ZooKeeperClusterMetaModelImpl import org.pongasoft.glu.provisioner.core.metamodel.impl.ZooKeeperMetaModelImpl @@ -98,10 +100,28 @@ public class GluMetaModelBuilder if(jsonModel.zooKeeperRoot) gluMetaModel.zooKeeperRoot = jsonModel.zooKeeperRoot + // state machine? + gluMetaModel.stateMachine = deserializeStateMachine(jsonModel.stateMachine) + // fabrics jsonModel.fabrics?.each { name, fabricModel -> deserializeFabric(name, fabricModel)} } + StateMachineMetaModelImpl deserializeStateMachine(Map stateMachineModel) + { + if(stateMachineModel) + { + StateMachineImpl stateMachine = + new StateMachineImpl(transitions: stateMachineModel.defaultTransitions) + + return new StateMachineMetaModelImpl(defaultTransitions: stateMachine, + defaultEntryState: stateMachineModel.defaultEntryState) + + } + else + return null + } + /** * Deserialize a fabric */ diff --git a/provisioner/org.linkedin.glu.provisioner-core/src/main/groovy/org/pongasoft/glu/provisioner/core/metamodel/impl/builder/GluMetaModelJsonGroovyDsl.groovy b/provisioner/org.linkedin.glu.provisioner-core/src/main/groovy/org/pongasoft/glu/provisioner/core/metamodel/impl/builder/GluMetaModelJsonGroovyDsl.groovy index bfdedd57..f8748f21 100644 --- a/provisioner/org.linkedin.glu.provisioner-core/src/main/groovy/org/pongasoft/glu/provisioner/core/metamodel/impl/builder/GluMetaModelJsonGroovyDsl.groovy +++ b/provisioner/org.linkedin.glu.provisioner-core/src/main/groovy/org/pongasoft/glu/provisioner/core/metamodel/impl/builder/GluMetaModelJsonGroovyDsl.groovy @@ -26,6 +26,8 @@ public class GluMetaModelJsonGroovyDsl { def binding = new GluMetaModelBinding(metaModelVersion: GluMetaModelImpl.META_MODEL_VERSION, gluVersion: null, + stateMachine: null, + zooKeeperRoot: null, fabrics: [:], agents: [], consoles: [], diff --git a/provisioner/org.linkedin.glu.provisioner-core/src/main/java/org/pongasoft/glu/provisioner/core/metamodel/GluMetaModel.java b/provisioner/org.linkedin.glu.provisioner-core/src/main/java/org/pongasoft/glu/provisioner/core/metamodel/GluMetaModel.java index 39c5180a..12237712 100644 --- a/provisioner/org.linkedin.glu.provisioner-core/src/main/java/org/pongasoft/glu/provisioner/core/metamodel/GluMetaModel.java +++ b/provisioner/org.linkedin.glu.provisioner-core/src/main/java/org/pongasoft/glu/provisioner/core/metamodel/GluMetaModel.java @@ -42,6 +42,11 @@ public interface GluMetaModel extends Externable String getZooKeeperRoot(); + /** + * If you need to redefine the standard state machine (not a typical use case!) + */ + StateMachineMetaModel getStateMachine(); + /** * This is the version of glu */ diff --git a/provisioner/org.linkedin.glu.provisioner-core/src/main/java/org/pongasoft/glu/provisioner/core/metamodel/StateMachineMetaModel.java b/provisioner/org.linkedin.glu.provisioner-core/src/main/java/org/pongasoft/glu/provisioner/core/metamodel/StateMachineMetaModel.java new file mode 100644 index 00000000..96f4b57b --- /dev/null +++ b/provisioner/org.linkedin.glu.provisioner-core/src/main/java/org/pongasoft/glu/provisioner/core/metamodel/StateMachineMetaModel.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013 Yan Pujante + * + * 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. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.pongasoft.glu.provisioner.core.metamodel; + +import org.linkedin.glu.utils.core.Externable; +import org.linkedin.groovy.util.state.StateMachine; + +/** + * @author yan@pongasoft.com + */ +public interface StateMachineMetaModel extends Externable +{ + StateMachine getDefaultTransitions(); + String getDefaultEntryState(); +} diff --git a/provisioner/org.linkedin.glu.provisioner-core/src/test/groovy/test/provisioner/core/metamodel/TestMetaModel.groovy b/provisioner/org.linkedin.glu.provisioner-core/src/test/groovy/test/provisioner/core/metamodel/TestMetaModel.groovy index 4358d3b8..dcc3793a 100644 --- a/provisioner/org.linkedin.glu.provisioner-core/src/test/groovy/test/provisioner/core/metamodel/TestMetaModel.groovy +++ b/provisioner/org.linkedin.glu.provisioner-core/src/test/groovy/test/provisioner/core/metamodel/TestMetaModel.groovy @@ -45,6 +45,62 @@ public class TestMetaModel extends GroovyTestCase checkJson(model, expectedModel) } + /** + * Test that system wide global values work + */ + public void testGlobalValues() + { + def model = """{ + "gluVersion": "x.y.z", + "zooKeeperRoot": "/acme", + "stateMachine": { + "defaultTransitions": { + "NONE": [{"to": "s1", "action": "noneTOs1"}], + "s1": [{"to": "NONE", "action": "s1TOnone"}, {"to": "s2", "action": "s1TOs2"}], + "s2": [{"to": "s1", "action": "s2TOs1"}] + }, + "defaultEntryState": "s2" + } +}""" + + def expectedModel = """ +{ + "gluVersion": "x.y.z", + "metaModelVersion": "1.0.0", + "stateMachine": { + "defaultEntryState": "s2", + "defaultTransitions": { + "NONE": [ + { + "action": "noneTOs1", + "to": "s1" + } + ], + "s1": [ + { + "action": "s1TOnone", + "to": "NONE" + }, + { + "action": "s1TOs2", + "to": "s2" + } + ], + "s2": [ + { + "action": "s2TOs1", + "to": "s1" + } + ] + } + }, + "zooKeeperRoot": "/acme" +} +""" + + checkJson(model, expectedModel) + } + /** * This represents a model similar to the tutorial */ diff --git a/utils/org.linkedin.glu.utils/src/main/groovy/org/linkedin/glu/groovy/utils/io/GluGroovyIOUtils.groovy b/utils/org.linkedin.glu.utils/src/main/groovy/org/linkedin/glu/groovy/utils/io/GluGroovyIOUtils.groovy index 3e41bf2d..385e9df1 100644 --- a/utils/org.linkedin.glu.utils/src/main/groovy/org/linkedin/glu/groovy/utils/io/GluGroovyIOUtils.groovy +++ b/utils/org.linkedin.glu.utils/src/main/groovy/org/linkedin/glu/groovy/utils/io/GluGroovyIOUtils.groovy @@ -69,24 +69,23 @@ public class GluGroovyIOUtils extends GroovyIOUtils static Resource compileAndJar(FileSystem fs, def sources, def jar, def classpath = null) { def cc = new CompilerConfiguration() - cc.targetDirectory = fs.createTempDir().file - if(classpath) - cc.classpathList = classpath.collect { toFile(it).canonicalPath } - CompilationUnit cu = new CompilationUnit(cc) - sources.each { - cu.addSource(toFile(it)) - } - cu.compile() + fs.withTempFile { Resource targetDirectory -> + cc.targetDirectory = fs.mkdirs(targetDirectory).file + if(classpath) + cc.classpathList = classpath.collect { toFile(it).canonicalPath } + CompilationUnit cu = new CompilationUnit(cc) + sources.each { + cu.addSource(toFile(it)) + } + cu.compile() - Resource jarFile = fs.toResource(jar) + Resource jarFile = fs.toResource(jar) - AntUtils.withBuilder { ant -> - ant.jar(destfile: jarFile.file, basedir: cc.targetDirectory) + AntUtils.withBuilder { ant -> + ant.jar(destfile: jarFile.file, basedir: cc.targetDirectory) + } + return jarFile } - - fs.rmdirs(cc.targetDirectory) - - return jarFile }