You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Jens Riboe <je...@ribomation.com> on 2004/04/28 13:34:58 UTC
Redefinition of fileset
Hi,
I'm investigating how to use <typedef>, by redefining <fileset> and use in
in a context expecting an ordinary ditto. However, it doesn't work as
expected.
Ant reports a redefinition
Trying to override old definition of datatype fileset
But I cannot see any traceout of the new fileset implementation.
I'm using
xyz> ant -version
Apache Ant version 1.6.1 compiled on February 12 2004
Am I missing something or cannot I redefine fileset like the example below?
Many thanks in advance, for any light on this problem.
Cheers,
Jens
---build.xml------------------------------------------------------
<target name="tst.fileset" depends="compile" >
<typedef name="fileset"
classname="com.ribomation.anttasks.dependencylist.MyFileSet">
<classpath> <pathelement location="${class.dir}"/> </classpath>
</typedef>
<delete dir="${tmp.dir}" quiet="true" />
<mkdir dir="${tmp.dir}" />
<mkdir dir="${tmp.dir}/input" />
<antcall target="mktmp">
<param name="tmp.dir" value="${tmp.dir}/input"/>
</antcall>
<antcall target="mktmp">
<param name="tmp.dir" value="${tmp.dir}/input"/>
</antcall>
<concat destfile="${tmp.dir}/RESULT.txt" append="true">
<fileset dir="${tmp.dir}/input"/>
</concat>
<loadfile property="txt" srcFile="${tmp.dir}/RESULT.txt"/>
<echo message="Content: [${txt}]"/>
</target>
<target name="mktmp">
<tempfile property="tmpfile" destdir="${tmp.dir}" prefix="t"
suffix=".txt"/>
<echo message="Hello " file="${tmpfile}" />
</target>
---------------------------------------------------------------
---OUTPUT------------------------------------------------------
xyz> ant tst.fileset
Buildfile: build.xml
init.props:
init.dirs:
init:
compile:
[javac] Compiling 4 source files to C:\hack-cvs\DEPEND~1\target\classes
tst.fileset:
Trying to override old definition of datatype fileset
[delete] Deleting directory C:\hack-cvs\DEPEND~1\target\tmp
[mkdir] Created dir: C:\hack-cvs\DEPEND~1\target\tmp
[mkdir] Created dir: C:\hack-cvs\DEPEND~1\target\tmp\input
mktmp:
mktmp:
[echo] Content: [Hello Hello ]
BUILD SUCCESSFUL
Total time: 2 seconds
---------------------------------------------------------------
---MyFileSet------------------------------------------------------
public class MyFileSet extends FileSet {
public DependencyFileSet() {
this.getProject().log("[MyFileSet] init", Project.MSG_WARN);
}
public DirectoryScanner getDirectoryScanner(Project p) {
this.getProject().log("[MyFileSet] getDirectoryScanner()",
Project.MSG_WARN);
return super.getDirectoryScanner(p);
}
public void setDir(File dir) throws BuildException {
this.getProject().log("[MyFileSet] setDir("+dir+")",
Project.MSG_WARN);
}
}
---------------------------------------------------------------
Ant's own <concat> contains the following snippet
for (Enumeration e = sources.elements(); e.hasMoreElements();) {
Object o = e.nextElement();
if (...} else if (o instanceof FileSet) {
FileSet fileSet = (FileSet) o;
DirectoryScanner scanner =
fileSet.getDirectoryScanner(getProject());
checkAddFiles(fileSet.getDir(getProject()),
scanner.getIncludedFiles());
} else ...}
}
I inserted a print statement into MyFileSet.getDirectoryScanner()
and expected to see
[MyFileSet] getDirectoryScanner()"
in the OUTPUT.
The concat task contains this method for adding a FileSet.
public void addFileset(FileSet set) {
sources.addElement(set);
}
I thought my own fileset would be substituted instead.
Re: Redefinition of fileset
Posted by Jens Riboe <je...@ribomation.com>.
Thanks, the 'ant-type' trick made my day ;-)
I changed the typedef name to 'foo' instead of fileset
and added
ant-type="foo"
in the fileset inside concat
and now it works as expected.
/jens
Peter Reilly wrote:
> The <fileset> nested element in <concat> and most (as in all current)
> tasks
>
> is not a typedef, but the class "org.apache.tools.ant.types.FileSet"
> (The java code is void addFileSet(FileSet x)), so just redefining
> the fileset type will have no impact on the nested elements.
>
> There is two solutions, both involve using a typedef:
> use a typedef to define a new fileset type
> <typedef name="ribomatic.fileset" classname="....">
> <classpath ,,>
> </typedef>
>
> 1) use an id for the fileset and use that
> 2) use the undocumented ant-type attribute to set
> the class to use for the nested element
>
> Example:
>
> <scripttypedef name="myfileset" language="beanshell">
> import org.apache.tools.ant.types.FileSet;
> public class MyFileSet extends FileSet {
> }
> </scripttypedef>
> <myfileset id="x" dir="." includes="*.xml"/>
> <concat>
> <fileset refid="x"/>
> </concat>
>
> <concat>
> <fileset ant-type="myfileset" dir="." includes="*.xml"/>
> </concat>
>
> Peter
>
> Jens Riboe wrote:
>
>> Hi,
>>
>> I'm investigating how to use <typedef>, by redefining <fileset> and
>> use in
>> in a context expecting an ordinary ditto. However, it doesn't work as
>> expected.
>>
>> Ant reports a redefinition
>> Trying to override old definition of datatype fileset
>> But I cannot see any traceout of the new fileset implementation.
>>
>> I'm using
>> xyz> ant -version
>> Apache Ant version 1.6.1 compiled on February 12 2004
>>
>> Am I missing something or cannot I redefine fileset like the example
>> below?
>>
>> Many thanks in advance, for any light on this problem.
>> Cheers,
>> Jens
>>
>> ---build.xml------------------------------------------------------
>> <target name="tst.fileset" depends="compile" >
>> <typedef name="fileset"
>> classname="com.ribomation.anttasks.dependencylist.MyFileSet">
>> <classpath> <pathelement location="${class.dir}"/>
>> </classpath>
>> </typedef>
>>
>> <delete dir="${tmp.dir}" quiet="true" />
>> <mkdir dir="${tmp.dir}" />
>> <mkdir dir="${tmp.dir}/input" />
>> <antcall target="mktmp">
>> <param name="tmp.dir" value="${tmp.dir}/input"/>
>> </antcall>
>> <antcall target="mktmp">
>> <param name="tmp.dir" value="${tmp.dir}/input"/>
>> </antcall>
>>
>> <concat destfile="${tmp.dir}/RESULT.txt" append="true">
>> <fileset dir="${tmp.dir}/input"/>
>> </concat>
>> <loadfile property="txt" srcFile="${tmp.dir}/RESULT.txt"/>
>> <echo message="Content: [${txt}]"/>
>> </target>
>>
>> <target name="mktmp">
>> <tempfile property="tmpfile" destdir="${tmp.dir}" prefix="t"
>> suffix=".txt"/>
>> <echo message="Hello " file="${tmpfile}" />
>> </target>
>> ---------------------------------------------------------------
>>
>> ---OUTPUT------------------------------------------------------
>> xyz> ant tst.fileset
>> Buildfile: build.xml
>> init.props:
>> init.dirs:
>> init:
>> compile:
>> [javac] Compiling 4 source files to
>> C:\hack-cvs\DEPEND~1\target\classes
>> tst.fileset:
>> Trying to override old definition of datatype fileset
>> [delete] Deleting directory C:\hack-cvs\DEPEND~1\target\tmp
>> [mkdir] Created dir: C:\hack-cvs\DEPEND~1\target\tmp
>> [mkdir] Created dir: C:\hack-cvs\DEPEND~1\target\tmp\input
>> mktmp:
>> mktmp:
>> [echo] Content: [Hello Hello ]
>> BUILD SUCCESSFUL
>> Total time: 2 seconds
>> ---------------------------------------------------------------
>>
>> ---MyFileSet------------------------------------------------------
>> public class MyFileSet extends FileSet {
>> public DependencyFileSet() {
>> this.getProject().log("[MyFileSet] init", Project.MSG_WARN);
>> }
>> public DirectoryScanner getDirectoryScanner(Project p) {
>> this.getProject().log("[MyFileSet] getDirectoryScanner()",
>> Project.MSG_WARN);
>> return super.getDirectoryScanner(p);
>> }
>> public void setDir(File dir) throws BuildException {
>> this.getProject().log("[MyFileSet] setDir("+dir+")",
>> Project.MSG_WARN);
>> }
>> }
>> ---------------------------------------------------------------
>>
>> Ant's own <concat> contains the following snippet
>> for (Enumeration e = sources.elements(); e.hasMoreElements();) {
>> Object o = e.nextElement();
>> if (...} else if (o instanceof FileSet) {
>> FileSet fileSet = (FileSet) o;
>> DirectoryScanner scanner =
>> fileSet.getDirectoryScanner(getProject());
>> checkAddFiles(fileSet.getDir(getProject()),
>> scanner.getIncludedFiles());
>> } else ...}
>> }
>>
>> I inserted a print statement into MyFileSet.getDirectoryScanner()
>> and expected to see
>> [MyFileSet] getDirectoryScanner()"
>> in the OUTPUT.
>>
>> The concat task contains this method for adding a FileSet.
>> public void addFileset(FileSet set) {
>> sources.addElement(set);
>> }
>> I thought my own fileset would be substituted instead.
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
Re: Redefinition of fileset
Posted by Peter Reilly <pe...@corvil.com>.
The <fileset> nested element in <concat> and most (as in all current) tasks
is not a typedef, but the class "org.apache.tools.ant.types.FileSet"
(The java code is void addFileSet(FileSet x)), so just redefining
the fileset type will have no impact on the nested elements.
There is two solutions, both involve using a typedef:
use a typedef to define a new fileset type
<typedef name="ribomatic.fileset" classname="....">
<classpath ,,>
</typedef>
1) use an id for the fileset and use that
2) use the undocumented ant-type attribute to set
the class to use for the nested element
Example:
<scripttypedef name="myfileset" language="beanshell">
import org.apache.tools.ant.types.FileSet;
public class MyFileSet extends FileSet {
}
</scripttypedef>
<myfileset id="x" dir="." includes="*.xml"/>
<concat>
<fileset refid="x"/>
</concat>
<concat>
<fileset ant-type="myfileset" dir="." includes="*.xml"/>
</concat>
Peter
Jens Riboe wrote:
> Hi,
>
> I'm investigating how to use <typedef>, by redefining <fileset> and
> use in
> in a context expecting an ordinary ditto. However, it doesn't work as
> expected.
>
> Ant reports a redefinition
> Trying to override old definition of datatype fileset
> But I cannot see any traceout of the new fileset implementation.
>
> I'm using
> xyz> ant -version
> Apache Ant version 1.6.1 compiled on February 12 2004
>
> Am I missing something or cannot I redefine fileset like the example
> below?
>
> Many thanks in advance, for any light on this problem.
> Cheers,
> Jens
>
> ---build.xml------------------------------------------------------
> <target name="tst.fileset" depends="compile" >
> <typedef name="fileset"
> classname="com.ribomation.anttasks.dependencylist.MyFileSet">
> <classpath> <pathelement location="${class.dir}"/>
> </classpath>
> </typedef>
>
> <delete dir="${tmp.dir}" quiet="true" />
> <mkdir dir="${tmp.dir}" />
> <mkdir dir="${tmp.dir}/input" />
> <antcall target="mktmp">
> <param name="tmp.dir" value="${tmp.dir}/input"/>
> </antcall>
> <antcall target="mktmp">
> <param name="tmp.dir" value="${tmp.dir}/input"/>
> </antcall>
>
> <concat destfile="${tmp.dir}/RESULT.txt" append="true">
> <fileset dir="${tmp.dir}/input"/>
> </concat>
> <loadfile property="txt" srcFile="${tmp.dir}/RESULT.txt"/>
> <echo message="Content: [${txt}]"/>
> </target>
>
> <target name="mktmp">
> <tempfile property="tmpfile" destdir="${tmp.dir}" prefix="t"
> suffix=".txt"/>
> <echo message="Hello " file="${tmpfile}" />
> </target>
> ---------------------------------------------------------------
>
> ---OUTPUT------------------------------------------------------
> xyz> ant tst.fileset
> Buildfile: build.xml
> init.props:
> init.dirs:
> init:
> compile:
> [javac] Compiling 4 source files to
> C:\hack-cvs\DEPEND~1\target\classes
> tst.fileset:
> Trying to override old definition of datatype fileset
> [delete] Deleting directory C:\hack-cvs\DEPEND~1\target\tmp
> [mkdir] Created dir: C:\hack-cvs\DEPEND~1\target\tmp
> [mkdir] Created dir: C:\hack-cvs\DEPEND~1\target\tmp\input
> mktmp:
> mktmp:
> [echo] Content: [Hello Hello ]
> BUILD SUCCESSFUL
> Total time: 2 seconds
> ---------------------------------------------------------------
>
> ---MyFileSet------------------------------------------------------
> public class MyFileSet extends FileSet {
> public DependencyFileSet() {
> this.getProject().log("[MyFileSet] init", Project.MSG_WARN);
> }
> public DirectoryScanner getDirectoryScanner(Project p) {
> this.getProject().log("[MyFileSet] getDirectoryScanner()",
> Project.MSG_WARN);
> return super.getDirectoryScanner(p);
> }
> public void setDir(File dir) throws BuildException {
> this.getProject().log("[MyFileSet] setDir("+dir+")",
> Project.MSG_WARN);
> }
> }
> ---------------------------------------------------------------
>
> Ant's own <concat> contains the following snippet
> for (Enumeration e = sources.elements(); e.hasMoreElements();) {
> Object o = e.nextElement();
> if (...} else if (o instanceof FileSet) {
> FileSet fileSet = (FileSet) o;
> DirectoryScanner scanner =
> fileSet.getDirectoryScanner(getProject());
> checkAddFiles(fileSet.getDir(getProject()),
> scanner.getIncludedFiles());
> } else ...}
> }
>
> I inserted a print statement into MyFileSet.getDirectoryScanner()
> and expected to see
> [MyFileSet] getDirectoryScanner()"
> in the OUTPUT.
>
> The concat task contains this method for adding a FileSet.
> public void addFileset(FileSet set) {
> sources.addElement(set);
> }
> I thought my own fileset would be substituted instead.
>
>
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org