Actually, if you wanted to do it programatically in code and you could guarantee that each line had no more than one token, you could probably make it work by creating regular expressions. Here is some pseudocode:

   for each line in the template file
       pull out the token name from the line
create a regular expression from the line that anchors both ends and replaces the @token@ with a "(.*)"
       read equivalent line from the resulting file
       run regular expression on line
       if no match
           error out, this file was not generated from the template
       value of token is group 1
register token name, token value in a Properties object (or equivalent dict or hash construct)
   write Properties object to disk

So in your example, the regular expression would be "^this (.*) file$" and the group 1 match would give you "is a sample".

Translated into Java, this could be a custom task. Or it could be done with some script in an ant build file.

You could even make it work with multiple tokens on a line so long as enough characters showed up between the tokens that would not also show up in the substitution values.

[EMAIL PROTECTED] wrote:
No there isnt.

And I think this cant be done:
If you combine the template with the property values you doesnt have any 
markers where a property value starts and where it ends (if your template 
doesnt provide these). Therefore you cant parse the resulting file.

Example:

template
  this @value@ file
property
  value=is a sample
result
  this is a sample file

How you would parse the "this is a sample file" string?


Jan

-----Ursprüngliche Nachricht-----
Von: Patrick Martin [mailto:[EMAIL PROTECTED] Gesendet: Donnerstag, 6. September 2007 10:18
An: Ant User
Betreff: extract properties from file and corresponding template

Hello,

I have a file that was generated from a template and a set of
properties using ant filters.
Basically, the template contained tokens like @my.property@ which
where replaced by the corresponding value of ${my.property}.
template + properties >>> file

Now, I'd like to be able to get the set of properties back from this
file and the corresponding template.
file + template >>> properties

Is there any task out there that already exists for that?

Thank you,

Patrick

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



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


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

Reply via email to