org.apache.tools.ant.taskdefs

Class ExecuteOn

Known Direct Subclasses:
AbstractAccessTask, Attrib, Chmod, Transform

public class ExecuteOn
extends ExecTask

Executes a given command, supplying a set of files as arguments.

Since:
Ant 1.2

Nested Class Summary

static class
ExecuteOn.FileDirBoth
Enumerated attribute with the values "file", "dir" and "both" for the type attribute.

Field Summary

protected File
destDir
protected Vector
filesets
protected FileNameMapper
mapper
protected Mapper
mapperElement
protected Commandline.Marker
srcFilePos
protected boolean
srcIsFirst
Has <srcfile> been specified before <targetfile>
protected Commandline.Marker
targetFilePos
protected String
type

Fields inherited from class org.apache.tools.ant.taskdefs.ExecTask

cmdl, failOnError, newEnvironment, redirector, redirectorElement

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

Method Summary

void
addDirset(DirSet set)
Adds directories to operate on.
void
addFilelist(FileList list)
Source files to operate upon.
void
addFileset(FileSet set)
Source files to operate upon.
protected void
checkConfiguration()
protected ExecuteStreamHandler
createHandler()
Create the StreamHandler to use with our Execute instance.
Mapper
createMapper()
Mapper to use for mapping source files to target files.
Commandline.Marker
createSrcfile()
Marker that indicates where the name of the source file should be put on the command line.
Commandline.Marker
createTargetfile()
Marker that indicates where the name of the target file should be put on the command line.
protected String[]
getCommandline(String srcFile, File baseDir)
Construct the command line for serial execution.
protected String[]
getCommandline(String[] srcFiles, File[] baseDirs)
Construct the command line for parallel execution.
protected String[]
getDirs(File baseDir, DirectoryScanner ds)
Return the list of Directories from this DirectoryScanner that should be included on the command line.
protected String[]
getFiles(File baseDir, DirectoryScanner ds)
Return the list of files from this DirectoryScanner that should be included on the command line.
protected String[]
getFilesAndDirs(FileList list)
Return the list of files or directories from this FileList that should be included on the command line.
protected void
runExec(Execute exe)
Run the command using the given Execute instance.
protected void
runParallel(Execute exe, Vector fileNames, Vector baseDirs)
Runs the command in "parallel" mode, making sure that at most maxParallel sourcefiles get passed on the command line.
void
setAddsourcefile(boolean b)
Whether to send the source file name on the command line.
void
setDest(File destDir)
The directory where target files are to be placed.
void
setForwardslash(boolean forwardSlash)
The source and target file names on Windows and OS/2 must use forward slash as file separator.
void
setIgnoremissing(boolean b)
Whether to ignore nonexistent files from filelists.
void
setMaxParallel(int max)
Limit the command line length by passing at maximum this many sourcefiles at once to the command.
void
setParallel(boolean parallel)
If true, run the command only once, appending all files as arguments.
void
setRelative(boolean relative)
Whether the filenames should be passed on the command line as absolute or relative pathnames.
void
setSkipEmptyFilesets(boolean skip)
If no source files have been found or are newer than their corresponding target files, do not run the command.
void
setType(ExecuteOn.FileDirBoth type)
Whether the command works only on files, directories or both?
void
setVerbose(boolean b)
Whether to print a verbose summary after execution.
protected void
setupRedirector()
Set up properties on the redirector that we needed to store locally.

Methods inherited from class org.apache.tools.ant.taskdefs.ExecTask

addConfiguredRedirector, addEnv, checkConfiguration, createArg, createHandler, createWatchdog, execute, getResolveExecutable, isValidOs, logFlush, maybeSetResultPropertyValue, prepareExec, resolveExecutable, runExec, runExecute, setAppend, setCommand, setDir, setError, setErrorProperty, setExecutable, setFailIfExecutionFails, setFailonerror, setInput, setInputString, setLogError, setNewenvironment, setOs, setOutput, setOutputproperty, setResolveExecutable, setResultProperty, setSpawn, setTimeout, setTimeout, setVMLauncher, setupRedirector

Methods inherited from class org.apache.tools.ant.Task

execute, 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, log, log, setProject

Field Details

destDir

protected File destDir


filesets

protected Vector filesets


mapper

protected FileNameMapper mapper


mapperElement

protected Mapper mapperElement


srcFilePos

protected Commandline.Marker srcFilePos


srcIsFirst

protected boolean srcIsFirst
Has <srcfile> been specified before <targetfile>


targetFilePos

protected Commandline.Marker targetFilePos


type

protected String type

Method Details

addDirset

public void addDirset(DirSet set)
Adds directories to operate on.

Parameters:
set - the DirSet to add.

Since:
Ant 1.6


addFilelist

public void addFilelist(FileList list)
Source files to operate upon.


addFileset

public void addFileset(FileSet set)
Source files to operate upon.


checkConfiguration

protected void checkConfiguration()
Overrides:
checkConfiguration in interface ExecTask

To do:
using taskName here is brittle, as a user could override it. this should probably be modified to use the classname instead.


createHandler

protected ExecuteStreamHandler createHandler()
            throws BuildException
Create the StreamHandler to use with our Execute instance.
Overrides:
createHandler in interface ExecTask

Returns:
instance of ExecuteStreamHandler

Throws:
BuildException - under unknown circumstances


createMapper

public Mapper createMapper()
            throws BuildException
Mapper to use for mapping source files to target files.


createSrcfile

public Commandline.Marker createSrcfile()
Marker that indicates where the name of the source file should be put on the command line.


createTargetfile

public Commandline.Marker createTargetfile()
Marker that indicates where the name of the target file should be put on the command line.


getCommandline

protected String[] getCommandline(String srcFile,
                                  File baseDir)
Construct the command line for serial execution.

Parameters:
srcFile - The filename to add to the commandline
baseDir - filename is relative to this dir


getCommandline

protected String[] getCommandline(String[] srcFiles,
                                  File[] baseDirs)
Construct the command line for parallel execution.

Parameters:
srcFiles - The filenames to add to the commandline
baseDirs - filenames are relative to this dir


getDirs

protected String[] getDirs(File baseDir,
                           DirectoryScanner ds)
Return the list of Directories from this DirectoryScanner that should be included on the command line.


getFiles

protected String[] getFiles(File baseDir,
                            DirectoryScanner ds)
Return the list of files from this DirectoryScanner that should be included on the command line.


getFilesAndDirs

protected String[] getFilesAndDirs(FileList list)
Return the list of files or directories from this FileList that should be included on the command line.

Since:
Ant 1.6.2


runExec

protected void runExec(Execute exe)
            throws BuildException
Run the command using the given Execute instance. This may be overridden by subclasses
Overrides:
runExec in interface ExecTask

Parameters:
exe - instance of Execute to run

Throws:
BuildException - if the new process could not be started only if failIfExecFails is set to true (the default)


runParallel

protected void runParallel(Execute exe,
                           Vector fileNames,
                           Vector baseDirs)
            throws IOException,
                   BuildException
Runs the command in "parallel" mode, making sure that at most maxParallel sourcefiles get passed on the command line.

Since:
Ant 1.6


setAddsourcefile

public void setAddsourcefile(boolean b)
Whether to send the source file name on the command line.

Defaults to true.

Since:
Ant 1.6


setDest

public void setDest(File destDir)
The directory where target files are to be placed.


setForwardslash

public void setForwardslash(boolean forwardSlash)
The source and target file names on Windows and OS/2 must use forward slash as file separator.


setIgnoremissing

public void setIgnoremissing(boolean b)
Whether to ignore nonexistent files from filelists.

Since:
Ant 1.6.2


setMaxParallel

public void setMaxParallel(int max)
Limit the command line length by passing at maximum this many sourcefiles at once to the command.

Set to <= 0 for unlimited - this is the default.

Since:
Ant 1.6


setParallel

public void setParallel(boolean parallel)
If true, run the command only once, appending all files as arguments. If false, command will be executed once for every file. Defaults to false.


setRelative

public void setRelative(boolean relative)
Whether the filenames should be passed on the command line as absolute or relative pathnames. Paths are relative to the base directory of the corresponding fileset for source files or the dest attribute for target files.


setSkipEmptyFilesets

public void setSkipEmptyFilesets(boolean skip)
If no source files have been found or are newer than their corresponding target files, do not run the command.


setType

public void setType(ExecuteOn.FileDirBoth type)
Whether the command works only on files, directories or both?


setVerbose

public void setVerbose(boolean b)
Whether to print a verbose summary after execution.

Since:
Ant 1.6


setupRedirector

protected void setupRedirector()
Set up properties on the redirector that we needed to store locally.
Overrides:
setupRedirector in interface ExecTask


Copyright B) 2000-2005 Apache Software Foundation. All Rights Reserved.