diff options
author | Matth?us G. Chajdas <dev@anteru.net> | 2019-11-10 13:56:53 +0100 |
---|---|---|
committer | Matth?us G. Chajdas <dev@anteru.net> | 2019-11-10 13:56:53 +0100 |
commit | 1dd3124a9770e11b6684e5dd1e6bc15a0aa3bc67 (patch) | |
tree | 87a171383266dd1f64196589af081bc2f8e497c3 /tests/examplefiles/test.groovy | |
parent | f1c080e184dc1bbc36eaa7cd729ff3a499de568a (diff) | |
download | pygments-master.tar.gz |
Diffstat (limited to 'tests/examplefiles/test.groovy')
-rw-r--r-- | tests/examplefiles/test.groovy | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/tests/examplefiles/test.groovy b/tests/examplefiles/test.groovy deleted file mode 100644 index 903863d2..00000000 --- a/tests/examplefiles/test.groovy +++ /dev/null @@ -1,97 +0,0 @@ -// This source code comes from http://www.odelia-technologies.com/node/200 - -package com.odelia.groovy.simpleworkflow - - -class SimpleWorkflowEngine { - def workflowMap = [:] - def context = [:] - def beforeActivityName = 'beforeActivity' - def afterActivityName = 'afterActivity' - - SimpleWorkflowEngine(workflow, context = [:]) { - this.context = context - parseWorkflow(workflow) - } - - def parseWorkflow(workflow) { - workflowMap = new WorkflowParser().parse(workflow) - } - - def getActivityValue(activity) { - assert activity instanceof String - if (!workflowMap[activity]) - throw new RuntimeException("$activity activity doesn't exist") - workflowMap[activity] - } - - def execute(activity, pause) { - if (workflowMap[beforeActivityName]) { - getActivityValue(beforeActivityName)(context, activity) - } - - def activityValue = getActivityValue(activity) - - // Determine the next activity to execute - def nextActivity - switch (activityValue) { - case String: nextActivity = activityValue; break - case Closure: nextActivity = activityValue(context); break - case Class: nextActivity = activityValue.newInstance()(context) - } - - if (workflowMap[afterActivityName]) { - getActivityValue(afterActivityName)(context, activity, nextActivity) - } - - if (!pause && nextActivity) - call(nextActivity) - else - nextActivity - } - - def call(activity) { - execute(activity, false) - } - - def nextActivity(activity) { - execute(activity, true) - } - - static void main(String[] args) { - if (args.size() != 2) { - println 'Usage: com.odelia.groovy.simpleworkflow.SimpleWorkflowEngine <dsl_filename> <activity_name>' - return - } - SimpleWorkflowEngine.newInstance(new File(args[0]))(args[1]) - } - -} - -private class WorkflowParser { - def map = [:] - - def methodMissing(String name, args) { - map[name] = args[0] - } - - def parse(Closure wf) { - wf.delegate = this - wf.resolveStrategy = Closure.DELEGATE_FIRST - wf() - map - } - - def workflow = { it -> - it.delegate = this - it.resolveStrategy = Closure.DELEGATE_FIRST - it() - } - - def parse(File workflowDef) { - def binding = new Binding([workflow: workflow]) - def shell = new GroovyShell(binding) - shell.evaluate(workflowDef) - map - } -}
\ No newline at end of file |