Ant/Condition のバックアップ差分(No.7)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Ant/Condition へ行く。
- 1 (2007-06-28 (木) 14:20:56)
- 2 (2007-07-03 (火) 16:17:07)
- 3 (2007-07-26 (木) 15:15:38)
- 4 (2011-01-13 (木) 22:01:44)
- 5 (2011-01-14 (金) 17:13:05)
- 6 (2011-01-18 (火) 22:45:56)
- 7 (2011-05-02 (月) 20:42:46)
- 8 (2011-06-03 (金) 13:30:59)
- 9 (2013-10-30 (水) 21:54:15)
- 10 (2014-09-02 (火) 16:06:47)
- 11 (2014-10-02 (木) 15:21:04)
- 12 (2014-11-08 (土) 01:41:12)
- 13 (2015-09-29 (火) 20:01:25)
- 14 (2015-12-28 (月) 21:05:17)
- 15 (2017-10-27 (金) 16:26:13)
- 16 (2018-10-30 (火) 16:39:38)
- 17 (2023-01-06 (金) 14:56:43)
- 18 (2024-01-19 (金) 11:15:36)
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:Antで条件分岐 TITLE:AntでConditionタスクを使った条件分岐を行う #navi(../) *Antで条件分岐 [#e4a52cc4] *AntでConditionタスクを使った条件分岐を行う [#oe644be4] #adsense2 >編集者:[[Terai Atsuhiro>aterai]]~ 作成日:2007-03-13~ 更新日:&lastmod; #contents(none) *Conditionタスクで条件分岐 [#ub4e2947] **概要 [#a5d11f1d] Conditionタスクを使って、例えばディレクトリの有無などによる条件で、Targetタスクを実行するかどうかを振り分けます。 **サンプルターゲット [#rca1e6b2] **サンプルターゲット [#vb50fe42] #code{{ <!-- リソースディレクトリが存在すれば、プロパティ:have.resourcesは真 --> <condition property="have.resources"> <available file="${res.dir}" /> </condition> <!-- ターゲット:prepare-resourceは、プロパティ:have.resourcesが 真の場合実行される --> <target name="prepare-resource" depends="prepare" if="have.resources"> <!-- 以下、ビルド用のリソースディレクトリを作って、リソースをコピー --> <mkdir dir="${build.res}" /> <native2ascii encoding="UTF-8" src="${res.dir}" dest="${build.res}" includes="**/*.properties.utf8" ext="" /> <copy todir="${build.res}"> <fileset dir="${res.dir}" excludes="**/*.properties.*, **/*.bak" /> </copy> </target> ...省略... <!-- ターゲット:compileで、ターゲット:prepare-resourceは呼び出されるが、 実行されるされるかどうかはプロパティ:have.resourcesの値による --> <target name="compile" depends="prepare-src, prepare-resource"> <javac srcdir="${build.src}" destdir="${build.dest}" encoding="${compile.encoding}" debug="${compile.debug}" optimize="${compile.optimize}" source="${compile.source}" deprecation="${compile.deprecation}" classpathref="project.class.path" /> </target> }} -[[Resourceファイルからメニューバーを生成>Swing/ResourceMenuBar]] --http://terai.xrea.jp/swing/resourcemenubar/src.zip **解説 [#e3fa0bef] **解説 [#l19609ea] 上記のサンプルでは、Conditionタスクを使って、プロパティ:have.resourcesに真偽を代入しています。 ターゲット:prepare-resourceは、propertiesファイルをユニコードエスケープしますが、これは、プロパティ:have.resourcesが真(if="have.resources")の場合だけ実行されます。このため、リソースディレクトリが無い(エスケープするpropertiesファイルが無い)場合、あとでcompileターゲットで、ターゲット:prepare-resourceは呼び出されていますが、何もしないというサンプルになっています。 ---- 以下は、同様にConditionタスクを使って、libディレクトリが存在する場合、その下にあるjarファイルをパスに含めるように上書きするためのサンプルです。 #code{{ <path id="project.class.path"> <pathelement location="${build.dest}" /> <pathelement path="${java.class.path}" /> </path> <condition property="have.library"> <available file="${lib.dir}" /> </condition> <target name="init" if="have.library"> <path id="project.class.path"> <pathelement location="${build.dest}" /> <fileset dir="${lib.dir}"> <include name="*.jar" /> </fileset> <pathelement path="${java.class.path}" /> </path> </target> }} -[[JToolBarでアイコンボタンを右寄せ>http://terai.xrea.jp/Swing/ToolBarLayout.html]] --http://terai.xrea.jp/swing/toolbarlayout/src.zip **参考リンク [#ge402425] **参考リンク [#k20fd095] --[[Conditionタスク>http://www.jajakarta.org/ant/ant-1.5/docs/ant-1.5/j/docs/manual/CoreTasks/condition.html]] *Scriptタスクで条件分岐 [#h513b2dd] Conditionタスクの条件が複雑になるようなら、以下のようにして <script language="javascript">タスクなどでif文を使う方法もあります。 **コメント [#q2481444] - Scriptタスクを使用する方法は、[[AntのScriptタスク中でif文を使った条件分岐を行う>Ant/Script]]に移動しました。 -- [[aterai]] &new{2011-01-18 (火) 22:46:59}; **サンプルターゲット [#w745641f] #code{{ <target name="prepare-resource" depends="prepare"> <script language="javascript"><![CDATA[ importClass(java.io.File); if(new File(project.getProperty("res.dir")).exists()) { project.executeTarget("copy-resource"); } ]]></script> </target> <target name="copy-resource"> <mkdir dir="${build.res}" /> <copy todir="${build.res}"> <fileset dir="${res.dir}" excludes="**/*.properties.*, **/*.bak" /> </copy> </target> }} **参考リンク [#b96228dd] -[http://ant.apache.org/manual/Tasks/script.html Script Task] -[http://api.dpml.net/org/apache/ant/1.7.0/org/apache/tools/ant/Project.html Project (Apache Ant API) - Project] -[http://weblogs.java.net/blog/emcmanus/archive/2010/09/20/using-javascript-make-apache-ant-less-painful Using JavaScript to make Apache Ant less painful] *コメント [#e027f5e8] #comment