----- Original Message -----
From: "Stephane Chauvin" <[EMAIL PROTECTED]>


> Magesh,
> Sorry to miss the great org/apache/tools/ant/filters package. It is a good
> job!
>
> For my needs, I have 2 questions:
> 1) I need to comment out my token, otherwise the compilation fails. And I
> have to compile before the replacement to use the serialver program. If I
am
> using ReplaceTokens, the comment characters are not replaced. Example:
>
> import java.io.Serializable;
> public class Test implements Serializable {
>     //@serialVersionUID@    // Serial Version UID
>
>     public Test(){
>
>     }
> }
> the result should be:
> import java.io.Serializable;
> public class Test implements Serializable {
>     private static final long serialVersionUID = 2010307013874058143L;
//
> Serial Version UID
>
>     public Test(){
>
>     }
> }
>
> A solution could be to define the "beginToken" to "//@". But this requires
> to change the definition of setBeginToken(char beginToken) to accept a
> String instead of a Char. Moreover, the number of spaces between "//" and
> the first "@" should be fixed. It is a small detail, not a big deal.

You can achieve this with what is currently available,
but it is perhaps not as elegant as one would like it
to be:

  <loadfile srcFile="Test.java" property="t">
    <filterchain>
      <replacetokens>
        <token key="serialVersionUID" value="private static final long
serialVersionUID = 2010307013874058143L;"/>
      </replacetokens>
      <replacetokens begintoken="/" endtoken=" ">
        <token key="/private" value="private "/>
      </replacetokens>
    </filterchain>
  </loadfile>
  <echo message="${t}"/>

>
> 2) The second point is about the token value. I do not know the token
value
> until I find the token key in the file. I run the serialver program on a
> class when I read the token in the source file. It is not a good idea to
run
> serialver before to parse the source file because this program fails when
it
> is not a Serializable class. It means it will be difficult to see the
> difference between an user error (when there is a token in a bad file),
and
> the normal reject. And I also prefer to print in the ANT output the SUID
> (serialver task) only when a file is tagged with this token, and not for
all
> the serializable files.
>
> I probably need to extend BaseFilterReader and create my own filterreader.
> Is that make sense?
>

Yes, it makes sense to write a special filterreader for this.
Instead of having replacesuid as a task, implement it as a
filterreader...  If you do so, you can automatically use
it in <copy>, <move>, <loadfile> (and a few other tasks in the
future).  Your task need not bother about creating the actual
file, etc.  It can be delegated to the parent task that uses
the filterreader.

> Thank you for any suggestions,
> Stephane.
>

Cheers,
Magesh

**********************************************
* Wisdom comes to those who live long enough *
* to see things twice.                       *
**********************************************



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to