Top Description Inners Fields Constructors Methods
org.apache.tools.ant.taskdefs

public Class ExecuteOn

extends ExecTask
Class Inheritance
Known Direct Subclasses
org.apache.tools.ant.taskdefs.Transform, org.apache.tools.ant.taskdefs.optional.unix.AbstractAccessTask, org.apache.tools.ant.taskdefs.optional.windows.Attrib, org.apache.tools.ant.taskdefs.Chmod
Imports
java.io.File, .IOException, java.util.ArrayList, .HashSet, .List, .Set, .Vector, org.apache.tools.ant.BuildException, .DirectoryScanner, .Project, org.apache.tools.ant.types.AbstractFileSet, .Commandline, .DirSet, .EnumeratedAttribute, .FileList, .FileSet, .Mapper, .Resource, .ResourceCollection, org.apache.tools.ant.types.resources.FileProvider, .FileResource, .Union, org.apache.tools.ant.util.FileNameMapper, .ResourceUtils, .SourceFileScanner

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ExecuteOn.FileDirBoth

Enumerated attribute with the values "file", "dir" and "both" for the type attribute.

Field Summary

Modifier and TypeField and Description
private boolean
protected File
protected Vector<AbstractFileSet>
private boolean
private boolean
private boolean
protected FileNameMapper
protected Mapper
private int
private boolean
private boolean
private Union
private boolean
protected Commandline.Marker
protected boolean
srcIsFirst

Has <srcfile> been specified before <targetfile>

protected Commandline.Marker
protected String
private boolean
Inherited from org.apache.tools.ant.taskdefs.ExecTask:
cmdlfailOnErrornewEnvironmentredirectorredirectorElement

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
add(ResourceCollection
resource collection to add.
rc
)

Add a collection of resources upon which to operate.

public void
add(FileNameMapper
the mapper to add.
fileNameMapper
)

Add a nested FileNameMapper.

public void
addDirset(DirSet
the DirSet to add.
set
)

Add a set of directories upon which to operate.

public void
addFilelist(FileList
the FileList to add.
list
)

Add a list of source files upon which to operate.

public void
addFileset(FileSet
the FileSet to add.
set
)

Add a set of files upon which to operate.

protected void
checkConfiguration()

Overrides org.apache.tools.ant.taskdefs.ExecTask.checkConfiguration.

Check the configuration of this ExecuteOn instance.
protected ExecuteStreamHandler

Returns:

ExecuteStreamHandler.
createHandler
()

Overrides org.apache.tools.ant.taskdefs.ExecTask.createHandler.

Create the ExecuteStreamHandler instance that will be used during execution.
public Mapper

Returns:

Mapper.
createMapper
()

Create a nested Mapper element to use for mapping source files to target files.

public Commandline.Marker

Returns:

Commandline.Marker.
createSrcfile
()

Create a placeholder indicating where on the command line the name of the source file should be inserted.

public Commandline.Marker

Returns:

Commandline.Marker.
createTargetfile
()

Create a placeholder indicating where on the command line the name of the target file should be inserted.

protected String[]

Returns:

the command line in the form of a String[].
getCommandline
(String[]
The filenames to add to the commandline.
srcFiles
,
File[]
filenames are relative to this dir.
baseDirs
)

Construct the command line for parallel execution.

protected String[]

Returns:

the command line in the form of a String[].
getCommandline
(String
The filename to add to the commandline.
srcFile
,
File
filename is relative to this dir.
baseDir
)

Construct the command line for serial execution.

protected String[]

Returns:

a String[] containing the directory names.
getDirs
(File
the File base directory.
baseDir
,
DirectoryScanner
the DirectoryScanner to use for file scanning.
ds
)

Return the list of Directories from this DirectoryScanner that should be included on the command line.

protected String[]

Returns:

a String[] containing the filenames.
getFiles
(File
the File base directory.
baseDir
,
DirectoryScanner
the DirectoryScanner to use for file scanning.
ds
)

Return the list of files from this DirectoryScanner that should be included on the command line.

protected String[]

Returns:

a String[] containing the directory names.
getFilesAndDirs
(FileList
the FileList to check.
list
)

Return the list of files or directories from this FileList that should be included on the command line.

private static void
insertTargetFiles(String[] targetFiles, String[] arguments, int insertPosition, String prefix, String suffix)

Inserts target file names (which are already absolute paths) into the list of arguments, taking prefix and postfix into account.

private void
logSkippingFileset(String
the current type.
currentType
,
DirectoryScanner
the directory scanner.
ds
,
File
the dir base
base
)

log a message for skipping a fileset.

private String[]
restrict(String[] s, File baseDir)

protected void
runExec(Execute
the Execute instance representing the external process.
exe
)

Overrides org.apache.tools.ant.taskdefs.ExecTask.runExec.

Run the specified Execute object.
protected void
runParallel(Execute
the Executable to use.
exe
,
Vector<String>
the Vector of filenames.
fileNames
,
Vector<File>
the Vector of base directories corresponding to fileNames.
baseDirs
)

Run the command in "parallel" mode, making sure that at most maxParallel sourcefiles get passed on the command line.

public void
setAddsourcefile(boolean
whether to add the source file to the command line.
b
)

Set whether to send the source file name on the command line.

public void
setDest(File
the File object representing the destination directory.
destDir
)

Specify the directory where target files are to be placed.

public void
setForce(boolean
whether to bypass timestamp comparisons.
b
)

Set whether to bypass timestamp comparisons for target files.

public void
setForwardslash(boolean
whether the forward slash will be forced.
forwardSlash
)

Set whether the source and target file names on Windows and OS/2 must use the forward slash as file separator.

public void
setIgnoremissing(boolean
whether to ignore missing files.
b
)

Set whether to ignore nonexistent files from filelists.

public void
setMaxParallel(int
int maximum number of sourcefiles passed to the executable.
max
)

Limit the command line length by passing at maximum this many sourcefiles at once to the command.

public void
setParallel(boolean
whether to run in parallel.
parallel
)

Set whether to execute in parallel mode.

public void
setRelative(boolean
whether to pass relative pathnames.
relative
)

Set whether the filenames should be passed on the command line as absolute or relative pathnames.

public void
setSkipEmptyFilesets(boolean
whether to skip empty filesets.
skip
)

Set whether empty filesets will be skipped.

public void
setType(ExecuteOn.FileDirBoth
a FileDirBoth EnumeratedAttribute.
type
)

Set whether the command works only on files, directories or both.

protected void
public void
setVerbose(boolean
whether to operate in verbose mode.
b
)

Set whether to operate in verbose mode.

Inherited from org.apache.tools.ant.taskdefs.ExecTask:
addConfiguredRedirectoraddEnvcreateArgcreateWatchdogexecutegetOsgetOsFamilygetResolveExecutableisValidOslogFlushmaybeSetResultPropertyValueprepareExecresolveExecutablerunExecutesetAppendsetCommandsetDirsetDiscardErrorsetDiscardOutputsetErrorsetErrorPropertysetExecutablesetFailIfExecutionFailssetFailonerrorsetInputsetInputStringsetLogErrorsetNewenvironmentsetOssetOsFamilysetOutputsetOutputpropertysetResolveExecutablesetResultPropertysetSearchPathsetSpawnsetTimeoutsetTimeoutsetVMLauncher

Field Detail

addSourceFileback to summary
private boolean addSourceFile
destDirback to summary
protected File destDir
filesetsback to summary
protected Vector<AbstractFileSet> filesets
forceback to summary
private boolean force
forwardSlashback to summary
private boolean forwardSlash
ignoreMissingback to summary
private boolean ignoreMissing
mapperback to summary
protected FileNameMapper mapper
mapperElementback to summary
protected Mapper mapperElement
maxParallelback to summary
private int maxParallel
parallelback to summary
private boolean parallel
relativeback to summary
private boolean relative
resourcesback to summary
private Union resources
skipEmptyback to summary
private boolean skipEmpty
srcFilePosback to summary
protected Commandline.Marker srcFilePos
srcIsFirstback to summary
protected boolean srcIsFirst

Has <srcfile> been specified before <targetfile>

targetFilePosback to summary
protected Commandline.Marker targetFilePos
typeback to summary
protected String type
verboseback to summary
private boolean verbose

Constructor Detail

ExecuteOnback to summary
public ExecuteOn()

Method Detail

addback to summary
public void add(ResourceCollection rc)

Add a collection of resources upon which to operate.

Parameters
rc:ResourceCollection

resource collection to add.

Since
Ant 1.7
addback to summary
public void add(FileNameMapper fileNameMapper)

Add a nested FileNameMapper.

Parameters
fileNameMapper:FileNameMapper

the mapper to add.

Since
Ant 1.6.3
addDirsetback to summary
public void addDirset(DirSet set)

Add a set of directories upon which to operate.

Parameters
set:DirSet

the DirSet to add.

Since
Ant 1.6
addFilelistback to summary
public void addFilelist(FileList list)

Add a list of source files upon which to operate.

Parameters
list:FileList

the FileList to add.

addFilesetback to summary
public void addFileset(FileSet set)

Add a set of files upon which to operate.

Parameters
set:FileSet

the FileSet to add.

checkConfigurationback to summary
protected void checkConfiguration()

Overrides org.apache.tools.ant.taskdefs.ExecTask.checkConfiguration.

Check the configuration of this ExecuteOn instance.

Annotations
@Override
createHandlerback to summary
protected ExecuteStreamHandler createHandler() throws BuildException

Overrides org.apache.tools.ant.taskdefs.ExecTask.createHandler.

Create the ExecuteStreamHandler instance that will be used during execution.

Returns:ExecuteStreamHandler

ExecuteStreamHandler.

Annotations
@Override
Exceptions
BuildException:
on error.
createMapperback to summary
public Mapper createMapper() throws BuildException

Create a nested Mapper element to use for mapping source files to target files.

Returns:Mapper

Mapper.

Exceptions
BuildException:
if more than one mapper is defined.
createSrcfileback to summary
public Commandline.Marker createSrcfile()

Create a placeholder indicating where on the command line the name of the source file should be inserted.

Returns:Commandline.Marker

Commandline.Marker.

createTargetfileback to summary
public Commandline.Marker createTargetfile()

Create a placeholder indicating where on the command line the name of the target file should be inserted.

Returns:Commandline.Marker

Commandline.Marker.

getCommandlineback to summary
protected String[] getCommandline(String[] srcFiles, File[] baseDirs)

Construct the command line for parallel execution.

Parameters
srcFiles:String[]

The filenames to add to the commandline.

baseDirs:File[]

filenames are relative to this dir.

Returns:String[]

the command line in the form of a String[].

getCommandlineback to summary
protected String[] getCommandline(String srcFile, File baseDir)

Construct the command line for serial execution.

Parameters
srcFile:String

The filename to add to the commandline.

baseDir:File

filename is relative to this dir.

Returns:String[]

the command line in the form of a String[].

getDirsback to summary
protected String[] getDirs(File baseDir, DirectoryScanner ds)

Return the list of Directories from this DirectoryScanner that should be included on the command line.

Parameters
baseDir:File

the File base directory.

ds:DirectoryScanner

the DirectoryScanner to use for file scanning.

Returns:String[]

a String[] containing the directory names.

getFilesback to summary
protected String[] getFiles(File baseDir, DirectoryScanner ds)

Return the list of files from this DirectoryScanner that should be included on the command line.

Parameters
baseDir:File

the File base directory.

ds:DirectoryScanner

the DirectoryScanner to use for file scanning.

Returns:String[]

a String[] containing the filenames.

getFilesAndDirsback to summary
protected String[] getFilesAndDirs(FileList list)

Return the list of files or directories from this FileList that should be included on the command line.

Parameters
list:FileList

the FileList to check.

Returns:String[]

a String[] containing the directory names.

Since
Ant 1.6.2
insertTargetFilesback to summary
private static void insertTargetFiles(String[] targetFiles, String[] arguments, int insertPosition, String prefix, String suffix)

Inserts target file names (which are already absolute paths) into the list of arguments, taking prefix and postfix into account.

logSkippingFilesetback to summary
private void logSkippingFileset(String currentType, DirectoryScanner ds, File base)

log a message for skipping a fileset.

Parameters
currentType:String

the current type.

ds:DirectoryScanner

the directory scanner.

base:File

the dir base

restrictback to summary
private String[] restrict(String[] s, File baseDir)
runExecback to summary
protected void runExec(Execute exe) throws BuildException

