You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Luis N. Polasek" <lp...@sichile.cl> on 2002/08/06 21:37:46 UTC

Task to remove a method from .java file

Hi...

    I´m new to Ant, and after searching and not finding any solution, I came to this list to ask how do I remove a method from a .java source file using Ant.

    There is such a task to do this. Remember that the method can span in multiple lines, and can have a lot of { anf } (to do a regex replace)

                 Thanks in advance...




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task to remove a method from .java file

Posted by Matt Benson <gu...@yahoo.com>.
Whatever, but you can't do it in XML either.

-Matt

--- Steve Loughran <st...@iseran.com> wrote:
> 
> ----- Original Message -----
> From: "Luis N. Polasek" <lp...@sichile.cl>
> To: "Ant Users List" <an...@jakarta.apache.org>
> Sent: Tuesday, August 06, 2002 1:12 PM
> Subject: Re: Task to remove a method from .java file
> 
> 
> > Quoting Erik Hatcher
> <ja...@ehatchersolutions.com>:
> >
> > > This sounds like a pretty crazy thing to want to
> do, and there are
> > > certainly better patterns, but.... check out the
> trick I applied to
> > > Cactus testing, which got documented on their
> FAQ:
> > >
> > > <http://jakarta.apache.org/cactus/faq.html#faq2>
> > >
> > > You could have a filtered copy that commented
> out a section of code if
> > > desired.  Keep in mind that I do not endorse
> this type of thing, merely
> > > letting you know its possible!  :)
> > >
> > > Erik
> >
> >        That approach it�s ok for xml files, but it
> is difficult to
> implement in .java source files, since the
> commentaries are different you
> can use "//" to comment a single line, or "/*"  and
> "*/" to comment in
> multiple lines. and another problem in commenting
> its that you can have
> already set a commentari in the method you want to
> comment out.
> 
> that's a flaw in Java then, that you cant nest
> comments. In standard ML you
> can:
> 
> (* comment (* sub comment *) first comment *)
> 
> which leads to a different set of issues.
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task to remove a method from .java file

Posted by Steve Loughran <st...@iseran.com>.
----- Original Message -----
From: "Luis N. Polasek" <lp...@sichile.cl>
To: "Ant Users List" <an...@jakarta.apache.org>
Sent: Tuesday, August 06, 2002 1:12 PM
Subject: Re: Task to remove a method from .java file


> Quoting Erik Hatcher <ja...@ehatchersolutions.com>:
>
> > This sounds like a pretty crazy thing to want to do, and there are
> > certainly better patterns, but.... check out the trick I applied to
> > Cactus testing, which got documented on their FAQ:
> >
> > <http://jakarta.apache.org/cactus/faq.html#faq2>
> >
> > You could have a filtered copy that commented out a section of code if
> > desired.  Keep in mind that I do not endorse this type of thing, merely
> > letting you know its possible!  :)
> >
> > Erik
>
>        That approach it´s ok for xml files, but it is difficult to
implement in .java source files, since the commentaries are different you
can use "//" to comment a single line, or "/*"  and "*/" to comment in
multiple lines. and another problem in commenting its that you can have
already set a commentari in the method you want to comment out.

that's a flaw in Java then, that you cant nest comments. In standard ML you
can:

(* comment (* sub comment *) first comment *)

which leads to a different set of issues.




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task to remove a method from .java file

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Same issues apply to the XML trick too, and I denoted this by saying 
"Place no comments in the following section".  Its a trade-off, but if 
you do XML validation or compilation at build time you'll catch such 
screwups right away.

	Erik


Luis N. Polasek wrote:
> Quoting Erik Hatcher <ja...@ehatchersolutions.com>:
> 
> 
>>This sounds like a pretty crazy thing to want to do, and there are 
>>certainly better patterns, but.... check out the trick I applied to 
>>Cactus testing, which got documented on their FAQ:
>>
>><http://jakarta.apache.org/cactus/faq.html#faq2>
>>
>>You could have a filtered copy that commented out a section of code if 
>>desired.  Keep in mind that I do not endorse this type of thing, merely 
>>letting you know its possible!  :)
>>
>>	Erik
> 
> 
>        That approach it´s ok for xml files, but it is difficult to implement in .java source files, since the commentaries are different you can use "//" to comment a single line, or "/*"  and "*/" to comment in multiple lines. and another problem in commenting its that you can have already set a commentari in the method you want to comment out.
> 
>         Anyway, thanks for the tip.
> 
> 
>                           Best  regards.
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task to remove a method from .java file

Posted by David Jencks <da...@directvinternet.com>.
I agree it's sorely needed.  I used filter to replace some tokens either
with /* and */ or nothing, but this really sucks as a solution.

For this particular project, another completely different solution would be
to remove the ejb-lifecycle methods from the classes and use xdoclet to
generate the ejb-ized versions + interfaces + dds

david jencks

On 2002.08.06 17:10:51 -0400 Ian McFarland wrote:
> Sounds like #ifdef. Actually, some preprocessor-like stuff would be 
> quite a nice thing in Java, and in Ant. Is there anything like that, or 
> a clever way to do it with Ant? I didn't notice it, if there is, 
> although it sounds like the regex stuff could do it. Never thought to 
> try!
> 
> -Ian
> 
> On Tuesday, August 6, 2002, at 01:40  PM, Luis N. Polasek wrote:
> 
> > Quoting Matt Benson <gu...@yahoo.com>:
> >
> >> What is your purpose in removing a method from a Java
> >> source file?
> >
> >         That´s becaus I have a two releases of the same project, one 
> > using EJB and the other using only Tomcat. The idea is to strip the 
> > EJB methods form the <ComponentName>Beam  source file. This methods 
> > are (ejbCreate, ejbPassivate, etc).
> >
> >         And I´m trying using ant to automate the construction of the 
> > Tomcat version out from the EJB version.
> >
> >
> >
> > --
> > To unsubscribe, e-mail:   
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail: 
> > <ma...@jakarta.apache.org>
> >
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 
> 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task to remove a method from .java file

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
It wouldn't be preprocessing, for what I'm talking about.  There could 
simply be a switch that determined whether to build with or without an 
EJB layer:

	ant -Duse.ejb=false

Simple as that from the build perspective.  You could use conditional 
patternsets to include/exclude the appropriate code from compilation and 
control which targets are to be run to either build an EJB JAR or not, 
for example.

Under the covers of the code would entail an abstract factory or some 
such pattern to control which implementation is used at run-time, 
perhaps by use of a build-time configured JNDI lookup or from an 
embedded properties file in the distribution, or by looking for the 
existence of an implementation dynamically.

I'll leave the rest as an exercise for the reader!  :))

	Erik

Kevin Z Grey wrote:
> 
> How exactly would this pre-processing be done?  As a task that you 
> explicitly invoke on the necessary files or on the fly at compile time? 
> I could whip up the first one pretty fast...
> 
> ~~K
> 
> 
> Erik Hatcher wrote:
> 
>> Exactly... this is a perfect situation for an abstract factory, for 
>> example, or maybe a simple factory perhaps.
>>
>> Having Ant strip out some code is really the wrong way to go about 
>> this particular thing, even though its doable.
>>
>>     Erik
>>
>>
>> Matt Benson wrote:
>>
>>> I haven't written beans; however it seems like with
>>> the proper design this would be a non-issue?
>>>
>>> -Matt
>>>
>>> --- "Luis N. Polasek" <lp...@sichile.cl> wrote:
>>>
>>>> Quoting Matt Benson <gu...@yahoo.com>:
>>>>
>>>>
>>>>> What is your purpose in removing a method from a
>>>>
>>>>
>>>>
>>>> Java
>>>>
>>>>> source file?
>>>>
>>>>
>>>>
>>>>        That´s becaus I have a two releases of the
>>>> same project, one using EJB and the other using only
>>>> Tomcat. The idea is to strip the EJB methods form
>>>> the <ComponentName>Beam  source file. This methods
>>>> are (ejbCreate, ejbPassivate, etc).
>>>>
>>>>        And I´m trying using ant to automate the
>>>> construction of the Tomcat version out from the EJB
>>>> version.
>>>>
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task to remove a method from .java file

Posted by Kevin Z Grey <kz...@ntplx.net>.
How exactly would this pre-processing be done?  As a task that you 
explicitly invoke on the necessary files or on the fly at compile time? 
 I could whip up the first one pretty fast...

~~K


Erik Hatcher wrote:

> Exactly... this is a perfect situation for an abstract factory, for 
> example, or maybe a simple factory perhaps.
>
> Having Ant strip out some code is really the wrong way to go about 
> this particular thing, even though its doable.
>
>     Erik
>
>
> Matt Benson wrote:
>
>> I haven't written beans; however it seems like with
>> the proper design this would be a non-issue?
>>
>> -Matt
>>
>> --- "Luis N. Polasek" <lp...@sichile.cl> wrote:
>>
>>> Quoting Matt Benson <gu...@yahoo.com>:
>>>
>>>
>>>> What is your purpose in removing a method from a
>>>
>>>
>>> Java
>>>
>>>> source file?
>>>
>>>
>>>        That´s becaus I have a two releases of the
>>> same project, one using EJB and the other using only
>>> Tomcat. The idea is to strip the EJB methods form
>>> the <ComponentName>Beam  source file. This methods
>>> are (ejbCreate, ejbPassivate, etc).
>>>
>>>        And I´m trying using ant to automate the
>>> construction of the Tomcat version out from the EJB
>>> version.
>>>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task to remove a method from .java file

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Exactly... this is a perfect situation for an abstract factory, for 
example, or maybe a simple factory perhaps.

Having Ant strip out some code is really the wrong way to go about this 
particular thing, even though its doable.

	Erik


Matt Benson wrote:
> I haven't written beans; however it seems like with
> the proper design this would be a non-issue?
> 
> -Matt
> 
> --- "Luis N. Polasek" <lp...@sichile.cl> wrote:
> 
>>Quoting Matt Benson <gu...@yahoo.com>:
>>
>>
>>>What is your purpose in removing a method from a
>>
>>Java
>>
>>>source file?
>>
>>        That´s becaus I have a two releases of the
>>same project, one using EJB and the other using only
>>Tomcat. The idea is to strip the EJB methods form
>>the <ComponentName>Beam  source file. This methods
>>are (ejbCreate, ejbPassivate, etc).
>>
>>        And I´m trying using ant to automate the
>>construction of the Tomcat version out from the EJB
>>version.
>>
>>
>>
>>--
>>To unsubscribe, e-mail:  
>><ma...@jakarta.apache.org>
>>For additional commands, e-mail:
>><ma...@jakarta.apache.org>
>>
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Health - Feel better, live better
> http://health.yahoo.com
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task to remove a method from .java file

Posted by Matt Benson <gu...@yahoo.com>.
I haven't written beans; however it seems like with
the proper design this would be a non-issue?

-Matt

--- "Luis N. Polasek" <lp...@sichile.cl> wrote:
> Quoting Matt Benson <gu...@yahoo.com>:
> 
> > What is your purpose in removing a method from a
> Java
> > source file?
> 
>         That�s becaus I have a two releases of the
> same project, one using EJB and the other using only
> Tomcat. The idea is to strip the EJB methods form
> the <ComponentName>Beam  source file. This methods
> are (ejbCreate, ejbPassivate, etc).
> 
>         And I�m trying using ant to automate the
> construction of the Tomcat version out from the EJB
> version.
> 
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task to remove a method from .java file

