如何为给定文件中的每一行执行ant任务?

时间:2010-08-06 12:55:54

标签: ant

我需要为给定文件中的每一行执行一个ant任务。任何想法都赞赏。

1 个答案:

答案 0 :(得分:2)

我有一个属性文件,用于定义需要运行的进程。这一切都在一行上以逗号分隔,而不是您指定的多行。这个answer显示了如何迭代文件。

env.start=webserver:localhost, dataserver:localhost

然后在处理应用程序执行的ant文件中,我有以下内容

<target name="start-all" description="Start all processes specified in target-info.properties:env.start">
        <foreach list="${env.start}" trim="yes" param="process.and.host" target="-start-process"/>
</target>

<target name="-start-process">
        <property name="colon.separated.pattern" value="([^:]*):([^:]*)"/>
        <propertyregex property="process" input="${process.and.host}" regexp="${colon.separated.pattern}" select="\1"/>
        <propertyregex property="host" input="${process.and.host}" regexp="${colon.separated.pattern}" select="\2"/>
        <condition property="start.target" value="start-${process}" else="-start-process-ssh">
            <equals arg1="${host}" arg2="localhost" trim="yes" casesensitive="no"/>
        </condition>
        <antcall target="${start.target}"/>
</target>
然后为env.start属性中定义的进程执行

$ {start.target},例如

<target name="start-webserver" description="Start the webserver on this machine">
        <echo>** Starting webserver **</echo>
        <run-script dir="${project.base.dir}/apache-tomcat" script="${project.base.dir}/apache-tomcat/bin/startup" spawn="yes">
            <args>
                <env key="CATALINA_HOME" value="${project.base.dir}/apache-tomcat"/>
                <env key="CATALINA_PID" value="${project.base.dir}/apache-tomcat/logs/pid_catalina"/>
            </args>
        </run-script>
</target>

<target name="start-dataserver" depends="decipher_caldb_password,check-event-seed,run-prestart-sql" description="Start the dataserver on this machine">
        <run-calypso process="dataserver" class="calypsox.apps.startup.StartNOGUI" failonerror="yes"
            args="-class com.calypso.apps.startup.StartDataServer"/>
</target>

我可以通过运行

启动env.start中定义的所有进程
ant -f run.xml start-all
相关问题