私はこの質問はかなり古いですけど、ここでの考え方です。これは本当に純粋なantソリューションではないようですが、<scriptdef>
タグを使用してantにスクリプトを埋め込むことができます。ここで
を使用すると、XMLファイルで何かを検索し、プロパティに結果を格納するために使用できる機能です。
<scriptdef name="xpath-query" language="javascript">
<attribute name="query"/>
<attribute name="xmlfile"/>
<attribute name="property"/>
<![CDATA[
importClass(java.io.FileInputStream);
importClass(javax.xml.xpath.XPath);
importClass(javax.xml.xpath.XPathConstants);
importClass(javax.xml.xpath.XPathFactory);
importClass(org.xml.sax.InputSource);
importClass(java.lang.System);
var exp = attributes.get("query");
var filename = attributes.get("xmlfile");
var xpath = XPathFactory.newInstance().newXPath();
var input = new InputSource(new FileInputStream(filename));
var value = xpath.evaluate(exp, input, XPathConstants.STRING);
self.project.setProperty(attributes.get("property"), value);
System.out.println("Copied this value:" + value + " to this property:" + attributes.get("property"));
]]>
</scriptdef>
次に、あなたは、XPathクエリを使用して、アプリケーションの現在の名前を得ることができますあなたが定義したタスク:
<xpath-query query='pathToResources\resources\string[@name="app_name"]' xmlFile="app.xml" property="appName" />
次に、アプリケーション名はプロパティappName
に保存されます。
そこから、アプリ名を使ってxmlファイルのregex replaceを行うことができます。
<replaceregexp file="app.xml" match="${appName}" replace="${newAppName}" />
ダウンサイドこの特定のアプローチの可能性は、あなたがXMLファイルのどこかに同じアプリ名の文字列を持っている場合、正規表現で置き換えることであることは、あなたが意図していなかった何かを置き換えることができます。
おそらく<scriptdef>
を定義して、プロパティで見つかったものを格納するのではなく、置き換えを行うことができますが、私はこの部分を手軽に手に入れました。
のために働くあなたは解決策を見つけましたか? – Jovan