我对蚂蚁几乎一无所知。我知道它不应该被用作编程语言,但是我是某个ant项目的使用者,我想在使用项目提供的库时修改我自己的项目中的一些东西。
我想做的主要工作是我有一个字符串,需要在将它发送到父项目目标之前修改它。
我将尝试提供易于理解的代码,但目前我剩下的部分是:要么将值存储在变量中而不是属性(不确定如何做到这一点)中直接调用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发布于 2017-05-09 21:08:21
我不认为你需要一个嵌入式脚本。我回顾了逻辑,我认为使用ANT basename任务来获得文件名会更简单。
示例
├── build.xml
└── src
└── files
└── file1.war项目运行情况如下
$ ant
build:
[echo] file1.warbuild.xml
<project name="demo" default="build">
<target name="build">
<basename property="undeploy_name" file="src/files/file1.war"/>
<echo>${undeploy_name}</echo>
</target>
</project>https://stackoverflow.com/questions/43841687
复制相似问题