Posted by Stefan Kost <s....@webmacher.de>.
There is another possible solution, it's abit hackish too.
Even though java has no real preprocessor, the compiler can behave the
same way. Just have a static class

final class SourceConfig {
	final static boolean ejbVersion=true;
}

Then use in the source

if(SourceConfig.ejbConfig==true) {
...
}

Finally, the ant-script just need to patch the SourceConfig class. SUch
comparissions with final static vars get optimized and if it evalues to
fasle, the innercode can never be called, so it is dropped when
compiling(I verified this with jode). Unfortunately this leaves empty
method skelletons in there. I am not sure how we could persuade the
compiler to drop them too.
I've just used this approch to wrap debug-output statements, so that I
can 100% drop them.

Stefan


> Sounds like #ifdef. Actually, some preprocessor-like stuff would be 
> quite a nice thing in Java, and in Ant. Is there anything like that, or 
> a clever way to do it with Ant? I didn't notice it, if there is, 
> although it sounds like the regex stuff could do it. Never thought to 
> try!
> 
> -Ian
> 
> On Tuesday, August 6, 2002, at 01:40  PM, Luis N. Polasek wrote:
> 
> > Quoting Matt Benson <gu...@yahoo.com>:
> >
> >> What is your purpose in removing a method from a Java
> >> source file?
> >
> >         That´s becaus I have a two releases of the same project, one 
> > using EJB and the other using only Tomcat. The idea is to strip the 
> > EJB methods form the <ComponentName>Beam  source file. This methods 
> > are (ejbCreate, ejbPassivate, etc).
> >
> >         And I´m trying using ant to automate the construction of the 
> > Tomcat version out from the EJB version.
> >
> >
> >
> > --
> > To unsubscribe, e-mail:   
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail: 
> > <ma...@jakarta.apache.org>
> >
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
-- 

 < W E B M A C H E R > 
EDV+INTERNETSERVICE GMBH

POST: August Bebel Str. 69
      04275 Leipzig

FON:  +49 341 30 34 833
FAX:  +49 341 30 34 840
WEB:  www.webmacher.de


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task to remove a method from .java file

Posted by Ian McFarland <ia...@neo.com>.
Sounds like #ifdef. Actually, some preprocessor-like stuff would be 
quite a nice thing in Java, and in Ant. Is there anything like that, or 
a clever way to do it with Ant? I didn't notice it, if there is, 
although it sounds like the regex stuff could do it. Never thought to 
try!

-Ian

On Tuesday, August 6, 2002, at 01:40  PM, Luis N. Polasek wrote:

> Quoting Matt Benson <gu...@yahoo.com>:
>
>> What is your purpose in removing a method from a Java
>> source file?
>
>         That´s becaus I have a two releases of the same project, one 
> using EJB and the other using only Tomcat. The idea is to strip the 
> EJB methods form the <ComponentName>Beam  source file. This methods 
> are (ejbCreate, ejbPassivate, etc).
>
>         And I´m trying using ant to automate the construction of the 
> Tomcat version out from the EJB version.
>
>
>
> --
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task to remove a method from .java file

Posted by "Luis N. Polasek" <lp...@sichile.cl>.
Quoting Matt Benson <gu...@yahoo.com>:

> What is your purpose in removing a method from a Java
> source file?

        That´s becaus I have a two releases of the same project, one using EJB and the other using only Tomcat. The idea is to strip the EJB methods form the <ComponentName>Beam  source file. This methods are (ejbCreate, ejbPassivate, etc).

        And I´m trying using ant to automate the construction of the Tomcat version out from the EJB version.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task to remove a method from .java file

Posted by Matt Benson <gu...@yahoo.com>.
What is your purpose in removing a method from a Java
source file?

-Matt

