关于sap:SAP-Hybris使用recipe进行安装时是如何执行ant命令的

0次阅读

共计 1494 个字符,预计需要花费 4 分钟才能阅读完成。

关上 Hybris 装置文件夹下的 recipes,轻易关上一个 recipe 的 build.gradle 文件,发现应用了 installer-platform-plugin 和 installer-addon-plugin 这两个 plugin. Groovy setup 工作的逻辑,也就是应用这两个 plugin 里的实现,依据 config 实例化 platform 对象,而后调用其 setup 办法和 executeAntTarget 办法。

这两个办法的实现源代码在哪里?这就是本文所要形容的内容。

去 docs 文件夹里能够找到插件的实现源代码:

到源代码里依据 executeAntTarget 进行搜寻:

在 AbstractPlatform.groovy 里找到了 executeAntTarget 的实现逻辑,发现其 delegate 到了成员属性 antExecutor 里:

这个 antExecutor 的类型是 HybrisAntExecutor:

找到 HybrisAntExcutor,发现其只不过是调用类 HybrisPluginUtils 的静态方法:

静态方法之一:runProcess

实现外围:

private static void runExternalProcess(String workDir, String[] command, Closure closure) {def builder = new DefaultExecHandleBuilder()
        builder.setWorkingDir((new File(workDir)).absolutePath)
        builder.setCommandLine(command)
        if (closure) closure.call(builder)
        def handle = builder.build()
        handle.start()
        def result = handle.waitForFinish()

        if (result.getExitValue() != 0) {throw new IllegalStateException("external process returned non-zero exit code, command: ${command}")
        }
    }

运行内部程序的办法,应用的是 Groovy SDK 提供的 import org.gradle.process.internal.DefaultExecHandleBuilder.

静态方法之二:isWindowsOs

import org.apache.tools.ant.taskdefs.condition.Os

HybrisAntExcutor 办法之一:getWindowsAntCmd

    private String[] getWindowsAntCmd(String antArgs, String antOpts) {def antPreCommand = "set \"ANT_OPTS=${antOpts}\""antPreCommand +=" & set \"PLATFORM_HOME=${platformHome}\""
        antPreCommand += "& set \"ANT_HOME=${platformHome}\\apache-ant-1.9.1\""antPreCommand +=" & set \"PATH=${platformHome}\\apache-ant-1.9.1\\bin;%PATH%\""
        String antCommand = "${antPreCommand} & ant ${antArgs}"
        ['cmd', '/c', antCommand]
    }

要获取更多 Jerry 的原创文章,请关注公众号 ” 汪子熙 ”:

正文完
 0