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

org.openscm.kundo.plugins.AbstractResourceDelegate.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

/**
 * Abstract Resource Delegate
 * @author Nigel Garner
 * @version 1.0.0
 * 
 * Description: A Resource Delegate to manage the resource files specified in the project metadata.
 * 
 * 

The resource delegate consumes data set by the kundo-project-plugin and uses each resource set. The delegate * copies the files from the specified dir to the appropriate output dir, applying any include/exclude filters in the process.

*/ /* * @ant-target doResources and doTestResources */ abstract class AbstractResourceDelegate extends AbstractPluginTargetDelegate { /* * The name of the key which resources will be grouped by. * @ant-property-name resource.key * @ant-property-name resource.test.key */ protected String key /* * Property to specify if files should be overwritten. * @ant-property-name resource.overwrite * @ant-property-name resource.test.overwrite */ protected String overwrite /* * Property to specify if empty directories should be copied. * @ant-property-name resource.include.empty.dirs * @ant-property-name resource.test.include.empty.dirs */ protected String includeEmptyDirs /* * Property to specify if the last modified files should be preserved. * @ant-property-name resource.preserve.last.modified * @ant-property-name resource.test.preserve.last.modified */ protected String preserveLastModified /* * Property to specify if the build should fail if copying fails. * @ant-property-name resource.fail.on.error * @ant-property-name resource.test.fail.on.error */ protected String failOnError /* * Property to specify copy output should be verbose. * @ant-property-name resource.fail.on.error * @ant-property-name resource.test.fail.on.error */ protected String verbose /** * Constructor sets ant and buildContext instances in super class * @param ant AntBuilder instance * @param buildContext BuildContext instance */ AbstractResourceDelegate( 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 key != null assert overwrite != null assert includeEmptyDirs != null assert preserveLastModified != null assert failOnError != null assert verbose != null assert buildContext.get( "project.properties" ) != null } /** * Setter method for member variable key. * @param key String representation the resource groupid key. */ void setKey( String key ){ this.key = key } /** * Setter method for member variable overwrite. * @param overwrite String representation of whether files should be overwritten. */ void setOverwrite( String overwrite) { this.overwrite = overwrite } /** * Setter method for member variable includeEmptyDirs. * @param includeEmptyDirs String representation of whether empty directories should be included. */ void setIncludeEmptyDirs( String includeEmptyDirs ) { this.includeEmptyDirs = includeEmptyDirs } /** * Setter method for member variable preserveLastModified. * @param preserveLastModified String representation of whether last modified files should be preserved. */ void setPreserveLastModified( String preserveLastModified ) { this.preserveLastModified = preserveLastModified } /** * Setter method for member variable failOnError. * @param failOnError String representation of whether the build should fail if there is an error in copying. */ void setFailOnError( String failOnError ) { this.failOnError = failOnError } /** * Setter method for member variable verbose. * @param verbose String representation of whether the copy output should be verbose. */ void setVerbose( String verbose ) { this.verbose = verbose } void doResources() { // Retrieve the project metadata log.info( "Processing metadata with key: $key" ) Map properties = buildContext.get( "project.properties" ) // Retrieve the list of paths associated with the current metadata key List resourcePaths = properties.get( key ) // For each resource path that exists resourcePaths.each{ path -> File testFile = new File( path.dir ) if( testFile.exists() ){ if( log.isDebugEnabled() ) log.debug( "Processing $key path $path " ) // Copy files from path.dir to path.output paths given a set of inclusions and exclusions. ant.copy( toDir:path.output, overwrite:overwrite, includeEmptyDirs:includeEmptyDirs, preservelastmodified:preserveLastModified, failonerror:failOnError, verbose:verbose ) { // File set to use. ant.fileset( dir:path.dir, includes:path.include, excludes:path.exclude ) } } } } /** * Concrete implementation of the AbstractDelegate.execute() method */ void doExecute(){ doResources() } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy