You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Sony Antony <so...@gmail.com> on 2010/07/05 02:17:20 UTC

Overriding ant task

Hi :
Im trying to modify the <copy> task so that if a token seen in the
file being copied, is undefined in teh <filterset>, the build will
fail..
( It will also list all teh undefined tokens encountered against the
corresponding file name )

1. Was there an way to do this without writing java code ?

2. I have already made the changes required in teh ant source code.
But I cant figure out how to execute my code.
I created a jar file with just the changed class files, and did a
<taskdef> with this jar file.
But none of my files got executed.
Since my class files were packaged just like teh original ant
classfiles, it appeard that ant ignored them completely thinking that
those class files have already been loaded.

Is there a way around it so that class files seen inside my jar file
will be picked up first and the remaining files will be resolved from
the original ant classloader

Thanks
--sony

Files being changed and packaged inside antfix.jar
apache-ant-1.8.1/src/main/org/apache/tools/ant/taskdefs/Copy.java
apache-ant-1.8.1/src/main/org/apache/tools/ant/types/FilterSet.java
apache-ant-1.8.1/src/main/org/apache/tools/ant/types/FilterSetCollection.java
apache-ant-1.8.1/src/main/org/apache/tools/ant/util/ResourceUtils.java

<taskdef name="copy2" classname="org.apache.tools.ant.taskdefs.Copy"
classpath="/path/to/antfix.jar"/>

Doesnt work :
<target name="try">
        <copy2 file="srcfile" toFile="destfile">
<filterset begintoken="@" endtoken="#">
<filter token="TOK1" value="VAL1"/>
<filter token="TOK2" value="VAL2"/>
</filterset>
        </copy2>
        </target>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Overriding ant task

Posted by Sony Antony <so...@gmail.com>.
Thank you David :
Your sugegstion as it is will not work for me as once I copy teh
files, I wont have teh names ( I mape them ).
But Im convinced that your approach in general is better than changing
eth source code.

So I decided to use filter chains.

Basically I m trying to first copy the files in one filterreader, and
the next one will check if there are still unexpanded tokens left.

I have the following problems now :
1. What is teh equivalent filter reader for the folloing
<filterset begintoken="@" endtoken="#" filtersfile="props" recurse="true"/>

Following works only in ant 8.1 ( I found out about propertiesresource
after reading teh sourcecode )
 <filterchain>
          <replacetokens begintoken="@" endtoken="#"
propertiesresource="props"/>
</filterchain>

2. I couldnt find any filterreader corresponding to <fail> ( I want to
do a <tokenfilter> /<containsregex> and trigger failure if there are
tokens still left )
Do I need to write a new filterreader  that will throw a
BuildException() for this ?

--sony


--sony

On Mon, Jul 5, 2010 at 1:39 AM, David Weintraub <qa...@gmail.com> wrote:
> Seems like a lot of work. Why not do the <copy> task with the filter,
> then use a mechanism to test the copied files to see if any tokens
> exist. You can use the <concat> command with the <containsregex>
> filter to see if any tokens (Pattern = /@\w+@/) exists in the files
> just copied.
>
> If you do find such files exist, you can fail the build.
>
> On Sun, Jul 4, 2010 at 7:17 PM, Sony Antony <so...@gmail.com> wrote:
>> Hi :
>> Im trying to modify the <copy> task so that if a token seen in the
>> file being copied, is undefined in teh <filterset>, the build will
>> fail..
>> ( It will also list all teh undefined tokens encountered against the
>> corresponding file name )
>>
>> 1. Was there an way to do this without writing java code ?
>>
>> 2. I have already made the changes required in teh ant source code.
>> But I cant figure out how to execute my code.
>> I created a jar file with just the changed class files, and did a
>> <taskdef> with this jar file.
>> But none of my files got executed.
>> Since my class files were packaged just like teh original ant
>> classfiles, it appeard that ant ignored them completely thinking that
>> those class files have already been loaded.
>>
>> Is there a way around it so that class files seen inside my jar file
>> will be picked up first and the remaining files will be resolved from
>> the original ant classloader
>>
>> Thanks
>> --sony
>>
>> Files being changed and packaged inside antfix.jar
>> apache-ant-1.8.1/src/main/org/apache/tools/ant/taskdefs/Copy.java
>> apache-ant-1.8.1/src/main/org/apache/tools/ant/types/FilterSet.java
>> apache-ant-1.8.1/src/main/org/apache/tools/ant/types/FilterSetCollection.java
>> apache-ant-1.8.1/src/main/org/apache/tools/ant/util/ResourceUtils.java
>>
>> <taskdef name="copy2" classname="org.apache.tools.ant.taskdefs.Copy"
>> classpath="/path/to/antfix.jar"/>
>>
>> Doesnt work :
>> <target name="try">
>>        <copy2 file="srcfile" toFile="destfile">
>> <filterset begintoken="@" endtoken="#">
>> <filter token="TOK1" value="VAL1"/>
>> <filter token="TOK2" value="VAL2"/>
>> </filterset>
>>        </copy2>
>>        </target>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>
>
>
> --
> David Weintraub
> qazwart@gmail.com
>
> ---------------------------------------------------------------------
> 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: Overriding ant task

Posted by David Weintraub <qa...@gmail.com>.
Seems like a lot of work. Why not do the <copy> task with the filter,
then use a mechanism to test the copied files to see if any tokens
exist. You can use the <concat> command with the <containsregex>
filter to see if any tokens (Pattern = /@\w+@/) exists in the files
just copied.

If you do find such files exist, you can fail the build.

On Sun, Jul 4, 2010 at 7:17 PM, Sony Antony <so...@gmail.com> wrote:
> Hi :
> Im trying to modify the <copy> task so that if a token seen in the
> file being copied, is undefined in teh <filterset>, the build will
> fail..
> ( It will also list all teh undefined tokens encountered against the
> corresponding file name )
>
> 1. Was there an way to do this without writing java code ?
>
> 2. I have already made the changes required in teh ant source code.
> But I cant figure out how to execute my code.
> I created a jar file with just the changed class files, and did a
> <taskdef> with this jar file.
> But none of my files got executed.
> Since my class files were packaged just like teh original ant
> classfiles, it appeard that ant ignored them completely thinking that
> those class files have already been loaded.
>
> Is there a way around it so that class files seen inside my jar file
> will be picked up first and the remaining files will be resolved from
> the original ant classloader
>
> Thanks
> --sony
>
> Files being changed and packaged inside antfix.jar
> apache-ant-1.8.1/src/main/org/apache/tools/ant/taskdefs/Copy.java
> apache-ant-1.8.1/src/main/org/apache/tools/ant/types/FilterSet.java
> apache-ant-1.8.1/src/main/org/apache/tools/ant/types/FilterSetCollection.java
> apache-ant-1.8.1/src/main/org/apache/tools/ant/util/ResourceUtils.java
>
> <taskdef name="copy2" classname="org.apache.tools.ant.taskdefs.Copy"
> classpath="/path/to/antfix.jar"/>
>
> Doesnt work :
> <target name="try">
>        <copy2 file="srcfile" toFile="destfile">
> <filterset begintoken="@" endtoken="#">
> <filter token="TOK1" value="VAL1"/>
> <filter token="TOK2" value="VAL2"/>
> </filterset>
>        </copy2>
>        </target>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>



-- 
David Weintraub
qazwart@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org