我对蚂蚁的了解几乎一无所获。 我明白它不应该被用作编程语言,但我是某个蚂蚁项目的消费者,并希望在使用项目提供给我的库时修改我自己项目中的某些内容。
我想要做的主要观点是我有一个字符串,需要在将其发送到父项目目标之前对其进行修改。
我尝试提供易于理解的代码,但目前我离开的部分是: 要么将值存储在变量而不是属性中(不知道如何执行此操作) 从我的javascript函数直接调用另一个目标。
所以这是代码:
<target name="deploy-custom" depends="init">
<scriptdef name="replaceString" language="javascript">
<attribute name="fileIn" />
<attribute name="directoryFile" />
<![CDATA[echo = project.createTask("echo");
var fileName = attributes.get("filein"); //get attribute for scriptdef
var directoryIn = attributes.get("directoryfile"); //get attribute for scriptdef
echo.setMessage("file name: " + fileName );
echo.perform( );
echo.setMessage("dir in " + directoryIn );
echo.perform( );
var fileOut = fileName.replace(directoryIn, "");
echo.setMessage("replace " + fileOut );
echo.perform( );
project.setProperty("undeploy_name", fileOut);]]>
</scriptdef>
<echo message="executing target deploy-custom" />
<for param="file">
<path>
<fileset dir="${mydir}/content/custom-deploy">
<include name="*.war" />
</fileset>
</path>
<sequential>
<replaceString fileIn="@{file}" directoryFile="${mydir}/content/custom-deploy/" />
<JBossCLI port="${jboss.port.management-native}">
<undeploy namePattern="${undeploy_name}" />
</JBossCLI>
<deployToLiferay file="@{file}" />
</sequential>
</for>
<echo>ABRS custom banklets deployed!</echo>
</target>
所以我的问题是在我尝试保存undeploy_name属性时,我可以调用目标deployToLiferay吗?如果没有,我可以将其保存在变量而不是属性中吗?
我不介意使用其他语言而不是javascript,但我不确定如何做我需要做的事情。
根据我在这里找到的信息,我现在正在努力专注于直接使用脚本。这是我得到的信息:
https://coderanch.com/t/108191/call-ant-macrodef-groovy-script
我试图将我的脚本修改为:
<macrodef name="undeploy">
<attribute name="undplPattern" />
<sequential>
<echo message="undeploy undplPattern @{undplPattern}" />
<JBossCLI port="${jboss.port.management-native}">
<undeploy namePattern="@{undplPattern}" />
</JBossCLI>
</sequential>
</macrodef>
<scriptdef name="undeploy-pattern" language="javascript">
<attribute name="fileIn" />
<attribute name="directoryFile" />
<![CDATA[
var echo = project.createTask("echo");
var fileName = attributes.get("filein"); //get attribute for scriptdef
var directoryIn = attributes.get("directoryfile"); //get attribute for scriptdef
echo.setMessage("file name: " + fileName );
echo.perform( );
echo.setMessage("dir in " + directoryIn );
echo.perform( );
var fileOut = fileName.replace(directoryIn, "");
fileOut = fileOut.replace(/\d+/g, "");
fileOut = fileOut.replace("..",".*");
fileOut = fileOut.replace(/[.]/g,"\\.");
fileOut = fileOut.replace("web-\\.*\\.war","web.*");
echo.setMessage("undeploy pattern transformation: " + fileOut );
echo.perform( );
var undeploy_t = project.createTask("undeploy");
undeploy_t.setDynamicAttribute("undplPattern", fileOut);
undeploy_t.perform( );
]]>
</scriptdef>
来自:
<echo message="item @{file}" />
<undeploy-pattern fileIn="@{file}" directoryFile="${currentScriptDirectory}/content/custom-banklets/" />
<deployToLiferay file="@{file}" />
在此修改之后,当我尝试设置setDynamicAttribute并执行该任务时,它现在失败。
08:01:18.492: item /data/com.client-dshbrd-banklet-web-0.0.1.war
08:01:18.509: file name: /data/com.client-dshbrd-banklet-web-0.0.1.war
08:01:18.510: dir in /data/
08:01:18.520: undeploy pattern transformation: com\.client-dshbrd-banklet-web.*
08:01:18.528: COMMAND 'deploy-custom-banklets' FAILED (execution time: 2 seconds)
08:01:18.528: * /data/contribution.xml:250: The following error occurred while executing this line:
08:01:18.528: * /data/contribution.xml:259: required attribute undplpattern not set
答案 0 :(得分:0)
我认为您不需要嵌入式脚本。我查看了逻辑,我认为使用ANT basename task来获取文件名会更简单。
├── build.xml
└── src
└── files
└── file1.war
项目运行如下
$ ant
build:
[echo] file1.war
<project name="demo" default="build">
<target name="build">
<basename property="undeploy_name" file="src/files/file1.war"/>
<echo>${undeploy_name}</echo>
</target>
</project>