views:

84

answers:

3

In my Ant build file, I'm using an encrypted property which I'm reading off a text file. I need to decrypt this in sort of a bootstrap target during my build process. How do I do this?

As an example, here are the contents of the files.

myFile.txt:

ENCRYPTED=encryptedtext

build.xml:

<project name="myProject" default="all">
<property file="myFile.txt">

<!--Specify bootstrap target here to perform the decryption task-->

<target name="myTarget">
<!--Use the decrypted property here-->

I get that one way to do this is to setup a target to perform the decryption, and add it as a depends in all the necessary targets. I don't want to do that. I'm interested in alternatives that make the process as clean as possible. This also means I've already considered solutions that go "Why don't you perform the decryption elsewhere and read it off from there?" and I'm not interested in them.

Thank you.

+5  A: 

In my opinion, contrary to your stated goal, I think the cleanest way to setup your requirements is to use the depends structure that ant provides. It was developed for just this purpose.

If you want to ensure that this decryption is run every time you run your ant process, and you still want to resist the urge to use the depends tool, you have the option of putting your decryption process in your ant.bat, before the call to ant proper, or wrap the ant.bat in your own decryptAndCallAnt.bat.

akf
Agreed. Why is having another target not "clean"?
spilth
Depends cannot be used to pass parameters, we can do so using antcall. But antcall also reparses the build file, so there is that overhead in performance, which depending on the size of build file, can be non trivial. So, most of the time Depends is better suited.
omermuhammed
I should have clarified what I meant by "clean". I was just interested in whether ANT provides such a bootstrap target. I understand what you're saying though, and I agree.
Suvesh Pratapa
+3  A: 

If you implement your own task to perform the decryption, you should be able to do something like this:

<decrypt file="myFile.txt" refid="decrypted.refid"/>
<property refid="decrypted.refid"/>

You implement your own task called decrypt, which reads myFile.txt and defines a resource with the ref-id decrypted.refid. The property task can read properties from any type of resource using the "ref-id" attribute. You'll have to do some digging into the Ant manual in order to figure out the details of how to defined your own task and how to define a resource containing the encrypted file contents, but it should be doable.

JesperE
Thank you. Up-vote for the detail.
Suvesh Pratapa
A: 

With newer versions of Ant (since 1.6 I think) tasks do not need to contained in a target. If you always want certain tasks to execute just don't wrap them in a target.