/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ // // $Id$ // package buildharness import buildharness.util.* class BuildHarness { /** The package where command classes live */ static final def COMMANDS_PACKAGE = "buildharness.commands" /** Nested Groovy shell for evaluate expressions */ def shell = new GroovyShell(this.class.classLoader) /** Build context */ def context public BuildHarness(script) { this.context = new BuildContext(script) } def run() { def name = context.getRequired('command') while (true) { try { execute(name) // If we get this far, we did not forward, so exit the loop break } catch (ForwardNotification n) { name = n.name println "Forwarding to: ${name}" } } } def execute(name) { Line.display() println "Command: ${name}" def command try { command = shell.evaluate("new ${COMMANDS_PACKAGE}.${name}()") } catch (Exception e) { command = shell.evaluate("new ${name}()") } println "Command instance: ${command}" // Dump the environemnt context.dumpProperties() Line.display() command.init(context) command.execute() } static def bootstrap(script) { def exitn try { new BuildHarness(script).run() } catch (ExitNotification n) { exitn = n } catch (Throwable t) { Line.display() // Dump for debugging purposes t.printStackTrace() exitn = new ExitNotification(cause: t) } Line.display(false) if (exitn != null) { script.ant.fail(message: exitn as String) } } }