我正在开发一个 ant 构建脚本来部署 jars。即只更新指定文件夹中的最终/测试版应用程序 jar。它检查部署的 jar 是否已经是最新的。如果是,它使用除非标志跳过运行目标。
以下是目标片段
<property name="deploy-dir-final" location="C:\Deploy\final" />
<property name="deploy-dir-beta" location="C:\Deploy\beta" />
<macrodef name="macro-deploy-jar">
<attribute name="deploydir" default="C:\Deploy\beta" />
<sequential>
<echo>Deploying jar</echo>
<copy overwrite="true" file="C:/project/application.jar" todir="@{deploydir}"/>
<echo>Deployed</echo>
</sequential>
</macrodef>
<target name="deploy-jar-final" depends="is-final-jar-up-to-date" unless="jar.isUpToDate">
<task-deploy-jar deploy-dir-path="${deploy-dir-final}"/>
</target>
<target name="deploy-jar-beta" depends="is-beta-jar-up-to-date" unless="jar.isBetaUpToDate">
<task-deploy-jar deploy-dir-path="${deploy-dir-beta}"/>
</target>
<target name="is-final-jar-up-to-date">
<echo message="Checking if deployed final jar is up-to-date"/>
<uptodate property="jar.isUpToDate" targetfile="${deploy-dir-final}/application.jar" >
<srcfiles dir= "${output-dir}" includes="application.jar"/>
</uptodate>
</target>
<target name="is-beta-jar-up-to-date">
<echo message="Checking if deployed beta jar is up-to-date"/>
<uptodate property="jar.isBetaUpToDate" targetfile="${deploy-dir-beta}/application.jar" >
<srcfiles dir= "${output-dir}" includes="application.jar"/>
</uptodate>
</target>
在部署 jar 目标的情况下,我使用 macrodef 进行代码重用。但在部署之前,我正在检查现有的 jar 是否已经是最新的。它通过依赖于目标的属性来完成。但我也可以在这里看到代码重用的范围,因为它的唯一不同之处在于路径。我不明白我们如何将参数传递给依赖目标。
在这种情况下,有什么方法可以使用类似于 macrodef 的代码重用?或者我们可以在 macordef 上使用 if 条件,以便它只在设置了某些属性时才运行。
或者任何其他方式我都可以实现相同的目标,而无需编写两个目标来检查最终和 beta jar,只是为了检查它们是否是最新的。