Ant/Condition のバックアップの現在との差分(No.2)
- バックアップ一覧
- 差分 を表示
- 現在との差分 - 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のConditionタスクで条件分岐 #navi(../) *AntのConditionタスクで条件分岐 [#ba5cf55c] >編集者:[[Terai Atsuhiro>terai]]~ 作成日:2007-03-13~ 更新日:&lastmod; --- title: AntでConditionタスクを使った条件分岐を行う author: aterai pubdate: 2007-03-13 description: Conditionタスクを使って、Targetタスクを実行するかどうかを振り分けます。 --- #contents **概要 [#lc35ee3e] Conditionタスクを使って、例えばディレクトリの有無などによる条件で、Targetタスクを実行するかどうかを振り分けます。 * 概要 [#summary] `Condition`タスクを使って、例えばディレクトリの有無などによる条件で、`Target`タスクを実行するかどうかを振り分けます。 **サンプルターゲット [#rca1e6b2] `Script`タスクを使用する方法は、[[AntのScriptタスク中でif文を使った条件分岐を行う>Ant/Script]]に移動しました。 * サンプルターゲット [#example] #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の値による --> 実行されるかどうかはプロパティ: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> }} *解説 [#e3fa0bef] 上記のサンプルでは、Conditionタスクを使って、プロパティ:have.resourcesに真偽を代入しています。 - [[Resourceファイルからメニューバーを生成>Swing/ResourceMenuBar]]の[https://ateraimemo.com/swing/resourcemenubar/src.zip src.zip]などを参照 ターゲット:prepare-resourceは、propertiesファイルをユニコードエスケープしますが、これは、プロパティ:have.resourcesが真(if="have.resources")の場合だけ実行されます。このため、リソースディレクトリが無い(エスケープするpropertiesファイルが無い)場合、あとでcompileターゲットで、ターゲット:prepare-resourceは呼び出されていますが、何もしないというサンプルになっています。 * 解説 [#explanation] 上記のサンプルでは`Condition`タスクを使用して`have.resources`プロパティに真偽を代入しています。 - `prepare-resource`ターゲットは`properties`ファイルをユニコードエスケープし、`have.resources`プロパティが真(`if="have.resources"`)の場合のみ実行 - このためリソースディレクトリが存在しない(エスケープする`properties`ファイルがない)場合、`compile`ターゲットで`prepare-resource`ターゲットが呼び出されて何も実行しない ---- 以下は、同様にConditionタスクを使って、libディレクトリが存在する場合、その下にあるjarファイルをパスに含めるように上書きするためのサンプルです。 以下は、同様に`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> }} *参考リンク [#ge402425] --[[Conditionタスク>http://www.jajakarta.org/ant/ant-1.5/docs/ant-1.5/j/docs/manual/CoreTasks/condition.html]] --[[Condition - Ant詳説>http://homepage1.nifty.com/kuprij/antdoc/tasks/condition.html]] *コメント [#e027f5e8] - [[JToolBarでアイコンボタンを右寄せ>Swing/ToolBarLayout]]の、[https://ateraimemo.com/swing/toolbarlayout/src.zip src.zip]などを参照 * 参考リンク [#reference] - [https://ant.apache.org/manual/Tasks/conditions.html Conditions Task] - [https://ant.apache.org/manual/ifunless.html If and Unless on all tasks/nested elements] -- `Ant 1.9.1`からタスクなどに`if`、`unless`属性を使用可能になった * コメント [#comment] #comment - `Script`タスクを使用する方法は、[[AntのScriptタスク中でif文を使った条件分岐を行う>Ant/Script]]に移動しました。 -- &user(aterai); &new{2011-01-18 (火) 22:46:59}; #comment