Line | |
---|
1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
2 | <project name="loadproperties-test"
|
---|
3 | basedir="."
|
---|
4 | default="testPrefixedProperties">
|
---|
5 |
|
---|
6 | <target name="init">
|
---|
7 | </target>
|
---|
8 |
|
---|
9 | <target name="testPrefixedProperties" depends="init">
|
---|
10 | <property name="server" value="localhost"/>
|
---|
11 | <echo file="properties.tmp">
|
---|
12 | #http.@PORT@ = 90
|
---|
13 | http.@PORT@ = 80
|
---|
14 | http.@SERVER@ = ${server}
|
---|
15 | </echo>
|
---|
16 | <loadproperties srcFile="properties.tmp">
|
---|
17 | <filterchain>
|
---|
18 | <striplinecomments>
|
---|
19 | <comment value="#"/>
|
---|
20 | </striplinecomments>
|
---|
21 | <prefixlines prefix="server1."/>
|
---|
22 | <replacetokens>
|
---|
23 | <token key="PORT" value="port"/>
|
---|
24 | <token key="SERVER" value="server"/>
|
---|
25 | </replacetokens>
|
---|
26 | <expandproperties/>
|
---|
27 | </filterchain>
|
---|
28 | </loadproperties>
|
---|
29 | <property name="server1.http.url"
|
---|
30 | value="http://${server1.http.server}:${server1.http.port}"/>
|
---|
31 | </target>
|
---|
32 |
|
---|
33 | <target name="testPropertiesFromResource" depends="init">
|
---|
34 | <echo file="properties.tmp">
|
---|
35 | #tpfr.a=a
|
---|
36 | tpfr.a=A
|
---|
37 | tpfr.b=b\
|
---|
38 | e
|
---|
39 | tpfr.c=@C@
|
---|
40 | </echo>
|
---|
41 | <loadproperties resource="properties.tmp" classpath="${basedir}">
|
---|
42 | <filterchain>
|
---|
43 | <replacetokens>
|
---|
44 | <token key="C" value="sea"/>
|
---|
45 | </replacetokens>
|
---|
46 | </filterchain>
|
---|
47 | </loadproperties>
|
---|
48 | <condition property="testPropertiesFromResource.ok">
|
---|
49 | <equals arg1="Abesea" arg2="${tpfr.a}${tpfr.b}${tpfr.c}" />
|
---|
50 | </condition>
|
---|
51 | <fail unless="testPropertiesFromResource.ok">
|
---|
52 | $${tpfr.a}$${tpfr.b}$${tpfr.c}="${tpfr.a}${tpfr.b}${tpfr.c}"
|
---|
53 | </fail>
|
---|
54 | </target>
|
---|
55 |
|
---|
56 | <target name="cleanup">
|
---|
57 | <delete file="properties.tmp"/>
|
---|
58 | </target>
|
---|
59 |
|
---|
60 | </project>
|
---|
Note:
See
TracBrowser
for help on using the repository browser.