--- "Luis N. Polasek" <lp...@sichile.cl> wrote:
> Quoting Erik Hatcher
> <ja...@ehatchersolutions.com>:
> 
> > This sounds like a pretty crazy thing to want to
> do, and there are 
> > certainly better patterns, but.... check out the
> trick I applied to 
> > Cactus testing, which got documented on their FAQ:
> > 
> > <http://jakarta.apache.org/cactus/faq.html#faq2>
> > 
> > You could have a filtered copy that commented out
> a section of code if 
> > desired.  Keep in mind that I do not endorse this
> type of thing, merely 
> > letting you know its possible!  :)
> > 
> > 	Erik
> 
>        That approach it�s ok for xml files, but it
> is difficult to implement in .java source files,
> since the commentaries are different you can use
> "//" to comment a single line, or "/*"  and "*/" to
> comment in multiple lines. and another problem in
> commenting its that you can have already set a
> commentari in the method you want to comment out.
> 
>         Anyway, thanks for the tip.
> 
> 
>                           Best  regards.
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task to remove a method from .java file

Posted by "Luis N. Polasek" <lp...@sichile.cl>.
Quoting Erik Hatcher <ja...@ehatchersolutions.com>:

> This sounds like a pretty crazy thing to want to do, and there are 
> certainly better patterns, but.... check out the trick I applied to 
> Cactus testing, which got documented on their FAQ:
> 
> <http://jakarta.apache.org/cactus/faq.html#faq2>
> 
> You could have a filtered copy that commented out a section of code if 
> desired.  Keep in mind that I do not endorse this type of thing, merely 
> letting you know its possible!  :)
> 
> 	Erik

       That approach it´s ok for xml files, but it is difficult to implement in .java source files, since the commentaries are different you can use "//" to comment a single line, or "/*"  and "*/" to comment in multiple lines. and another problem in commenting its that you can have already set a commentari in the method you want to comment out.

        Anyway, thanks for the tip.


                          Best  regards.

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Task to remove a method from .java file

Posted by Ryan P Ripley <ry...@zimmer.com>.
Isn't this kind of like handing a child a gun and telling him not to
shoot people??

--Ryan

-----Original Message-----
From: Erik Hatcher [mailto:jakarta-ant@ehatchersolutions.com] 
Sent: Tuesday, August 06, 2002 2:49 PM
To: Ant Users List
Subject: Re: Task to remove a method from .java file


This sounds like a pretty crazy thing to want to do, and there are 
certainly better patterns, but.... check out the trick I applied to 
Cactus testing, which got documented on their FAQ:

<http://jakarta.apache.org/cactus/faq.html#faq2>

You could have a filtered copy that commented out a section of code if 
desired.  Keep in mind that I do not endorse this type of thing, merely 
letting you know its possible!  :)

	Erik


Luis N. Polasek wrote:
> Hi...
> 
>     I´m new to Ant, and after searching and not finding any solution, 
> I came to this list to ask how do I remove a method from a .java 
> source file using Ant.
> 
>     There is such a task to do this. Remember that the method can span

> in multiple lines, and can have a lot of { anf } (to do a regex 
> replace)
> 
>                  Thanks in advance...
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
> 
> 
> 



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task to remove a method from .java file

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
This sounds like a pretty crazy thing to want to do, and there are 
certainly better patterns, but.... check out the trick I applied to 
Cactus testing, which got documented on their FAQ:

<http://jakarta.apache.org/cactus/faq.html#faq2>

You could have a filtered copy that commented out a section of code if 
desired.  Keep in mind that I do not endorse this type of thing, merely 
letting you know its possible!  :)

	Erik


Luis N. Polasek wrote:
> Hi...
> 
>     I´m new to Ant, and after searching and not finding any solution, I came to this list to ask how do I remove a method from a .java source file using Ant.
> 
>     There is such a task to do this. Remember that the method can span in multiple lines, and can have a lot of { anf } (to do a regex replace)
> 
>                  Thanks in advance...
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>