文件结构:
.
├── build.xml
├── etc
│ ├── a
│ │ └── aa.proto
│ └── b
│ └── bb.proto
└── some.properties
一些属性:
a.aa.proto=propa
b.bb.proto=propb
构建.xml:
<project name="a" default="props" basedir=".">
<!-- define file containing *.proto propterties -->
<property name="prop.file" value="some.properties" />
<target name="props">
<echo>props file: ${prop.file}</echo>
<!-- create an OR regex based on file names
while stripping the path prefix -->
<pathconvert property="proto.files" pathsep="|">
<map from="${basedir}/etc/" to="" />
<fileset dir="${basedir}">
<include name="**/*.proto" />
</fileset>
</pathconvert>
<echo>proto files: ${proto.files}</echo>
<!-- load converted regex into new property -->
<loadresource property="proto.props">
<!-- use property as a resource, avoids temp files -->
<propertyresource name="proto.files" />
<!-- replace / with . -->
<filterchain>
<tokenfilter>
<filetokenizer />
<replacestring from="/" to="." />
</tokenfilter>
</filterchain>
</loadresource>
<echo>proto props: ${proto.props}</echo>
<!-- load properties matching the regex -->
<loadproperties srcfile="${prop.file}">
<filterchain>
<containsregex pattern="${proto.props}" />
</filterchain>
</loadproperties>
<!-- confirm -->
<echo>a:${a.aa.proto}</echo>
<echo>b:${b.bb.proto}</echo>
</target>
</project>
构建输出:
Buildfile: /tmp/a/build.xml
props:
[echo] props file: some.properties
[echo] proto files: a/aa.proto|b/bb.proto
[echo] proto props: a.aa.proto|b.bb.proto
[echo] a:propa
[echo] b:propb
BUILD SUCCESSFUL
Total time: 1 second