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

public Class ImportTask

extends Task
Class Inheritance
Imports
java.io.File, java.net.MalformedURLException, .URL, java.util.Vector, org.apache.tools.ant.BuildException, .MagicNames, .Project, .ProjectHelper, .ProjectHelperRepository, .Task, org.apache.tools.ant.types.Resource, .ResourceCollection, org.apache.tools.ant.types.resources.FileProvider, .FileResource, .URLProvider, .URLResource, .Union, org.apache.tools.ant.util.FileUtils

Task to import another build file into the current project.

It must be 'top level'. On execution it will read another Ant file into the same Project.

Important Note

Trying to understand how relative file references resolved in deep/complex build hierarchies - such as what happens when an imported file imports another file can be difficult. Use absolute references for enhanced build file stability, especially in the imported files.

Examples:

<import file="../common-targets.xml"/>

Import targets from a file in a parent directory.

<import file="${deploy-platform}.xml"/>

Import the project defined by the property deploy-platform.

Since
Ant1.6

Field Summary

Modifier and TypeField and Description
private String
private static final FileUtils
private boolean
private String
private final Union
private String
Inherited from org.apache.tools.ant.Task:
targettaskNametaskTypewrapper

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
add(ResourceCollection
ResourceCollection
r
)

The resource to import.

public void
execute()

Overrides org.apache.tools.ant.Task.execute.

Called by the project to let the task do its work.
private Resource
private boolean
hasAlreadyBeenImported(Resource importedResource, Vector<Object> importStack)

private void
importResource(ProjectHelper helper, Resource importedResource)

private boolean
protected final boolean

Returns:

boolean
isInIncludeMode
()

Whether the task is in include (as opposed to import) mode.

private boolean
isOneOf(Object o, Resource importedResource, File importedFile, URL importedURL)

public void
setAs(String
String
prefix
)

The prefix to use when prefixing the imported target names.

public void
setFile(String
the name of the file
file
)

the name of the file to import.

public void
setOptional(boolean
if true ignore files that are not present, default is false
optional
)

sets the optional attribute

public void
setPrefixSeparator(String
String
s
)

The separator to use between prefix and target name, default is ".".

private static void
setProjectHelperProps(String
String
prefix
,
String
String
prefixSep
,
boolean
boolean
inIncludeMode
)

Sets a bunch of Thread-local ProjectHelper properties.

Inherited from org.apache.tools.ant.Task:
bindToOwnergetOwningTargetgetRuntimeConfigurableWrappergetTaskNamegetTaskTypegetWrapperhandleErrorFlushhandleErrorOutputhandleFlushhandleInputhandleOutputinitisInvalidloglogloglogmaybeConfigureperformreconfiguresetOwningTargetsetRuntimeConfigurableWrappersetTaskNamesetTaskType

Field Detail

fileback to summary
private String file
FILE_UTILSback to summary
private static final FileUtils FILE_UTILS
optionalback to summary
private boolean optional
prefixSeparatorback to summary
private String prefixSeparator
resourcesback to summary
private final Union resources
targetPrefixback to summary
private String targetPrefix

Constructor Detail

ImportTaskback to summary
public ImportTask()

Method Detail

addback to summary
public void add(ResourceCollection r)

The resource to import.

Parameters
r:ResourceCollection

ResourceCollection

Since
Ant 1.8.0
executeback to summary
public void execute()

Overrides org.apache.tools.ant.Task.execute.

Doc from org.apache.tools.ant.Task.execute.

Called by the project to let the task do its work. This method may be called more than once, if the task is invoked more than once. For example, if target1 and target2 both depend on target3, then running "ant target1 target2" will run all tasks in target3 twice.

Annotations
@Override
getFileAttributeResourceback to summary
private Resource getFileAttributeResource()
hasAlreadyBeenImportedback to summary
private boolean hasAlreadyBeenImported(Resource importedResource, Vector<Object> importStack)
importResourceback to summary
private void importResource(ProjectHelper helper, Resource importedResource)
isExistingAbsoluteFileback to summary
private boolean isExistingAbsoluteFile(String name)
isInIncludeModeback to summary
protected final boolean isInIncludeMode()

Whether the task is in include (as opposed to import) mode.

In include mode included targets are only known by their prefixed names and their depends lists get rewritten so that all dependencies get the prefix as well.

In import mode imported targets are known by an adorned as well as a prefixed name and the unadorned target may be overwritten in the importing build file. The depends list of the imported targets is not modified at all.

Returns:boolean

boolean

Since
Ant 1.8.0
isOneOfback to summary
private boolean isOneOf(Object o, Resource importedResource, File importedFile, URL importedURL)
setAsback to summary
public void setAs(String prefix)

The prefix to use when prefixing the imported target names.

Parameters
prefix:String

String

Since
Ant 1.8.0
setFileback to summary
public void setFile(String file)

the name of the file to import. How relative paths are resolved is still in flux: use absolute paths for safety.

Parameters
file:String

the name of the file

setOptionalback to summary
public void setOptional(boolean optional)

sets the optional attribute

Parameters
optional:boolean

if true ignore files that are not present, default is false

setPrefixSeparatorback to summary
public void setPrefixSeparator(String s)

The separator to use between prefix and target name, default is ".".

Parameters
s:String

String

Since
Ant 1.8.0
setProjectHelperPropsback to summary
private static void setProjectHelperProps(String prefix, String prefixSep, boolean inIncludeMode)

Sets a bunch of Thread-local ProjectHelper properties.

Parameters
prefix:String

String

prefixSep:String

String

inIncludeMode:boolean

boolean

Since
Ant 1.8.0