/* * 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 class BuildContext { /** The invoking script reference */ def script /** Internal ant environment */ def ant = new AntBuilder() /** Overridded properties. */ def overrides = [:] public BuildContext(script) { assert script != null this.script = script // Replace the default listener with the enclosing listener from ant via the script reference // This is to prevent duplicate processing, which results in extra new lines :-( def p = ant.antProject p.removeBuildListener(p.buildListeners[0]) p.addBuildListener(script.ant.antProject.buildListeners[0]) } def resolveFile(path) { def file = new File(path) // TODO: Maybe need to resolve this puppy relative to ${basedir} return file.canonicalFile } def fail(msg, cause=null) { throw new ExitNotification(message: msg, cause: cause) } def forward(name) { throw new ForwardNotification(name: name) } def dumpProperties() { println 'Properties:' def props = [:] props.putAll(script.properties) props.putAll(overrides) props.keySet().sort().each { println " ${it}=" + props[it] } } def set(name, value) { assert name != null overrides[name] = value } def getInternal(name) { if (overrides.containsKey(name)) { return overrides[name] } else { return script.properties[name] } } def get(name, defaultValue=null) { assert name != null def value = getInternal(name) if (value == null) { return defaultValue } else { return value } } def getAsInt(name, defaultValue=-1) { def value = get(name) if (value == null) { return defaultValue } else { return Integer.parseInt(value) } } def getAsFile(name) { def value = get(name) return resolveFile(value) } def getRequired(name) { def value = get(name) assert value != null : "Missing required property: ${name}" return value } def getRequiredAsInt(name) { def value = getRequired(name) return Integer.parseInt(value) } def getRequiredAsFile(name) { def value = getRequired(name) return resolveFile(value) } }