All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openscm.kundo.plugins.PrepareDelegate.groovy Maven / Gradle / Ivy

The newest version!
package org.openscm.kundo.plugins

/*
 * Copyright (C) 2008 The Ultimate People Company Ltd ("UPCO").
 *
 * 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.
 */

import org.openscm.kundo.plugins.context.BuildContext
import org.openscm.kundo.common.logging.SimpleLogger

/**
 * Prepare Delegate
 * @author Nigel Garner
 * @version 1.0.0
 * 
 * Description: A Prepare Delegate that prepares a series of directories that have been loaded from 
 * either the plugin's default plugin.properties or the project's build.properties.
 * 
 * 

The delegate performs a two phases preparation: * 1 - All of the output directories are prepared from global indexed project properties * 2 - A generic list of directories from the comma delimited prepare.paths property are created

*/ /* * @ant-target doPrepare */ class PrepareDelegate extends AbstractPluginTargetDelegate { /* * a comma separated list of paths to prepare additional to previously global project paths * @ant-property-name prepare.paths */ private String paths /** * Constructor sets ant and buildContext instances in super class * @param ant AntBuilder instance * @param buildContext BuildContext instance */ PrepareDelegate( AntBuilder ant, BuildContext buildContext ){ super( ant, buildContext) } /** * Implementation of abstract method from AbstractPluginTargetDelegate * to hold assertions that all global and local properties are available to the plugin. * This method is automatically called prior to execution. */ void doCheck(){ assert paths != null assert buildContext.get( "project.properties" ) != null } /** * Injector for Paths element */ void setPaths( String paths ){ this.paths = paths } /** * Private method for creating generic paths * @param paths - List of string paths to be created */ def prepare( paths ) { // For each path in the list, prepare the source and output dir paths.each{ path -> // Log what we are going to do. if ( log.isDebugEnabled() ) log.debug( "Preparing to create directory: $path" ) ant.mkdir( dir:path ) } } /** * Private method for creating indexed paths retrieved from the project properties * @param paths - List of dynamic objects containing output paths to be created */ def prepareIndexedPaths( paths ) { // For each Expando in the list paths.each{ path -> // Check to see if there is a specified output directory if (path.output != null ) { // Log what we are going to do. if ( log.isDebugEnabled() ) log.debug( "Preparing to create indexed ouput directory: $path.output" ) // Create the directory ant.mkdir( dir:path.output ) } } } /** * Concrete implementation of the AbstractDelegate.execute() method */ void doExecute(){ // Step 1 - Prepare Indexed Paths // Retrieve the indexed project properties from the global context if ( log.isDebugEnabled() ) log.debug( "Preparing to process indexed directory from buildContext" ) Map properties = buildContext.get( "project.properties" ) if ( log.isDebugEnabled() ) log.debug( "Project properties retrieved from build context as $properties" ) // For each keyed path set properties.each { key, value -> // prepare the paths prepareIndexedPaths( value ) } // Step 2 - Prepare Generic Paths // Take the injected set of paths. Must be comma delimited.. if ( log.isDebugEnabled() ) log.debug( "Preparing to process injected directory property from prepare.paths" ) if( paths != null ) { // Split the generic project paths and process prepare( paths.split( ',' ) ) } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy