开发者

How to macro-ify ant targets?

I want to be able to have different targets doing nearly the same thing, as so:

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

The targets look like this:

<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>

(Nevermind the first thought that strikes: throw out ant! That's not an option just yet.) I tried using macrodef, but got a strange error message (even though the message didn't imply it, it think it had to do with putting a target in sequential). I don't want write a cmdline as so: ant -Dwhatever=nevermind. Any ideas?


My first try (without being able to test it at the moment):

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