Datatypes And Properties Flashcards

Datatypes and properties in ant

1
Q

What are the common data types

A

patternset, path, filterset and fileset

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the syntax of file set

A

<fileset dir=”src” includes”**/*.java” />

<fileset refid=”filesetId” />

<fileset dir=”src”>

<exclude name=”**/*.jsp” />

</fileset>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the default excludes

A

By default the following patterns are excluded

**/*~
**/#*#
**/.#*
**/%*%
**/CVS
**/CVS/**
**/.cvsignore
**/SCCS
**/SCCS/**
**/vssver.scc
**/._*

**/.svn
**/.svn/**

Inorder to turn this off the fileset has an attribute defaultexcludes=”no”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain fileset compilation

A

Filesets resolve their files when the declaration is encountered during exe- cution. This is important to know when referring to a previously defined fileset later, as new files and directories matching the patterns may have ap- peared between the resolution and reference—these new files would not be seen by tasks operating upon that fileset.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are paternsets

A

Filesets accomplish the include/exclude capability by utilizing another of Ant’s core datatypes: the patternset. A patternset is a collection of file matching patterns. A pat- ternset itself does not refer to any actual files until it is nested in a fileset and therefore rooted at a specific directory. A pattern is a path-matching specification similar to Unix- and MS-DOS-based file matching. Examples of this have already been shown with *.jar used to represent all files with the .jar extension in the top directory and **/*.jsp to represent all files in the entire directory tree with the .jsp extension. The pattern matching features are as follows:
• * matches zero or more characters.
• ? matches a single character.
• **, used as the name of a directory, represents matching of all directories from that point down, matching zero or more directories.
• Apatternendingwithatrailing/or\impliesatrailing**.

<patternset>
<include name=”**/*.gif,**/*.jpg”/>
<patternset>
<exclude name=”**/*.txt,**/*.xml”/>
</patternset>
</patternset>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are selectors

A

<filename>
<depth>
<size>
<date>
<present>
<depend>
<contains>

Selectors are combined in the containers

<and>, <or>, <not>, <none>, and <majority>

<copy todir=”newfiles” includeemptydirs=”false”>
<fileset dir=”web”>
<not>
<present targetdir=”currentfiles”/>
</not>
</fileset>
</copy>

<copy todir=”currentfiles” includeemptydirs=”false”>
<fileset dir=”web”>
<contains text=”System”/>
</fileset>
</copy>

contains is case sensitive and can be turned off by casesensitive=”no”

All rules must be satisfied before a file is considered part of a fileset, so when using selectors in conjunction with patternsets, the file must match the include patterns, must not match any exclude patterns, and the selector rules must test positively. A <custom> selector enables you to write your own selector logic in a Java class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a path

A

A path is a ordered list of path elements.

<pathelement location=”c:\ or c:/” />

<pathelement path=”c:\abc.jar; or : c:/abc1.jar” />

If path includes set of path then it’s defined with

<fileset>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are javac options

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Javac options 2

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are filter sets

A

Filter set replaces token with values

