5445 次
4 に答える
4
$ {destdir}がこのような「spring-beans」で終わるかどうかをテストできます(ant-contribがあり、Ant 1.7以降を使用していると仮定します)。
<property name="destdir" value="something\spring-beans" />
<condition property="destDirHasBeans">
<matches pattern=".*spring-beans$" string="${destdir}" />
</condition>
<if>
<equals arg1="destDirHasBeans" arg2="true" />
<then>
$destdir ends with spring-beans ...
</then>
<else> ...
</else>
</if>
正規表現パターンの「$」は".*spring-beans$"
、文字列の最後に一致するアンカーです。
于 2013-01-31T04:13:00.363 に答える
3
Matteoのように、Ant-Contribには素晴らしいものがたくさん含まれているので、私はそれを頻繁に使用します。
ただし、この場合は、次の<basename>
タスクを使用できます。
<basename property="basedir.name" file="${destdir}"/>
<condition property="ends.with.spring-beans">
<equals arg1="spring-beans" arg2="${basedir.name}"/>
<condition>
プロパティ${ends.with.spring-beans}
には、true
if${destdir}
がで終わる場合string-beans
とfalse
そうでない場合が含まれます。if
タスクのまたはunless
パラメータで使用でき<target>
ます。
于 2012-11-30T17:35:36.677 に答える
0
Ant-ContribのEndWith条件を使用できます
<endswith string="${destdir}" with="spring-beans"/>
例えば
<if>
<endswith string="${destdir}" with="spring-beans"/>
<then>
<!-- do something -->
</then>
</if>
編集
<endswith>
Ant-Contribパッケージの一部であり、でインストールして有効にする必要があります。
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
于 2012-11-30T17:18:34.783 に答える
0
JavaScriptの機能は、ANTでの文字列操作に使用できます。
<script language="javascript"> <![CDATA[
// getting the value for property sshexec.outputproperty1
str = project.getProperty("sshexec.outputproperty1");
// get the tail , after the separator ":"
str = str.substring(str.indexOf(":")+1,str.length() ).trim();
// store the result in a new property
project.setProperty("res",str);
]]> </script>
<echo message="Responce ${res}" />
于 2015-12-28T12:29:54.817 に答える