|
Re: replacing a token with the current date (plus time and/or version)? [message #256895 is a reply to message #256891] |
Mon, 13 October 2008 12:53 |
Eclipse User |
|
|
|
Originally posted by: eclipse-news.rizzoweb.com
Michael Moser wrote:
> I am seeking an way to change some placeholder (string) in my source
> code to the value of the data + time when the source code was compiled,
> such that the running application can later emit its compilation time
> (and ideally also the time and/or some running compilation number) in
> its help => about dialog.
>
> What's the cheapest (or most elegant) way to achieve this using eclipse
> (or its built-in ant)?
Eclipse's compiler has no capability for doing something like this, but
you could write a small Ant script that did the replace before
compilation happens, then add that Ant script as a custom builder to
your project. See
http://bewarethepenguin.blogspot.com/2008/08/customizing-bui lds-for-your-eclipse.html
(in your case you'll want to make sure your custom builder runs BEFORE
the Java Builder).
Hope this helps,
Eric
|
|
|
Re: replacing a token with the current date (plus time and/or version)? [message #256931 is a reply to message #256895] |
Wed, 15 October 2008 08:43 |
Michael Moser Messages: 914 Registered: July 2009 |
Senior Member |
|
|
Eric Rizzo wrote:
>> ..
> Eclipse's compiler has no capability for doing something like this,
> but you could write a small Ant script that did the replace before
> compilation happens, then add that Ant script as a custom builder to
> your project. See
> http://bewarethepenguin.blogspot.com/2008/08/customizing-bui lds-for-your-eclipse.html
> (in your case you'll want to make sure your custom builder runs BEFORE
> the Java Builder).
>
> Hope this helps,
> Eric
Thanks Eric,
that helped. I defined a build.xml containing an ant task that is
executed as part of the normal build.
One last question, tough. I am not exactly an ant guru and I find my
solution a bit trivial or, let say, not so elegant. What my ant-task
does is, to take a file "foo.template" which contains a token/substring
@timestamp@ and at each build it copies that file over to a file
"foo.java" while replacing that token with the current time.
Is there a solution to does something like that "inplace" - I mean,
without needing an additional ".template" file, but rather able to live
with the .java file only?
Some mechanism, that identifies an old date and timestamp within a
string (which might also be marked somehow, e.g. with a comment
preceeding that string declaration or such to easier identify it) and
replaces that with the current time?
Just curious to learn some new trick...
Michael
|
|
|
Re: replacing a token with the current date (plus time and/or version)? [message #256936 is a reply to message #256931] |
Wed, 15 October 2008 13:20 |
Eclipse User |
|
|
|
Originally posted by: eclipse-news.rizzoweb.com
Michael Moser wrote:
> Eric Rizzo wrote:
>>> ..
>> Eclipse's compiler has no capability for doing something like this,
>> but you could write a small Ant script that did the replace before
>> compilation happens, then add that Ant script as a custom builder to
>> your project. See
>> http://bewarethepenguin.blogspot.com/2008/08/customizing-bui lds-for-your-eclipse.html
>>
>> (in your case you'll want to make sure your custom builder runs BEFORE
>> the Java Builder).
>>
>> Hope this helps,
>> Eric
>
> Thanks Eric,
> that helped. I defined a build.xml containing an ant task that is
> executed as part of the normal build.
>
> One last question, tough. I am not exactly an ant guru and I find my
> solution a bit trivial or, let say, not so elegant. What my ant-task
> does is, to take a file "foo.template" which contains a token/substring
> @timestamp@ and at each build it copies that file over to a file
> "foo.java" while replacing that token with the current time.
>
> Is there a solution to does something like that "inplace" - I mean,
> without needing an additional ".template" file, but rather able to live
> with the .java file only?
> Some mechanism, that identifies an old date and timestamp within a
> string (which might also be marked somehow, e.g. with a comment
> preceeding that string declaration or such to easier identify it) and
> replaces that with the current time?
I can't think of any way to do that with built-in Ant tasks (but I'm
rusty, it has been a few years since I was doing much Ant writing); you
might want to ask on the Ant forums.
I do know that custom Ant tasks are pretty easy to write and this sounds
like a good candidate for that. Here's some links to get you started:
http://ant.apache.org/ant_task_guidelines.html
http://ant.apache.org/manual/develop.html
Eric
|
|
|
Powered by
FUDForum. Page generated in 0.03987 seconds