English 中文(简体)
Is there any way to specify a bootstrap target in an ANT build file?
原标题:

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.

最佳回答

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.





相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签