Bug 31271 - enhance copy task: error if tokenvalues are missing when filtering
Summary: enhance copy task: error if tokenvalues are missing when filtering
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: unspecified
Hardware: All other
: P3 enhancement with 5 votes (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2004-09-17 07:39 UTC by Holger Krauth
Modified: 2009-07-31 05:41 UTC (History)
0 users



Attachments
Zip of the project reflecting my suggestion: unzip and README.txt, please (785.59 KB, application/octet-stream)
2004-09-17 07:43 UTC, Holger Krauth
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Holger Krauth 2004-09-17 07:39:57 UTC
Given you are familiar with ANT copy task terms:

For efficient usage of tokenfiltering I was missing
(1) an error message if a tokens value could not be found in a filtersfile
(2) a warning if a filtersfile contains a tokenvalue that is never used

Therefore I wrote a <checkTokens>-Task which I would like to donate to ANT.


If this sounds interesting to you, see the README.txt in the attached .zip (if I
manage to attach it, me, the Bugzilla novice :-)

Regards,
  Holger
Comment 1 Holger Krauth 2004-09-17 07:43:21 UTC
Created attachment 12756 [details]
Zip of the project reflecting my suggestion: unzip and README.txt, please
Comment 2 Holger Krauth 2004-09-17 07:45:54 UTC
Abstract:
=========

<checkToken> is a custom ANT-Task that can be used together with the
tokenfiltering of
the <copy>-task. It fails if at least one tokens is not supplied a value and
warns if values are supplied without matching tokens.

It can also be used to assure that different properties files contain the same
set of keys.

This .tar.gz is intended to illustrate the enhancement request to ANT that I made.

I assume that you read this after having seen my enhancement request in Bugzilla and
unpacked the attached checkTokens.tar.gz, so you know about ANT.
If not check out http://ant.apache.org.

Holger Krauth (Holger.Krauth@danet.de/Holger.Krauth@web.de)


Background Tokenfiltering:
==========================

The copy task inside ANT has a built in feature called tokenfiltering.
If switched on, it parses all files to be copied for tokens and replaces
all tokens with values found in the fiven filtersfile.

Thus, you can define your application's "demo.properties" as a pattern, e.g.
containing
the line "port=@_port_@", the latter "port" being the token.
(The default token delimiters '@' are inappropriate if there is a comma separated
list of smtp addresses somewhere in your properties files!
Thus I chose to take '@_' and '_@' repectively).

Having 2 filtersfiles "test.properties" and "production.properties"
containing the line "port=2222" and "port=1111" enables you to produce (via ANTs
copy)
a "demo.properties" containing either "port=2222" or "port=1111" depending on
the filtersfile passed when copying with tokenfiltering.

A nice side effect is that all environment specific settings are gathered in one
single
filtersfile.


Motivation:
===========

We use tokenfiltering a lot to build applications for different environments:
local, inhouseTest, testSystem, production...

For efficient usage of tokenfiltering I was missing
(1) an error message if a tokens value could not be found in a filtersfile
(2) a warning if a filtersfile contains a tokenvalue that is never used

If you need to be convinced about the necessity:
Imagine a property connect.as.uid= being empty due to tokenname mistyping just
for the production
built of your application and to connecting to a database a anonymous and so
never retrieving the
whole data but just what anonymous can so and so due to missing values
assuming... Contact me
for colourful examples from real life.


Contents:
=========

./README.txt
./build.xml
./runDemo.sh

./src/java/jakarta/contribution/suggestion/ant/Demo.java
./src/java/jakarta/contribution/suggestion/ant/CheckTokens.java

./src/build-patterns/demo.properties

./src/build-environments/test.properties
./src/build-environments/production.properties

./src/test/jakarta/contribution/suggestion/ant/CheckTokensTest.java

./lib/ant-1.5.jar
./lib/junit-3.8.1.jar
./doc/api/index.html


Running Demo:
=============

This mini-project contains a Demo.main() being:

        Properties p = new Properties();
        p.load(ClassLoader.getSystemResource("demo.properties").openStream());
        System.out.println("Connecting to " + p.getProperty("host") + ":"
                + p.getProperty("port"));

The shippend build.xml can build this demo application for environment "test" or
"production":

$ ...checkTokens/ > ant test.deploy
[...]
$ ...checkTokens/ > runDemo.sh
Connecting to testhost:2222

$ ...checkTokens/ > ant production.deploy
[...]
$ ...checkTokens/ > runDemo.sh
Connecting to PRODUCTION-HOST:1111


These build targets are depending on the <checkTokens> task which can easily be
provoked to fail:
Open the ./src/build-environments/production.properties and change the line
port=1111
to be
CORRUPTport=1111


Building again will end up like:
$ ...checkTokens/ > ant production.deploy
[...]
checkTokens:
[checktokens] production.properties contains unused value 'CORRUPTport'!
[checktokens] production.properties provides no value for 'port' from
demo.properties!

BUILD FAILED
file:/home/hokr/projects/checkTokens/build.xml:83: There were errors.


Here "contains unused" is just a warning, whereas "provides no value" is an error.


For further details, please refer to the code.
or send me your comments, remarks, suggestions to Holger.Krauth@danet.de

Thank you for reading.

Regards,
  Holger Krauth