开发者

Is there any way to specify a bootstrap target in an ANT build file?

开发者 https://www.devze.com 2022-12-15 06:59 出处:网络
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?

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 decr开发者_开发百科yption, 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.


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号