如何宏观ify蚂蚁目标?

时间:2010-03-22 11:40:07

标签: ant

我希望能够让不同的目标做同样的事情,因为:

ant build   <- this would be a normal (default) build
ant safari  <- building the safari target.

目标看起来像这样:

<target name="build" depends="javac" description="GWT compile to JavaScript">
  <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
    <classpath>
      <pathelement location="src"/>
      <path refid="project.class.path"/>
    </classpath>
    <jvmarg value="-Xmx256M"/>
    <arg value="${lhs.target}"/>
  </java>
</target>

<target name="safari" depends="javac" description="GWT compile to Safari/JavaScript">
  <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
    <classpath>
      <pathelement location="src"/>
      <path refid="project.class.path"/>
    </classpath>
    <jvmarg value="-Xmx256M"/>
    <arg value="${lhs.safari.target}"/>
  </java>
</target>

(没关系第一个想法就是罢工:抛出蚂蚁!这还不是一个选项。)我尝试使用macrodef,但得到了一个奇怪的错误信息(即使消息并不暗示它,它认为它必须将目标放在顺序中)我不想像这样编写cmdline:ant -Dwhatever=nevermind。有什么想法吗?

1 个答案:

答案 0 :(得分:3)

我的第一次尝试(目前无法测试):

<target name="build" depends="javac, create.mymacro" description="GWT compile to JavaScript">
  <mymacro target="${lhs.target}"/>
</target>

<target name="safari" depends="javac, create.mymacro" description="GWT compile to Safari/JavaScript">
  <mymacro target="${lhs.safari.target}"/>
</target

<target name="create.mymacro">
  <macrodef name="mymacro">
    <attribute name="target" default="${lhs.target}"/>
    <sequential>
      <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
        <classpath>
          <pathelement location="src"/>
          <path refid="project.class.path"/>
        </classpath>
        <jvmarg value="-Xmx256M"/>
        <arg value="@{target}"/>
     </java>
    </sequential>
  </macrodef>
</target>
相关问题