Ant4Eclipse contains several tasks and conditions that can be used with every eclipse project type. This chapter explains the usage of these tasks and conditions.
The hasNature
condition is an Ant condition that can be used to check if a project has a specific nature. Natures are used to assign specific behaviour to Eclipse projects. Java projects for example have the nature 'org.eclipse.jdt.core.javanature
'.
The hasNature
condition can be used with ant's native condition and waitfor tasks (see Condition Task). It can also be used with the if-task from the ant-contrib project to create build steps that check whether a project has some specific nature.
The hasNature
datatype provides the following arguments:
Argument | Description | Required |
---|---|---|
workspaceDirectory | Absolute path of the workspace directory | Either 'workspaceDirectory' or 'workspaceId' has to be specified |
workspaceId | The identifier of a defined workspace (see <workspaceDefinition>) | Either 'workspaceDirectory' or 'workspaceId' has to be specified |
projectName | Name of the eclipse project | yes |
nature | Name of a Nature that should be checked | yes |
The following example checks if the project with the name 'simple.java.project' has the nature 'org.eclipse.jdt.core.javanature':
<antcontrib:if> <ant4eclipse:hasNature workspacedirectory="${workspace}" projectname="simple.java.project" nature="org.eclipse.jdt.core.javanature" /> <antcontrib:then> ... </antcontrib:then> </antcontrib:if>
The hasBuildCommand
condition is an Ant condition that can be used to check if an Eclipse project has a specific build command. An Eclipse project can have several build command assigned to it. Those build commands are normally executed after a file has been saved (incremental build) or when a full build is initiated (Project -> Clean...) (manual build). A typical java project contains the org.eclipse.jdt.core.javabuilder
which invokes the default Eclipse compiler on java sources.
If you would like to write build steps that depend on specific build commands, you can use the hasBuildCommand
condition which checks if a project has a specified buildCommand
. The hasBuildCommand
-condition can be used with ant's native condition
and waitfor
tasks (see Condition Task). It can also be used with the if
-task from the ant-contrib project to create build steps that check whether some specific build commands exist or not.
The hasBuildCommand
datatype provides the following arguments:
Argument | Description | Required |
---|---|---|
workspaceDirectory | Absolute path of the workspace directory | Either 'workspaceDirectory' or 'workspaceId' has to be specified |
workspaceId | The identifier of a defined workspace (see <workspaceDefinition>) | Either 'workspaceDirectory' or 'workspaceId' has to be specified |
projectName | Name of the eclipse project | yes |
buildCommand | Name of the build command that should be checked | yes |
The following example checks if the project with the name 'simple.java.project' has the build command 'org.eclipse.jdt.core.javabuilder':
<antcontrib:if> <ant4eclipse:hasBuildCommand workspacedirectory="${workspace}" projectname="simple.java.project" buildcommand="org.eclipse.jdt.core.javabuilder" /> <antcontrib:then> ... </antcontrib:then> </antcontrib:if>
The executeBuildCommands
task allows you to iterate over one or more build commands that are defined in your eclipse project.
The executeBuildCommands
task provides the following arguments:
Argument | Description | Required |
---|---|---|
workspaceDirectory | Absolute path of the workspace directory | Either 'workspaceDirectory' or 'workspaceId' has to be specified |
workspaceId | The identifier of a defined workspace (see <workspaceDefinition>) | Either 'workspaceDirectory' or 'workspaceId' has to be specified |
projectName | Name of the eclipse project | yes |
The following example iterates over all build commands defined in the eclipse project 'simple.java.project'
:
<ant4eclipse:executeBuildCommands workspacedirectory="${workspace}" projectname="simple.java.project"> <org.eclipse.jdt.core.javabuilder> ... </org.eclipse.jdt.core.javabuilder> </ant4eclipse:executeBuildCommands>
Returns the project directory for a given eclipse project. Since ant4eclipse supports the usage of linked projects, it is necessary in some case to resolve the 'real' path of a project.
The getProjectDirectory
task provides the following arguments:
Argument | Description | Required |
---|---|---|
workspaceDirectory | Absolute path of the workspace directory | Either 'workspaceDirectory' or 'workspaceId' has to be specified |
workspaceId | The identifier of a defined workspace (see <workspaceDefinition>) | Either 'workspaceDirectory' or 'workspaceId' has to be specified |
projectName | Name of the eclipse project | yes |
property | The name of the property that will hold the resolved path | either 'pathId' or 'property' has to be specified |
pathId | The reference id for the path that will be created | either 'pathId' or 'property' has to be specified |
pathSeparator | The system-dependent path-separator character. This character is used to separate filenames in a sequence of files. | no (default: On UNIX systems, this character is ':' ; on Microsoft Windows systems it is ';' ) |
dirSeparator | The system-dependent default name-separator character. | no (default: On UNIX systems the value of this field is '/' ; on Microsoft Windows systems it is '\' ) |
relative | Determines whether the result path should be resolved relative to the given workspace or absolute | no (default: false) |
The following example resolves the absolute path of the the project with the name 'simple.java.project':
<ant4eclipse:getProjectDirectory workspacedirectory="${workspace}" projectname="simple.java.project" property="test" />
The workspaceDefinition
type allows you define a workspace with a custom workspace layout. In eclipse a workspace always has a flat layout (Workspace -> Projects), but many users store there eclipse projects in a hierarchical way within the source code repository. Ant4eclipse directly supports the usage of custom workspace layouts through this datatype.
Many thanks to Mark Riley for submitting the initial patch!
The workspaceDefinition
datatype provides the following arguments:
Argument | Description | Required |
---|---|---|
id | The identifier of the workspace definition | yes |
To define a custom workspace layout, you can use one or more nested Directory Sets.
The following example defines a workspace that contains projects that can be found in any sub-directory (recursively) of the directory 'D:/tmp':
<ant4eclipse:workspaceDefinition id="myWorkspace"> <dirset dir="D:/tmp"> <include name="**"/> </dirset> </ant4eclipse:workspaceDefinition>
You can use the workspace definition within the ant4eclipse task by using the 'workspaceId' attribute insead of the 'workspaceDirectory' attribute.
The linkedResourceVariable
datatype is an Ant datatype that allows you to specify an environment specific path for a linked resource. Within the eclipse IDE these variables are defined in the preferences dialog (Window -> Preferences..., General -> Workspace -> Linked Resources).
The linkedResourceVariable
type provides the following arguments:
Argument | Description | Required |
---|---|---|
name | The name of the linked resource path variable as specified in the eclipse preferences. | yes |
location | The location of the linked resource. | yes |
<ant4eclipse:linkedResourceVariable name="myLinkedResourcesDirectory" location="D:/location" />