代码之家  ›  专栏  ›  技术社区  ›  Yoni

AntCall和Ant任务有什么区别?

ant
  •  12
  • Yoni  · 技术社区  · 15 年前

    Antcall任务之间是否存在实质性差异(描述 here )和蚂蚁任务(描述 here ,除了Ant任务运行在不同的构建文件上之外?

    1 回复  |  直到 14 年前
        1
  •  8
  •   user159088    15 年前

    这真的取决于你所说的“实质性差异”是什么意思。不同的是,一个调用另一个,所以基本上是相同的,但在不同的上下文中使用。

    这是一段来自 defaults.properties 它定义了标准的Ant任务:

    ant=org.apache.tools.ant.taskdefs.Ant
    antcall=org.apache.tools.ant.taskdefs.CallTarget
    ...........
    

    如果打开这些任务的源代码,您将看到 CallTarget 包含一个 Ant 对象并将大部分工作委托给它:

    public class CallTarget extends Task {
        private Ant callee;
        ...........
        ...........
        /**
         * Delegate the work to the ant task instance, after setting it up.
         * @throws BuildException on validation failure or if the target didn't
         * execute.
         */
        public void execute() throws BuildException {
            if (callee == null) {
                init();
            }
            if (!targetSet) {
                throw new BuildException(
                    "Attribute target or at least one nested target is required.",
                     getLocation());
            }
            callee.setAntfile(getProject().getProperty("ant.file"));
            callee.setInheritAll(inheritAll);
            callee.setInheritRefs(inheritRefs);
            callee.execute();
        }
        ..........
        ..........
    }