ラベル ANT の投稿を表示しています。 すべての投稿を表示
ラベル ANT の投稿を表示しています。 すべての投稿を表示

2010年1月8日金曜日

ANTでSVNを使用。

ANTで拡張タスク「<svn>」を使ってみる。

必要なライブラリは「svnant」。
http://subclipse.tigris.org/svnant.html サイトでダウンロードする。

まず、「<svn>」タスクを使って「export」のテスト結果。
$ ant -lib ./lib -buildfile svn_export.xml
Buildfile: svn_export.xml

main:
[echo] called target main
[input] remote repository url=
{リポジトリURL}
[input] local export dir=
{ローカル保存先}
[input] svn userid=
{svnのユーザID}
[input] svn password=
{svnのパスワード}

export:
[echo] SVN エクスポート。。。
[svn] <Export> started ...
[svn] <Export> finished.

BUILD SUCCESSFUL
Total time: 23 seconds


実行するときに「svnant」ライブラリが格納されてるPATHを知らせる為、
「-lib」オプションを付けるのが重要!


ソース(svn_export.xml)は
<?xml version="1.0" encoding="UTF-8"?>
<project default="main" basedir=".">
<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" />

<!-- - - - - - - - - - - - - - - - - -
target: main
- - - - - - - - - - - - - - - - - -->
<target name="main">
<echo message="called target main" />
<input message="remote repository url=" addproperty="svn.repository" />
<input message="local export dir=" addproperty="svn.local" />
<input message="svn userid=" addproperty="svn.user" />
<input message="svn password=" addproperty="svn.password" />

<antcall target="export" />
</target>

<!-- - - - - - - - - - - - - - - - - -
target: export
- - - - - - - - - - - - - - - - - -->
<target name="export">
<echo>SVN エクスポート。。。</echo>
<svn username="${svn.user}" password="${svn.password}">
<export srcUrl="${svn.repository}" destPath="${svn.local}" />
</svn>
</target>
</project>


他のタスクや使い方は
http://subclipse.tigris.org/svnant/svn.html
を参照。

ANTでif文とfor文を使用。

ANTで拡張タスク「<if>」、「<for>」を使ってみる。

必要なライブラリは「ant-contrib」。
今回試してみたバージョンは「1.0b3」
ant-contrib サイトで「ant-contrib-1.0b3」をダウンロードする。

まず、「<if>」のテスト結果。
$ ant -buildfile if_test.xml
Buildfile: if_test.xml

main:
[echo] called target main
[echo] hello babukuma!
[echo] abcd else...

BUILD SUCCESSFUL
Total time: 0 seconds


ソース(if_test.xml)は
<?xml version="1.0" encoding="UTF-8"?>
<project default="main" basedir=".">
<!--<taskdef resource="net/sf/antcontrib/antlib.xml" />-->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>

<!-- - - - - - - - - - - - - - - - - -
target: main
- - - - - - - - - - - - - - - - - -->
<target name="main">
<echo message="called target main" />
<property name="babu" value="kuma" />

<if>
<isset property="babu" />
<then>
<echo message="hello babukuma!" />
</then>
<else>
<echo message="babukuma else..." />
</else>
</if>

<if>
<isset property="abcd" />
<then>
<echo message="hello abcd!" />
</then>
<else>
<echo message="abcd else..." />
</else>
</if>
</target>
</project>


「<for>」のテスト結果。
$ ant -buildfile for_test.xml
Buildfile: for_test.xml

main:
[echo] called target main

test:
[echo] MSG:1

test:
[echo] MSG:2

test:
[echo] MSG:3

test:
[echo] MSG:4

BUILD SUCCESSFUL
Total time: 0 seconds


ソース(for_test.xml)は
<?xml version="1.0" encoding="UTF-8"?>
<project default="main" basedir=".">
<!--<taskdef resource="net/sf/antcontrib/antlib.xml" />-->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>

<!-- - - - - - - - - - - - - - - - - -
target: main
- - - - - - - - - - - - - - - - - -->
<target name="main">
<echo message="called target main" />
<property name="msg.array" value="1,2,3,4" />

<for param="msg" list="${msg.array}">
<sequential>
<var name="msg" unset="true" />
<property name="msg" value="@{msg}" />
<antcall target="test" />
</sequential>
</for>
</target>

<!-- - - - - - - - - - - - - - - - - -
target: test
- - - - - - - - - - - - - - - - - -->
<target name="test">
<echo>MSG:${msg}</echo>
</target>
</project>


使ってみると結構便利だと俺は勝手に思った。(hiro_nemuさんには他のスクリプトでいいんじゃってつこまれたけど。)

2008年8月1日金曜日

[TIP] ANT SignedJar


<!-- =================================
target: signedjar
================================= -->
<target name="signedjar" depends="compress" description="SigneJar Create">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="lib/ant-contrib-1.0b3.jar" />
</classpath>
</taskdef>

<trycatch>
<try>
<echo message="KeyStroeを生成する。" />
<genkey
alias="BabukumaAlias"
keystore="BabukumaKeystore"
storepass="123456">
<dname>
<param name="CN" value="Babukuma Soft" />
<param name="OU" value="Babukuma" />
<param name="O" value="babukuma.com" />
<param name="L" value="Kanda" />
<param name="ST" value="Tokyo" />
<param name="C" value="JP" />
</dname>
</genkey>
<echo message="KeyStroeを生成しました。" />
</try>
<catch>
<echo message="KeyStroeが存在します。" />
</catch>
<finally>
</finally>
</trycatch>

<echo message="SingedJarを生成する。" />
<signjar
jar="${app.dist.path}/${jar.name}"
signedjar="${app.dist.path}/Signed${jar.name}"
alias="BabukumaAlias"
keystore="BabukumaKeystore"
storepass="123456"
verbose="true" />
</target>