您好,登錄后才能下訂單哦!
打開Hybris安裝文件夾下的recipes,隨便打開一個recipe的build.gradle文件,發(fā)現(xiàn)使用了installer-platform-plugin和installer-addon-plugin這兩個plugin. Groovy setup任務(wù)的邏輯,也就是使用這兩個plugin里的實(shí)現(xiàn),根據(jù)config實(shí)例化platform對象,然后調(diào)用其setup方法和executeAntTarget方法。
這兩個方法的實(shí)現(xiàn)源代碼在哪里?這就是本文所要描述的內(nèi)容。
去docs文件夾里可以找到插件的實(shí)現(xiàn)源代碼:
到源代碼里根據(jù)executeAntTarget進(jìn)行搜索:
在AbstractPlatform.groovy里找到了executeAntTarget的實(shí)現(xiàn)邏輯,發(fā)現(xiàn)其delegate到了成員屬性antExecutor里:
這個antExecutor的類型是HybrisAntExecutor:
找到HybrisAntExcutor,發(fā)現(xiàn)其只不過是調(diào)用類HybrisPluginUtils的靜態(tài)方法:
實(shí)現(xiàn)核心:
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}") } }
運(yùn)行外部程序的方法,使用的是Groovy SDK提供的import org.gradle.process.internal.DefaultExecHandleBuilder.
import org.apache.tools.ant.taskdefs.condition.Os
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的原創(chuàng)文章,請關(guān)注公眾號"汪子熙":
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。