org.figure8.join.services.scripting.ant.tasks
Class SubstituteParametersTask

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by org.figure8.join.services.scripting.ant.tasks.RemoteServiceTask
              extended by org.figure8.join.services.scripting.ant.tasks.SubstituteParametersTask

public class SubstituteParametersTask
extends RemoteServiceTask

This is an Ant task to use for substituting deployment parameters, into source files, by their values according to environment and deployment target.
As an example, use a substituteParams that way to ensure substitution :
>substituteParams environmentKey="env01" targetName="full" regExp="\\$(\\w+)\\$" toDir="${dest.dir}"<
>fileset dir="${src.dir}" includes="*.properties"/<
>fileset dir="${src2.dir}" includes="*.xml"/<
>substituteParams/<

This task connects to Join server in order to dynamically retrieve the parameters name/value pairs for environment "env01" and target "full". It then uses the regular expression pattern "\$(\w+)\$" (this is its default value and you may omit it - be careful to double backslashes for Java string) to find the parameter names into source files contained into filesets.
By default, if an exception occurs or if a found parameter has no value, the task produces a "SubstituteTask.log" log file into destination directory. You may change the name of this log file using the log attribute of task. If you may also want the task to fail on error, set the failonerror attribute to true.

Version:
$Revision: 1.2 $
Author:
Laurent Broudoux

Field Summary
static java.lang.String DEFAULT_LOGFILE
          Constant representing the default name for log file
static java.lang.String DEFAULT_REGEXP
          Constant representing the default regular expression used : \$(\w+)\$
 
Fields inherited from class org.figure8.join.services.scripting.ant.tasks.RemoteServiceTask
REMOTE_URL_SUBCONTEXT
 
Fields inherited from class org.apache.tools.ant.Task
description, location, target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
project
 
Constructor Summary
SubstituteParametersTask()
          Creates a new instance of SubstituteParametersTask
 
Method Summary
 void addFileset(org.apache.tools.ant.types.FileSet set)
          Adds a set of files (nested fileset element)
protected  void doSubstitution(java.util.Map parametersMap)
          Do the substitution using the given parameters map into the configured filesets
protected  java.util.List doSubstitutionInFile(java.io.File src, java.io.File dest, java.util.regex.Pattern pattern, java.util.Map parametersMap)
          Do the substitution work from a source file into a destination file
 void execute()
          Execute this task : do the substitution according into configured filesets
 java.lang.String getEnvironmentKey()
           
 java.lang.String getLogFile()
           
 java.lang.String getRegExp()
           
 java.lang.String getTargetName()
           
 java.lang.String getToDir()
           
 boolean isFailonerror()
           
protected  java.util.Map retrieveParametersMap()
          Connect to remote service for retrieving a map containing parameters.
 void setEnvironmentKey(java.lang.String environmentKey)
           
 void setFailonerror(boolean failonerror)
           
 void setLogFile(java.lang.String logFile)
           
 void setRegExp(java.lang.String regExp)
           
 void setTargetName(java.lang.String targetName)
           
 void setToDir(java.lang.String toDir)
           
protected  void validateAttributes()
          Validate this task attributes before execution
 
Methods inherited from class org.figure8.join.services.scripting.ant.tasks.RemoteServiceTask
getPassword, getUrl, getUser, loginToRemoteService, releaseRemoteService, retrieveRemoteService, setPassword, setUrl, setUser
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject, setProject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_REGEXP

public static final java.lang.String DEFAULT_REGEXP
Constant representing the default regular expression used : \$(\w+)\$

See Also:
Constant Field Values

DEFAULT_LOGFILE

public static final java.lang.String DEFAULT_LOGFILE
Constant representing the default name for log file

See Also:
Constant Field Values
Constructor Detail

SubstituteParametersTask

public SubstituteParametersTask()
Creates a new instance of SubstituteParametersTask

Method Detail

getEnvironmentKey

public java.lang.String getEnvironmentKey()
Returns:
The key of physical environment to use for retrieving parameter references

setEnvironmentKey

public void setEnvironmentKey(java.lang.String environmentKey)
Parameters:
environmentKey - The key of physical environment to use for retrieving parameter references

getTargetName

public java.lang.String getTargetName()
Returns:
The name of deployment target to use for retrieving parameter references

setTargetName

public void setTargetName(java.lang.String targetName)
Parameters:
targetName - The name of deployment target to use for retrieving parameter references

getRegExp

public java.lang.String getRegExp()
Returns:
The regular expression pattern for selecting parameters within files

setRegExp

public void setRegExp(java.lang.String regExp)
Parameters:
regExp - The regular expression pattern for selecting parameters within files

getToDir

public java.lang.String getToDir()
Returns:
The destination directory for processed files

setToDir

public void setToDir(java.lang.String toDir)
Parameters:
toDir - The destination directory for processed files

getLogFile

public java.lang.String getLogFile()
Returns:
The name of log file where to write errors or warning

setLogFile

public void setLogFile(java.lang.String logFile)
Parameters:
logFile - The name of log file where to write errors or warning

isFailonerror

public boolean isFailonerror()
Returns:
Flag telling if substitution exceptions thrown a BuildException

setFailonerror

public void setFailonerror(boolean failonerror)
Parameters:
failonerror - Flag telling if substitution exceptions thrown a BuildException

addFileset

public void addFileset(org.apache.tools.ant.types.FileSet set)
Adds a set of files (nested fileset element)

Parameters:
set - A FileSet containing files to process

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Execute this task : do the substitution according into configured filesets

Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException - if something wrong occurs during task process

validateAttributes

protected void validateAttributes()
                           throws org.apache.tools.ant.BuildException
Validate this task attributes before execution

Throws:
org.apache.tools.ant.BuildException - if a mandatory attribute is not present

retrieveParametersMap

protected java.util.Map retrieveParametersMap()
                                       throws org.apache.tools.ant.BuildException
Connect to remote service for retrieving a map containing parameters.

Throws:
org.apache.tools.ant.BuildException

doSubstitution

protected void doSubstitution(java.util.Map parametersMap)
                       throws org.apache.tools.ant.BuildException
Do the substitution using the given parameters map into the configured filesets

Throws:
org.apache.tools.ant.BuildException - if exception occurs during log file writing or if errors and failonerror falgf is set to true

doSubstitutionInFile

protected java.util.List doSubstitutionInFile(java.io.File src,
                                              java.io.File dest,
                                              java.util.regex.Pattern pattern,
                                              java.util.Map parametersMap)
Do the substitution work from a source file into a destination file

Parameters:
src - The source file to substitute parameters in
dest - The destination file to write with parameters values
pattern - The regular expression pattern for selecting parameters into src
parametersMap - The map containing parameter name/value pairs
Returns:
A list containing substitution error messages (may be empty)


Copyright © 2005-2008 Join. All Rights Reserved.