Overrides org.apache.tools.ant.taskdefs.ExecTask.runExec.

Run the specified Execute object.

Parameters
exe:Execute

the Execute instance representing the external process.

Annotations
@Override
Exceptions
BuildException:
on error
runParallelback to summary
protected void runParallel(Execute exe, Vector<String> fileNames, Vector<File> baseDirs) throws IOException, BuildException

Run the command in "parallel" mode, making sure that at most maxParallel sourcefiles get passed on the command line.

Parameters
exe:Execute

the Executable to use.

fileNames:Vector<String>

the Vector of filenames.

baseDirs:Vector<File>

the Vector of base directories corresponding to fileNames.

Exceptions
IOException:
on I/O errors.
BuildException:
on other errors.
Since
Ant 1.6
setAddsourcefileback to summary
public void setAddsourcefile(boolean b)

Set whether to send the source file name on the command line.

Defaults to true.

Parameters
b:boolean

whether to add the source file to the command line.

Since
Ant 1.6
setDestback to summary
public void setDest(File destDir)

Specify the directory where target files are to be placed.

Parameters
destDir:File

the File object representing the destination directory.

setForceback to summary
public void setForce(boolean b)

Set whether to bypass timestamp comparisons for target files.

Parameters
b:boolean

whether to bypass timestamp comparisons.

Since
Ant 1.6.3
setForwardslashback to summary
public void setForwardslash(boolean forwardSlash)

Set whether the source and target file names on Windows and OS/2 must use the forward slash as file separator.

Parameters
forwardSlash:boolean

whether the forward slash will be forced.

setIgnoremissingback to summary
public void setIgnoremissing(boolean b)

Set whether to ignore nonexistent files from filelists.

Parameters
b:boolean

whether to ignore missing files.

Since
Ant 1.6.2
setMaxParallelback to summary
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.

Parameters
max:int

int maximum number of sourcefiles passed to the executable.

Since
Ant 1.6
setParallelback to summary
public void setParallel(boolean parallel)

Set whether to execute in parallel mode. 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.

Parameters
parallel:boolean

whether to run in parallel.

setRelativeback to summary
public void setRelative(boolean relative)

Set 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.

Parameters
relative:boolean

whether to pass relative pathnames.

setSkipEmptyFilesetsback to summary
public void setSkipEmptyFilesets(boolean skip)

Set whether empty filesets will be skipped. If true and no source files have been found or are newer than their corresponding target files, the command will not be run.

Parameters
skip:boolean

whether to skip empty filesets.

setTypeback to summary
public void setType(ExecuteOn.FileDirBoth type)

Set whether the command works only on files, directories or both.

Parameters
type:ExecuteOn.FileDirBoth

a FileDirBoth EnumeratedAttribute.

setupRedirectorback to summary
protected void setupRedirector()

Overrides org.apache.tools.ant.taskdefs.ExecTask.setupRedirector.

Set up the I/O Redirector.

Annotations
@Override
setVerboseback to summary
public void setVerbose(boolean b)

Set whether to operate in verbose mode. If true, a verbose summary will be printed after execution.

Parameters
b:boolean

whether to operate in verbose mode.

Since
Ant 1.6
org.apache.tools.ant.taskdefs back to summary

public Class ExecuteOn.FileDirBoth

extends EnumeratedAttribute
Class Inheritance

Enumerated attribute with the values "file", "dir" and "both" for the type attribute.

Field Summary

Modifier and TypeField and Description
public static final String
DIR

Dir value

public static final String
FILE

File value

Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
value

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String[]
getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

This is the only method a subclass needs to implement.
Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
containsValuegetIndexgetInstancegetValueindexOfValuesetValuetoString

Field Detail

DIRback to summary
public static final String DIR

Dir value

FILEback to summary
public static final String FILE

File value

Constructor Detail

FileDirBothback to summary
public FileDirBoth()

Method Detail

getValuesback to summary
public String[] getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

Doc from org.apache.tools.ant.types.EnumeratedAttribute.getValues.

This is the only method a subclass needs to implement.

Returns:String[]

an array holding all possible values of the enumeration. The order of elements must be fixed so that indexOfValue(String) always return the same index for the same value.

Annotations
@Override
See Also
EnumeratedAttribute#getValues