<html>
<head><title>Ant Book</title></head>
<body>
System build time: @DATE@ @ @TIME@
</body>
</html>
Here @DATE@ and @TIME@ will be replaced during the copy:
<tstamp/>
<copy todir=”new_web” overwrite=”true”>
<fileset dir=”web” includes=”**/*.jsp”/>
<filterset>
<filter token=”DATE” value=”${DSTAMP}”/>
<filter token=”TIME” value=”${TSTAMP}”/>
</filterset>
</copy>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

FILTERCHAINS AND FILTERREADERS

A

<classconstants>. Generates “name=value” lines for basic and String datatype constants
found in a class file.
<expandproperties> Replaces Ant property values. (See section 3.12 for property discussion.)
<headfilter> Extracts the first specified number of lines.
<linecontains> Only lines containing the specified string are passed through.
<linecontainsregexp> Only lines matching specified regular expression(s) are passed through.
<prefixlines> All lines have a prefix prepended.
<replacetokens> Performs token substitution, just as filtersets do.
<stripjavacomments> Removes Java style comments.
<striplinebreaks> Removes line breaks, defaulting to “\r” and “\n” but characters
stripped can be specified.
<striplinecomments> Removes lines beginning with a specified set of characters.
<tabstospaces> Replaces tabs with a specified number of spaces.
<tailfilter> Extracts the last specified number of lines.

<copy file=”config.properties” todir=”build”>
<filterchain>
<striplinecomments>
<comment value=”#”/>
</striplinecomments>
</filterchain>
</copy>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How can you load properties from java file

A

<loadproperties srcfile=”build/org/example/antbook/Constants.class”>
<filterchain>
<classconstants/>
<prefixlines prefix=”Constants.”/>
</filterchain>
</loadproperties>

<echo>Constants.VERSION = ${Constants.VERSION}</echo>
This results in the following output:
[echo] Constants.VERSION = 1.7

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are mappers and provide examples

A

identity The target is identical to the source file name.
flatten Source and target file names are identical, with the target file name having all leading
directory path stripped.
merge All source files are mapped to a single target file specified in the to attribute.
glob A single asterisk (*) used in the from pattern is substituted into the to pattern. Only
files matching the from pattern are considered.
package A subclass of the glob mapper, it functions similarly except replaces path separators with
the dot character (.) so that a file with the hierarchical package directory structure can be
mapped to a flattened directory structure retaining the package structure in the file name.
regexp Both the from and to patterns define regular expressions. Only files matching the
from expression are considered.

Mappers are used by <uptodate>,
<move>, <copy>, and <apply> and several other tasks.

<mapper type=”identity”/>
By default, the <copy> task uses the identity mapper. The following two <copy>
tasks have the same effect:
<copy todir=”new_web”>
<fileset dir=”web” includes=”**/*.jsp”/>
<mapper type=”identity”/>
</copy>
<copy todir=”new_web”>
<fileset dir=”web” includes=”**/*.jsp”/>
</copy>

<copy todir=”new_web”>
<fileset dir=”web” includes=”**/*.jsp”/>
<mapper type=”flatten”/>
</copy>

<copy todir=”output”>
<fileset dir=”data”/>
<mapper type=”merge” to=”data.dat”/>
</copy>
Assume that there is a single file in the data directory called data_20020202.dat, yet
this file name is dynamically generated. The use of the merge mapper will copy it to
the output directory with the name data.dat. This particular technique, remember, is
only useful with filesets containing a single file.

The glob mapper uses both the to and from attributes, each allowing a single asterisk
(*) pattern. The text matched by the pattern in the from attribute is substituted
into the to pattern.
<mapper type=”glob” from=”*.jsp” to=”*.jsp.bak”/>
The glob mapper is useful for making backup copies of files by copying them to new
names as shown in the example. Files not matching the from pattern are ignored.
<copy todir=”new_web”>
<fileset dir=”web” includes=”**/*.jsp”/>
<mapper type=”glob” from=”*.jsp” to=”*.jsp.bak” />
</copy>

<mapper type=”regexp” from=”^(.*).java$” to=”\1.java.bak”/>
The <copy> example shown for the glob mapper can be replicated using the
regexp mapper:
<copy todir=”new_web”>
<fileset dir=”web” includes=”**/*.jsp”/>
<mapper type=”regexp” from=”^(.*).jsp$” to=”\1.jsp.bak” />
</copy>

<property name=”results.dir” location=”test_results”/>
<uptodate property=”tests.uptodate”>
<srcfiles dir=”src” includes=”**/*.java”/>
<mapper type=”package” from=”*.java” to=”${results.dir}/TEST-*.xml” />
</uptodate>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are other data types

A

ZipFileset
Building an archive that contains the contents of other archive files can be accomplished
using the <zipfileset> datatype. A <zipfileset> not only allows putting
the contents of one archive inside another, it also provides the capability to prefix
an archives contents within another. For example, when building the WAR file for
our search engine application, we incorporate the Javadoc HTML in an api subdirectory
and our documentation under the help directory. These were not the directory
names used during our build process, yet the WAR file will have these names in its
structure.
<war destfile=”dist/antbook.war” webxml=”web.xml”>
<classes dir=”${build.classes.dir}”/>
.
.
.
<fileset dir=”web”/>
<zipfileset dir=”${javadoc.dir}” prefix=”api” />
<zipfileset dir=”${build.dir}/webdocs” prefix=”help”/>
</war>
The tasks that support the ZipFileset datatype are <zip>, <jar>, <war>, and <ear>.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly