[stringtemplate-interest] [ST4 Beta-4] Retrieving version information
Udo Borkowski
ub at abego-software.de
Sat Feb 12 15:22:42 PST 2011
Instead of writing the version information into a java file what about adding a file
"org/stringtemplate/v4/system.stg"
to the sources/jar with a content like this:
engineInfo ::= [
"v4_0b4":"",
"versionText":"StringTemplate 4.0b4",
"versionDate":"2011-02-28"
]
(ANT replacements already done)
This way people wishing to access the version information could just "import" the "system.stg" file and access the information through the map. E.g.
-----------
import "org/stringtemplate/v4/system.stg"
main(p) ::= <<
<if(engineInfo.v4_0b4)>
stuff special to v4_0b4
<endif>
<if(engineInfo.v4_0)>
stuff special to v4_0
<endif>
(Rendered with <engineInfo.versionText>)
>>
----------
would output:
---------
stuff special to v4_0b4
(Rendered with StringTemplate 4.0b4)
---------
(Notice: the map key with the version ("v4_0b4") must not start with a digit and not contain a "." (e.g. "4.0") because it could not be used in engineInfo.v4_0b4).
Obviously the (build-in) "system.stg" file could also used to include other interesting information about the system. And it easy to extend and maintain.
Udo
On 12.02.2011, at 21:42, Terence Parr wrote:
> Ah. so in the jar it's okay. cool. I tried to test that, but found javap not in my PATH on the Linux box :(
> Ter
> On Feb 12, 2011, at 12:34 PM, Oliver Zeigermann wrote:
>
>> Sources remain untouched
>>
>> Am 12.02.2011 20:26 schrieb "Terence Parr" <parrt at cs.usfca.edu>:
>>> didn't seem to work.
>>>
>>> public final static String VERSION = "@version@";
>>>
>>> in src zip.
>>>
>>> Ter
>>> On Feb 12, 2011, at 2:27 AM, Oliver Zeigermann wrote:
>>>
>>>> Using ant that is fairly easy. I attached a patch for the ant build
>>>> file that replaces every @version@ inside the source with the version
>>>> information from build.properties (no idea if this is the best
>>>> solution, though).
>>>>
>>>> E.g. adding
>>>>
>>>> public final static String VERSION = "@version@";
>>>>
>>>> to ST.java
>>>>
>>>> would result to
>>>>
>>>> public final static String VERSION = "4.0b4";
>>>>
>>>> in the compiled classes.
>>>>
>>>> Hope that helps
>>>>
>>>> - Oliver
>>>>
>>>> 2011/2/11 Udo Borkowski <ub at abego-software.de>:
>>>>> Hi Ter,
>>>>>
>>>>> I agree this will only work if the version information (text and/or boolean flag) is really in sync with the version control system (i.e. requires automated solution). Not sure how hard this is to implement.
>>>>>
>>>>> Regarding the test for the version: I haven't thought of this yet, but it would definitely be useful.
>>>>>
>>>>> Udo
>>>>>
>>>>> On 11.02.2011, at 00:55, Terence Parr wrote:
>>>>>
>>>>>> Hi Udo,
>>>>>>
>>>>>> Seems like the more common use case would be to test the version number and do something different to avoidable or use a feature only if a particular version is available. but we can't test values in the template so it would have to be a Boolean set for the various versions; might be hard to add one for every random version we make.
>>>>>>
>>>>>> <if(v4_0b1)>...<endif>
>>>>>>
>>>>>> Hmm... also I would have to figure out how to make ANT alter my software automatically to include the right version string; it would have to know about perforce version control and so on. setting this by hand would be a problem as it would get out of sync.
>>>>>>
>>>>>> Ter
>>>>>> On Feb 7, 2011, at 6:25 AM, Udo Borkowski wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> what about providing "version information" to be used in a template?
>>>>>>>
>>>>>>> I got this idea because I was using an older version of the engine (Beta3 instead of Beta4) without noticing.
>>>>>>>
>>>>>>>
>>>>>>> One could then use this information e.g. to include a text like
>>>>>>>
>>>>>>> "(Rendered with StringTemplate 4.0 Beta-4)"
>>>>>>>
>>>>>>> into generated web pages etc.
>>>>>>>
>>>>>>>
>>>>>>> One way to achieve this without adding "build-in" attributes etc. could be extending the class ST.
>>>>>>>
>>>>>>> E.g. add the following method to the class ST:
>>>>>>>
>>>>>>>
>>>>>>> public String getVersionText() {
>>>>>>> return "StringTemplate 4.0 Beta-4";
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> Then one could use
>>>>>>>
>>>>>>> (Rendered with <{ }.versionText>)
>>>>>>>
>>>>>>> in a template to render
>>>>>>>
>>>>>>> (Rendered with StringTemplate 4.0 Beta-4)
>>>>>>>
>>>>>>>
>>>>>>> Udo
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> stringtemplate-interest mailing list
>>>>>>> stringtemplate-interest at antlr.org
>>>>>>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>>>>>>
>>>>>> _______________________________________________
>>>>>> stringtemplate-interest mailing list
>>>>>> stringtemplate-interest at antlr.org
>>>>>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>>>>>
>>>>> _______________________________________________
>>>>> stringtemplate-interest mailing list
>>>>> stringtemplate-interest at antlr.org
>>>>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>>>>>
>>>> <build.xml.patch>_______________________________________________
>>>> stringtemplate-interest mailing list
>>>> stringtemplate-interest at antlr.org
>>>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>>>
>>> _______________________________________________
>>> stringtemplate-interest mailing list
>>> stringtemplate-interest at antlr.org
>>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list