[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[jfriends-ml 10753] MJP Item11 の実行結果



 井上泰です。

長文です。xmlタグがあります。サーバーにクロスサイト
スクリプティング対策が施されていると期待しています。

--------------------------------------------
MJP Item11のbuild.xmlの動作確認結果です。

ダウンロードしたままでは動きません。
時間がなくCruiseControlは未確認です。

1. project
default属性を追加
2. init
OK。initでproperty設定は行わず。
projectのタスクとして実行したほうが良いと思う。
3. javac
OK。encoding="SJIS"を追加した
4. junit
antの実行時にCLASSPATHにjuit.jarがなければ動かない
xml出力で漢字文字化け
xml -> html変換がうまくできていない
5. path
OK
6. prepare
depends="init"依存関係を追加するかどうか。
7. help
日本語化
8. clean
if="builddir"を追加
9. cvs
cvsがあらかじめインストールされていること。
Windows 環境にCygwinをインストールした
10. Bagrat
インストール処理にMySQLのDDL/DML発行を追加
Bagratのweb.xmlはそのままでは動作しないので修正
11. JDepend
antの実行時にCLASSPATHにjdepend.jarがなければ動かない
12. JavaNCSS
動作させただけ
13. Splash
setproxyタスクを追加。動作未確認
URLの指定:
jdk1.4.2では、file://
jdk1.3.1では、file:///
14. CheckStyle
動作させただけ
15. Javadoc
encoding追加
複数のソースディレクトリ、パッケージ、クラスパスに対応できるように変更した。
16. war
OK
JMXを使用してTomcatへの配備ができたと思う。(要調査)
17. SQL
OK
SQL文
直接記述する場合、CDATAセクションに記述するべきだろう。
src属性でファイルから読み込むことができる。
18. CruiseControl
未確認

おまけを追加しました
echoメッセージ表示
native2ascii
jalopy
asyle
Oracle用のSQL発行

以下はbuild.xmlです。
==================================================================================

<?xml version="1.0" encoding="Shift_JIS"?>
<!--
このxmlファイルのencodingはShift_JIS。
このファイルをLinux, Solarisで実行しても漢字は正常に表示される。
antがxmlファイルを読み込むとき、encodingからunicodeへコード変換がなされる。
<echo>タスクで表示する文字列は、出力時にunicodeからネイティブコードに変
換される。
-->
<project name="lifecycle management" default="help">
<!--
<project>のdefault属性は必須。なければ実行時エラー。
antのFAQで、defaultはヘルプ表示にするよう勧めている。
-->

<!--

必要ソフトウェア一覧

More Java Pitfalls サンプルソースの入手
http://www.wiley.com/legacy/compbooks/daconta/mjp/sourcecode.html
ant の入手
http://ant.apache.org/bindownload.cgi
jdkの入手
http://java.sun.com/j2se/downloads.html

junitの入手
http://www.junit.org/index.htm
Checkstyleの入手
http://checkstyle.sourceforge.net/
CVS: (Cygwinの入手; Windows環境でのみ必要)
http://cygwin.com/
JDependの入手
http://www.clarkware.com/software/JDepend.html
Bagratの入手
http://www.gjt.org/pkg/bugrat/
JavaNCSSの入手
http://www.kclee.com/clemens/java/javancss/
MySQL JDBCドライバーの入手
http://www.mysql.com/downloads/api-jdbc-stable.html
CruiseControlの入手
http://cruisecontrol.sourceforge.net/download.html

参考:(MJP以外)
Jalopyの入手
http://prdownloads.sourceforge.net/jalopy/jalopy-ant-0.6.1.zip
AStyleの入手
http://sourceforge.net/projects/astyle
Oracle JDBCドライバーの入手
http://otn.oracle.co.jp/software/tech/java/jdbc/

(すべてのタスクを実行させるための)環境変数の設定例

Windows

set ANT_HOME=c:\java\apache-ant-1.5.3-1
set JAVA_HOME=c:\java\j2sdk1.4.1_03
set JUNIT_HOME=c:\java\junit3.8.1
set JDEPEND_HOME=C:\java\jdepend-2.6

set CLASSPATH=.
set CLASSPATH=%JUNIT_HOME%\junit.jar;%CLASSPATH%
set CLASSPATH=%JDEPEND_HOME%\lib\jdepend.jar;%CLASSPATH%

set
PATH=C:\PROGRA~1\HOLON\XonWindows\bin;%ANT_HOME%\bin;%JAVA_HOME%\bin;%PATH%

@rem set ORACLE_HOME=C:\oracle\ora90

-->
<!--
*******************************************************
** Initialize global properties.
****************************************************
initを実行しなければプロパティが設定されない。
すべてのtargetがinitに依存するのなら、projectのタスクとして<property>タ
スクを実行するほうが好ましい。

個別プロパティ指定 'ant -D<プロパティ>=<値> <ターゲット>'
プロパティファイル指定: 'ant -propertyfile <プロパティファイル> <ター
ゲット>'
ファイル指定 <property file="<プロパティファイル>"/>
プロパティ指定 <property name="<プロパティ>" value="<値>"/>
連続実行指定: 'ant init[,<ターゲット>]*'
実行できなくする: <taeget>の属性if="<プロパティ>"と指定する。
依存関係を指定する: <taeget>の属性depends="init"と指定する。

-->

<target name="init" description="initialize lifecycle properties.">

<tstamp/>
<property name="testdir" value="." />
<property name="rootdir" value="."/>
<property name="builddir" value="build"/>
<property name="driver" value="org.gjt.mm.mysql.Driver" />
<property name="url" value="jdbc:mysql://192.168.0.6/State" />
<property name="userid" value="" />
<property name="password" value="" />
<property name="destdir" value="bugrat" />
<property name="zip.bugrat"
value="C:/Documents/Software/java/BugRat/bugrat-2.5.3.zip" />
<property name="destdir.bugrat" value="${destdir}/test" />
<property name="catalina.home" value="c:\apache\tomcat403"/>
<property name="cvs.repository"
value=":pserver:username@hostname:c:/cvsrep"/>
<property name="cvs.package" value="tests"/>

</target>

<!--
*******************************************************
** Java compilation
****************************************************
<javac>タスクでソースファイルのエンコーディングを指定する。
Shift_JISの場合、encoding="SJIS"と記述。
指定可能なエンコーディング名は以下のとおり。
http://java.sun.com/j2se/1.4/ja/docs/ja/guide/intl/encoding.doc.html
-->

<target name="compileProps">
<!-- プロパティ設定: 一度設定すると、この<project>(jvmプロセス)で有効 -->
<property name="appl.src.dir" value="./src"/>
<property name="appl.bin.dir" value="./bin"/>
<property name="org.junit.dir" value="C:/java/junit3.8.1"/>
</target>

<target name="compile"
depends="init,compileProps"
description="SJISで記述されたソースファイルをコンパイルする">

<javac srcdir="${appl.src.dir}"
destdir="${appl.bin.dir}"
encoding="SJIS"
deprecation="true"
debug="true">
<classpath id="appl.test.path">
<!-- classpthにidを設定: この<project>(jvmプロセス)でidが有効 -->
<pathelement location="${appl.src.dir}" />
<fileset dir="${org.junit.dir}">
<include name="*.jar" />
<exclude name="src.jar" />
</fileset>
</classpath>
</javac>

</target>

<!--
*******************************************************
** JUnit tests
****************************************************
<junit>タスクを実行するには、
antの実行時、CLASSPATHにjunit.jarが存在しなければならないようだ。
set JUNIT_HOME=c:\java\junit3.8.1
set CLASSPATH=%JUNIT_HOME%\junit.jar;%CLASSPATH%
<formatter type="xml"/>のとき、
無条件にencoding="UTF-8"が指定される。
TestCaseのメソッドからSystem.out.println()に漢字を出力すると文字化け。
<formatter type="plain" usefile="false" />ならば表示OK。
-->

<target name="testProps">
<!-- プロパティ設定: 一度設定すると、この<project>(jvmプロセス)で有効 -->
<property name="appl.docs.junit.dir" value="docs/junit"/>
<!-- ディレクトリの存在チェック -->
<available file="${appl.docs.junit.dir}" type="dir"
property="appl.docs.junit.dir.available"/>
</target>

<target name="makeJUnitDocDir" unless="appl.docs.junit.dir.available">
<!-- ディレクトリが存在しないとき(unlesss)、作成する -->
<mkdir dir="${appl.docs.junit.dir}"/>
</target>

<target name="test"
depends="compile,testProps,makeJUnitDocDir">

<echo message="JUnitテストを実行します"/>
<junit printsummary="true"
fork="true">
<!-- <formatter type="plain" usefile="false" /> -->
<formatter type="xml"/>
<test name="AllTests2" />
<classpath>
<fileset dir="${org.junit.dir}">
<include name="*.jar" />
<exclude name="src.jar" />
</fileset>
<pathelement location="${appl.bin.dir}" />
</classpath>
</junit>

<junitreport todir="${appl.docs.junit.dir}">
<fileset dir="${appl.docs.junit.dir}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${appl.docs.junit.dir}" />
</junitreport>

</target>

<!--
*******************************************************
** Classpath properties.
****************************************************-->

<path id="classpath.path">
<pathelement location="${builddir}"/>
<pathelement location="cache/lib/servlet.jar"/>
<fileset dir="cache/lib">
<include name="**/*.jar"/>
<exclude name="ant.jar"/>
</fileset>
</path>

<!--
*******************************************************
** Create the output directory structure.
****************************************************
ここでは${builddir}を必要とする。builddirプロパティはinitで設定される。
<target>の属性depends="init"がないので、
'ant prepare'と入力するとinitは実行されず、builddirプロパティは存在しない。
すると、'${builddir}'という名前のディレクトリを作成する。

-->

<target name="prepareProps">
<!-- パッチ: builddirプロパティを設定する。すでに設定されていれば無視 -->
<property name="builddir" value="build"/>
</target>

<target name="prepare" depends="prepareProps">

<mkdir dir="${builddir}"/>
<mkdir dir="${builddir}/tests"/>
<mkdir dir="${builddir}/WEB-INF/lib"/>
<mkdir dir="${builddir}/WEB-INF/classes/cache"/>

<copy todir="${builddir}/WEB-INF/classes/cache">
<fileset dir="cache/beans"/>
</copy>
<copy todir="${builddir}">
<fileset dir="cache/src"/>
</copy>
<copy todir="${builddir}/WEB-INF/lib">
<fileset dir="cache/lib"/>
</copy>
<copy todir="${builddir}/WEB-INF">
<fileset dir="cache/deployment"/>
</copy>
<copy todir="${builddir}">
<fileset dir="cache/stylesheet"/>
</copy>
<copy todir="${builddir}/tests">
<fileset dir="cache/tests"/>
</copy>
<copy todir="${builddir}/WEB-INF/classes">
<fileset dir="cache/properties"/>
</copy>

</target>

<!--
********************************************************
** Help
*****************************************************
'ant -projecthelp'で表示されるのは、<target>のdescription属性に記述した
テキスト
description属性がなければ表示されない
-->
<target name="help"> <!-- description="Lifecycle Help" -->

<echo message="Lifecycleスクリプトのヘルプ"/>
<echo message="詳細な説明を見るには、'ant -projecthelp'と入力してください"/>

</target>

<!--
********************************************************
** Remove the (build/release) directories
*****************************************************
ここでは${builddir}を必要とする。builddirプロパティはinitで設定される。
<target>の属性depends="init"がないので、
'ant clean'と入力するとinitは実行されず、builddirプロパティは存在しない。
すると、'${builddir}'という名前のディレクトリの削除を試みる。

<target name="clean">
-->

<target name="clean"
if="builddir"
description="ビルドディレクトリを削除する">

<echo message="削除ディレクトリ : ${builddir}"/>
<delete dir="${builddir}"/>

</target>

<!--
********************************************************
** CVS
*****************************************************
cvsを実行するには、

1) cvsプログラムがパス上に存在すること。
XonWindows(Cygwin)をWindowsにインストールしPATHを設定した。
set PATH=%PATH%;C:\PROGRA~1\HOLON\XonWindows\bin
(cvsがパスに見つからない場合は、<cvs>タスクがerror=2で中断する。)

Cygwinの入手(Windows環境のみ)
http://cygwin.com/

2) ~/.cvspassにパスワードが記述されていること。
一度、以下を実行すると~/.cvspassファイルが作成される。
cvs -d :pserver:anoncvs@xxxxxxxxxxxxxx:/home/cvspublic login
password: anoncvs

-->

<target name="cvsProps">
<!-- チェックアウト先のディレクトリ -->
<property name="cygwin.cvs.dir"
value="C:/Documents/java/wiley/pitfalls/item11/cvs"/>
<!-- csvのパスワード -->
<property name="cygwin.cvs.passfile" value="C:/Program
Files/HOLON/XonWindows/home/Administrator/.cvspass"/>
</target>

<target name="cvs"
depends="cvsProps"
description="CVSファイルをチェックアウトする">

<echo message="antのCVSファイルをチェックアウトする..."/>
<cvs cvsRoot=":pserver:anoncvs@xxxxxxxxxxxxxx:/home/cvspublic"
package="ant/src"
dest="${cygwin.cvs.dir}"
passfile="${cygwin.cvs.passfile}"/>

</target>

<!--
********************************************************
** Bugrat - Bug Tracking Tool
*****************************************************
Bugratのインストールを自動化する
Bugratとは、DBとサーブレットを利用したバグ登録/閲覧システムである。

1. Bugratをダウンロードする
http://www.gjt.org/pkg/bugrat/
antの<ftp>タスクで実行できるだろうが試みていない。
2. Bugrat作業ディレクトリの作成
3. Bugratのunzip
4. Bugratデータベースの初期化
5. Bugratサーブレットのデプロイ(手動)
1) Bugratの提供するweb.xmlを修正する
場所: <Bugrat解凍ディレクトリ>/java/org/gjt/bugrat/deploy/web.xml
1.1) xmlエレメントの宣言の順序を、DTDの指定どおりにする。
1.2) <init-param>JDBCの設定: urlパスワードなどを環境に合わせる。
2) bugrat.warを作成する
3) bugrat.warをデプロイする

-->

<target name="bugratProps" depends="init">
<!-- リソース(file)が存在すればプロパティ(haveBugrat)を設定する -->
<available property="haveBugrat" type="dir" file="${destdir}"/>
</target>

<target name="prepareBugrat"
depends="bugratProps"
unless="haveBugrat"
description="Bugrat: 1) ディレクトリを作成する">

<!-- ディレクトリが存在しない場合だけ、ディレクトリを作成する -->
<mkdir dir="${destdir}"/>
<mkdir dir="${destdir.bugrat}"/>
</target>

<target name="installBugrat"
depends="prepareBugrat"
description="Bugrat: 2) Bugratをunzipする">
<unzip src="${zip.bugrat}" dest="${destdir}"/>
</target>

<target name="deployBugrat"
depends="installBugrat"
description="Bugrat: 3) Bugratをインストールする">

<!-- この意味不明 -->
<pathconvert targetos="windows" property="bugrat_home">
<path location="${destdir.bugrat}"/>
</pathconvert>

</target>

<target name="cleanBugrat"
depends="init"
description="Bugrat: 9) Bugratディレクトリを削除する">

<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${destdir}" />

</target>

<!-- For the sake of brevity, I've omitted the SQL scripts that need to
be run
to build the Bugrat repository. These files include: defconfig.sql,
defproperties.sql, examplecats.sql, and mysqlschema.sql -->

<target name="createTables"
depends="mySqlProps"
description="Bugrat: 4) Bugratデータベースを初期化する">

<sql driver="${driver}"
url="${url}"
userid="${userid}"
password="${password}"
classpathref="appl.jdbc.mysql.path"
src="${destdir}/java/org/gjt/bugrat/sql/mysql-schema.sql">
</sql>

<sql driver="${driver}"
url="${url}"
userid="${userid}"
password="${password}"
classpathref="appl.jdbc.mysql.path"
src="${destdir}/java/Bugrat2.5.3/java/org/gjt/bugrat/sql/defconfig.sql">
</sql>

<sql driver="${driver}"
url="${url}"
userid="${userid}"
password="${password}"
classpathref="appl.jdbc.mysql.path"
src="${destdir}/java/Bugrat2.5.3/java/org/gjt/bugrat/sql/defproperties.sql">
</sql>

<sql driver="${driver}"
url="${url}"
userid="${userid}"
password="${password}"
classpathref="appl.jdbc.mysql.path"
src="${destdir}/java/Bugrat2.5.3/java/org/gjt/bugrat/sql/examplecats.sql">
</sql>

</target>

<!--
<target name="dropTables"
depends="mySqlProps"
description="Bugrat: 9) Bugratデータベースを破棄する">

<sql driver="${driver}"
url="${url}"
userid="${userid}"
password="${password}"
classpathref="appl.jdbc.mysql.path"
src="C:/Documents/java/Bugrat2.5.3/java/org/gjt/bugrat/sql/drop.sql">
</sql>

</target>
-->

<!--
********************************************************
** JDepend
*****************************************************
<jdepend>タスクを実行するには、
antの実行時、CLASSPATHにjdepend.jarが存在しなければならないようだ。
set JDEPEND_HOME=C:\java\jdepend-2.6
set CLASSPATH=%JDEPEND_HOME%\lib\jdepend.jar;%CLASSPATH%

JDependはパッケージの依存関係を表示する。
ソースファイルではなくクラスファイルに実行する。(jarはうまくいかなかった)

1. 解析結果:

* CC - 具象クラスの数
* AC - 抽象クラス(インターフェイス)の数
* Ca - 依存結合(Afferent Couplings) (Ca); importしたクラスの数
* Ce - 被依存結合(Efferent Couplings) (Ce); importされた相手側のクラスの数
* A - 抽象度 (0-1) AC/(CC+AC); 0: すべて具象、1: すべて抽象
* I - 不安定性 (0-1) Ce/(Ce+Ca); 0: 全く安定、1: 全く不安定
* D - 直線A+I=1からの距離 (0-1); 0: 直線上、1: 最も乖離
* V - 変更許容度 (0または1); デフォルト1、0: 変更を許容しない、1: 変更を
許容(Dは影響しない)
例: java.langパッケージは変更を許容しない。全く安定しているので依存関係
の分析は無意味。
jdepend.propertiesファイルに以下を記述する
java.lang=0
* Cyclic - パッケージの依存関係が循環しているかどうか

2. プロパティファイル:
jdepend.propertiesというファイルを、ユーザーのホームディレクトリか
CLASSPATH上に置く

1) パッケージフィルター
ignoreプレフィクスを付けたパッケージを無視する

ignore.java=java.*,javax.*
ignore.sun=sun.*,com.sun.*
ignore.tests=com.xyz.tests

2) 変更許容度
Vを設定する(0か1)。1がデフォルトなので0のパッケージだけ指定

java.lang=0

3) インナークラス
デフォルトでインナークラスは分析する

analyzeInnerClasses=false

-->

<target name="jdependProps">
<!-- antのビルド・クラス・ディレクトリ -->
<property name="ant.build.dir"
value="C:/Documents/java/jakarta-ant-1.5.1/build/classes" />
<property name="ant.docs.jdepend.dir" value="docs/jdepend" />
<available file="${ant.docs.jdepend.dir}" type="dir"
property="ant.docs.jdepend.dir.available"/>
</target>

<target name="makeJDependDocDir" unless="ant.docs.jdepend.dir.available">
<mkdir dir="${ant.docs.jdepend.dir}"/>
</target>

<target name="jdepend"
depends="compile,jdependProps,makeJDependDocDir"
description="JDependを実行してパッケージの依存関係を調べる">

<echo message="---- JDepend、xml形式のレポート実行 ----"/>
<jdepend format="xml"
outputfile="${ant.docs.jdepend.dir}/jdepend-report.xml">
<sourcespath>
<pathelement location="${ant.build.dir}"/>
</sourcespath>
</jdepend>
<property environment="env"/>
<style basedir="${ant.docs.jdepend.dir}"
destdir="${ant.docs.jdepend.dir}"
includes="${ant.docs.jdepend.dir}/jdepend-report.xml"
style="${env.ANT_HOME}/etc/jdepend.xsl" />

<echo message="---- JDepend、txt形式のレポート実行 ----"/>
<jdepend outputfile="${ant.docs.jdepend.dir}/jdepend-report.txt">
<sourcespath>
<pathelement location="${ant.build.dir}"/>
</sourcespath>
</jdepend>

</target>

<!--
********************************************************
** JavaNCSS
*****************************************************-->

<target name="javancssProps">
<property name="javancss.lib.dir" value="C:/java/javancss21.41/lib"/>
<property name="java.src.dir" value="C:/java/j2sdk1.4.1_03/src"/>
<property name="appl.docs.javancss.dir" value="./docs/javancss"/>
<available file="${appl.docs.javancss.dir}" type="dir"
property="appl.docs.javancss.dir.available"/>
<antcall target="makeJavaNcssDocDir"/>
</target>

<target name="makeJavaNcssDocDir" unless="appl.docs.javancss.dir.available">
<mkdir dir="${appl.docs.javancss.dir}"/>
</target>

<target name="javancss"
depends="javancssProps">

<taskdef name="javancss"
classname="javancss.JavancssAntTask" >
<classpath>
<fileset dir="${javancss.lib.dir}">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>

<!--
<javancss srcdir="${java.src.dir}"
abortOnFail="false"
ccnPerFuncMax="10"
includes="**/*.java"/>
-->

<javancss srcdir="${java.src.dir}"
generateReport="true"
outputfile="${appl.docs.javancss.dir}/javancss_metrics.xml"
format="xml"/>

</target>

<!--
********************************************************
** Splash screen
*****************************************************
プロキシの設定は<setproxy>タスクで行う。動作は確認していない。
-->
<target name="splash"
description="Display splash screen...">

<echo message="Display splash screen..."/>
<!-- http:// 指定による画像表示 -->

<!-- プロキシの指定は未確認
<setproxy proxyhost="isaserver" proxyport="8080"/>
-->

<splash imageurl="http://developer.java.sun.com/images/v4_java_logo.gif";
showduration="1000" />
<splash imageurl="http://ant.apache.org/images/ant_logo_large.gif";
showduration="1000" />

<!-- プロキシの指定解除は未確認
<setproxy proxyhost=""/>
-->

<!-- 環境変数を表すプロパティ -->
<property environment="env"/>
<!-- file:// 指定(jdk1.4.2)による画像表示
jdk1.3.1では、file:///になる -->
<splash imageurl="file:///${env.ANT_HOME}/docs/images/group-logo.gif"
showduration="1000" />
<splash
imageurl="file:///${env.ANT_HOME}/docs/images/jw_ec_logo_winner2002.gif"
showduration="1000" />
<splash imageurl="file:///${env.ANT_HOME}/docs/images/ant_logo_small.gif"
showduration="1000" />
<splash imageurl="file:///${env.ANT_HOME}/docs/images/ant_logo_medium.gif"
showduration="1000" />

<!-- デフォルトgifの表示 -->
<splash/>

</target>

<!--
********************************************************
** Checkstyle
*****************************************************
Checkstyleのクラス入手
http://checkstyle.sourceforge.net/
antで利用するには
http://checkstyle.sourceforge.net/anttask.html

<checkstyle>の属性allowTabs="yes"はエラーになる

-->
<target name="checkStyleProps">
<path id="net.sourceforge.checkstyle.path">
<fileset dir="c:/java/checkstyle-3.1">
<include name="*.jar"/>
</fileset>
</path>
</target>

<target name="checkStyle"
depends="compile,checkStyleProps"
description="Coding standard met?...">

<taskdef name="checkstyle"
classname="com.puppycrawl.tools.checkstyle.CheckStyleTask"
classpathref="net.sourceforge.checkstyle.path"/>

<echo message="コーディング標準に準拠しているかどうか?..."/>

<checkstyle config="docs/checkstyle/check_config.xml">
<formatter type="plain"/>
<fileset dir="${appl.src.dir}" includes="**/*.java"/>
<classpath refid="appl.test.path"/>
</checkstyle>

</target>


<!--
********************************************************
** Javadoc
*****************************************************
JavaDoc生成
encoding="SJIS"と指定: Solaris(Intel)でEUC_JPのJavaDocが生成されないこと
があった。
複数のソースディレクトリ、パッケージ、クラスパスに対応できるように変更した。
-->
<target name="javadocProps">
<property name="appl.src.dir" value="./src"/>
<property name="appl.docs.javadoc.dir" value="./docs/javadoc"/>
<available file="${appl.docs.javadoc.dir}" type="dir"
property="appl.docs.javadoc.dir.available"/>
</target>

<target name="makeJavaDocDir" unless="appl.docs.javadoc.dir.available">
<mkdir dir="${appl.docs.javadoc.dir}"/>
</target>

<target name="javadoc"
depends="compile,javadocProps,makeJavaDocDir"
description="Generate Javadoc artifacts">

<echo message="Generating Javadoc artifacts..."/>

<javadoc packagenames="*"
encoding="SJIS"
destdir="${appl.docs.javadoc.dir}"
author="true"
version="true"
use="true"
private="true"
windowtitle="Test API">

<sourcepath>
<pathelement path="${appl.src.dir}"/>
<!-- 任意のソースディレクトリを設定する ... -->
</sourcepath>
<packageset dir="${appl.src.dir}" defaultexcludes="yes">
<include name="org/**" />
<!-- 任意のパッケージを設定する ... -->
</packageset>
<classpath>
<path refid="appl.test.path" />
<!-- 任意のパスを設定する ... -->
</classpath>

<doctitle><![CDATA[<h1>Test</h1>]]></doctitle>
<bottom><![CDATA[<i>Copyright &#169; 2002 Java Pitfalls II All Rights
Reserved.</i>]]></bottom>

</javadoc>

</target>

<!--
********************************************************
** Build WAR file
*****************************************************-->
<target name="distribute"
depends="prepare">

<echo message="Compiling source..."/>

<javac srcdir="cache/beans"
destdir="${builddir}/WEB-INF/classes/">
<classpath>
<path refid="classpath.path"/>
</classpath>
</javac>

<echo message="Creating WAR file [cache.war]..."/>

<!--
<war warfile="${builddir}/cache.war" ... >
属性warfile=""はもはや支援されない。destfile=""に変更
-->
<war destfile="${builddir}/cache.war"
webxml="cache/deployment/web.xml">
<fileset dir="${builddir}">
<patternset id="_source">
<include name="*.jsp"/>
</patternset>
<patternset id="_stylesheet">
<include name="*.css"/>
</patternset>
</fileset>
<webinf dir="${builddir}/WEB-INF">
<patternset id="_tld">
<include name="*.tld"/>
</patternset>
</webinf>
<classes dir="${builddir}/WEB-INF/classes" >
<patternset id="_classes">
<include name="**"/>
</patternset>
</classes>
<lib dir="${builddir}/WEB-INF/lib"/>
</war>

</target>

<!--
********************************************************
** SQL - table creation, population and deletion
*****************************************************
MySQLの情報
http://www.mysql.com/
MySQL JDBCドライバーの入手
http://www.mysql.com/downloads/api-jdbc-stable.html

SQL文自体はCDATAセクションに記述するべきだろう。
SQL文はsrc属性でファイルから読み込めば依存性がなくなる。

-->

<target name="mySqlProps">
<property name="driver" value="org.gjt.mm.mysql.Driver" />
<property name="url" value="jdbc:mysql://192.168.0.6/test" />
<property name="userid" value="" />
<property name="password" value="" />
<property name="appl.mysql.dir"
value="C:/java/lib/mysql-connector-java-3.0.8-stable"/>
<path id="appl.jdbc.mysql.path">
<fileset dir="${appl.mysql.dir}">
<include name="*.jar" />
</fileset>
</path>
</target>

<target name="createMySQLCacheTables" depends="mySqlProps">

<sql driver="${driver}"
url="${url}"
userid="${userid}"
password="${password}"
classpathref="appl.jdbc.mysql.path">

<!--
NOTE: Could logon to MySQL thru URL mysql (default database) and create
the States dB instance
or do this manually through this step: create database States;
-->

<![CDATA[
CREATE TABLE GeneralInfo (
State VARCHAR(40) NOT NULL,
Flower VARCHAR(50),
Bird VARCHAR(50),
Capital VARCHAR(40),
PRIMARY KEY(State)
);

CREATE TABLE Topics (
State VARCHAR(40) NOT NULL,
AutomobileDealers VARCHAR(40),
BikeTrails VARCHAR(50),
Gyms VARCHAR(50),
Hospitals VARCHAR(50),
Laundromats VARCHAR(50),
Parks VARCHAR(50),
Physicians VARCHAR(50),
PetStores VARCHAR(50),
Restaurants VARCHAR(50),
RestAreas VARCHAR(50),
Supermarkets VARCHAR(50),
PRIMARY KEY(State)
);
]]>
</sql>

</target>

<target name="dropMySQLCacheTables" depends="mySqlProps">

<sql driver="${driver}"
url="${url}"
userid="${userid}"
password="${password}"
classpathref="appl.jdbc.mysql.path">
<![CDATA[
DROP TABLE GeneralInfo;
DROP TABLE Topics;
]]>
</sql>
</target>

<target name="populateMySQLCacheTables" depends="mySqlProps">

<sql driver="${driver}"
url="${url}"
userid="${userid}"
password="${password}"
classpathref="appl.jdbc.mysql.path">
<![CDATA[

INSERT INTO GeneralInfo VALUES (
'Alabama', 'Camellia', 'Yellowhammer', 'Montgomery'
);

INSERT INTO Topics VALUES (
'Alabama', 'KIA', 'Bama Path', 'Mr. Muscles',
'St. Lukes', 'Mr. Clean', 'Tuscaloosa',
'Dr. Nick', 'Mr. Pickles', 'Joes Pizzaria',
'Selma', 'Mr. Goodshoes'
);

COMMIT;
]]>
</sql>
</target>

<!--
********************************************************
** Cruise control
*****************************************************
CruiseControl Home
http://cruisecontrol.sourceforge.net/

CuruiseControlの役割
1) デーモンプロセスによって定期的にソースを調べ、必要ならビルドを実行する。
2) ビルドログファイルを出力する。ログはJSPで参照することができる

CruiseControlの入手
http://cruisecontrol.sourceforge.net/download.html

1) cvsから入手するには
cvs -z3
-d:pserver:anonymous@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:/cvsroot/cruisecontrol
co cruisecontrol

2) 自動生成用のantを実行する
cd <cvsのチェックアウトディレクトリ>\cruisecontrol\main

JUnitを実行するために環境変数CLASSPATHを設定
set JUNIT_HOME=.\lib
set CLASSPATH=%JUNIT_HOME%\junit.jar;%CLASSPATH%

ant all

途中で失敗する。(VSSが必要?)
[junit] Testcase:
testHandleEntryCheckin(net.sourceforge.cruisecontrol.sourcecontrols.VssJournalTest):
Caused an ERROR

ant jar

dist/curisecontrol.jarが作成される

-->

<target name="all"
depends="clean, compile, javadoc, distribute, test"
description="prepare application for CruiseControl"/>

<target name="cruiseProps">
<property name="catalina.home" value="C:/java/Tomcat 4.1"/>
<property name="net.sourceforge.cruisecontrol.checkout"
value="C:/Documents/java/CruiseControl"/>
<property name="net.sourceforge.cruisecontrol.dir"
value="${net.sourceforge.cruisecontrol.checkout}/cruisecontrol"/>
<property name="buildservlet.war"
value="${net.sourceforge.cruisecontrol.dir}/buildservlet.war"/>
</target>

<target name="cruise"
depends="cruiseProps"
if="catalina.home"
description="Start the automated build process with CruiseControl">

<copy todir="${catalina.home}/webapps/"
file="${buildservlet.war}" />

<java classname="net.sourceforge.cruisecontrol.MasterBuild" fork="yes" >
<arg line="-properties cruisecontrol.properties -lastbuild
20020901010101 -label test 1"/>
<classpath>
<pathelement
location="${net.sourceforge.cruisecontrol.dir}/main/dist/cruisecontrol.jar"/>
<pathelement path="${java.class.path}"/>
<pathelement path="${compile.classpath}"/>
<pathelement location="."/>
</classpath>
</java>

</target>

<target name="checkout"
if="cvs.repository"
description="Update package from CVS">

<cvs cvsroot="${cvs.repository}"
package="${cvs.package}"
dest="." passfile="etc\.passwd" />

</target>

<target name="modificationcheck"
depends="prepare"
description="Check modifications since last build">

<taskdef name="modificationset"
classname="net.sourceforge.cruisecontrol.ModificationSet"/>

<echo message="Checking for modifications..."/>
<modificationset lastbuild="${lastGoodBuildTime}"
quietperiod="30" dateformat="yyyy-MMM-dd HH:mm:ss">
<cvselement cvsroot="${cvs.repository}"
localworkingcopy="." />
</modificationset>

</target>

<target name="masterbuild"
depends="modificationcheck,checkout,all"
description="Cruise Control master build"/>

<target name="cleanbuild"
depends="clean,masterbuild"
description="Cruise Control clean build"/>


<!--
==================================================
追加ターゲット MJPに存在しないが追加した。(井上泰)
================================================== -->
<!--
********************************************************
** プロパティの確認表示
***************************************************** -->

<target name="show"
depends="init"
description="設定値を確認表示する">

<echo message=""/>
<echo message="----- サンプルビルド ${TODAY}(${DSTAMP}), ${TSTAMP} -----"/>
<echo message="----- 環境変数 -----"/>
<property environment="env"/>
<echo message="JAVA_HOME=${env.JAVA_HOME}"/>
<echo message="ANT_HOME=${env.ANT_HOME}"/>
<echo message="ファイル・エンコーディング=${file.encoding}"/>
<echo message=""/>
<echo message="----- プロパティ -----"/>
<echo message="testdir=${testdir}" />
<echo message="rootdir=${rootdir}" />
<echo message="builddir=${builddir}" />
<echo message="driver=${driver}" />
<echo message="url=${url}" />
<echo message="userid=${userid}" />
<echo message="password=${password}" />
<echo message="destdir=${destdir}" />
<echo message="zip.bugrat=${zip.bugrat}" />
<echo message="destdir.bugrat=${destdir.bugrat}" />
<echo message="catalina.home=${catalina.home}" />
<echo message="cvs.repository=${cvs.repository}" />
<echo message="cvs.package=${cvs.package}" />

</target>
<!--
********************************************************
** Jalopy : Javaソースコードを整形する
*****************************************************
Jalopyの入手
http://prdownloads.sourceforge.net/jalopy/jalopy-ant-0.6.1.zip
-->
<target name="beautify"
depends="compile"
description="Javaソースファイルを整形する">

<!-- Jalopyのインストールディレクトリを指定する -->
<property name="net.sourceforge.jalopy.dir"
value="c:/java/japloy0.6.1/lib"/>

<taskdef name="jalopy"
classname="de.hunsicker.jalopy.plugin.ant.AntPlugin">
<classpath id="net.sourceforge.jalopy.path">
<fileset dir="${net.sourceforge.jalopy.dir}">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>

<jalopy fileformat="AUTO"
history="file"
historymethod="adler32"
loglevel="info"
threads="2"
backup="true"
classpathref="appl.test.path">
<fileset dir="${appl.src.dir}">
<include name="**/*.java" />
</fileset>
</jalopy>

</target>

<!--
********************************************************
** AStyle : Javaソースコードを整形する
*****************************************************
AStyleの入手
http://sourceforge.net/projects/astyle
-->
<target name="beautify2"
depends="compile"
description="Javaソースファイルを整形する">

<!-- AStyleの実行プログラムを指定する -->
<property name="astyle,exe" value="C:/java/astyle/astyle.exe"/>

<apply executable="${astyle,exe}"
dir="${appl.src.dir}">
<arg value="--style=java"/>
<fileset dir="${appl.src.dir}" includes="**/*.java"/>
</apply>

</target>

<!--
********************************************************
** native2ascii : native code ==> unicode
*****************************************************
-->
<target name="unicode"
description="sjisソースをunicodeシーケンスに変換する" >
<!-- javadoc encoding="SJIS" はos.name="SunOS,Linux" でうまく機能しない
ため -->

<!-- 基本ディレクトリ -->
<property name="appl.src.dir" value="./src"/>
<property name="appl.src.unicode.dir" value="${appl.src.dir}/unicode"/>

<echo message="----- ネイティブ文字コードをunicodeに変換 -----"/>
<echo message="入力ディレクトリ = ${appl.src.dir}"/>
<echo message="出力ディレクトリ = ${appl.src.unicode.dir}"/>

<delete dir="${appl.src.unicode.dir}"/>
<mkdir dir="${appl.src.unicode.dir}" />

<native2ascii src="${appl.src.dir}"
dest="${appl.src.unicode.dir}"
encoding="SJIS"
includes="**/*.java,**/*.properties" />
<!-- package.htmlなどJavaDocで必要なファイルをコピーする -->
<copy todir="${appl.src.unicode.dir}">
<fileset dir="${appl.src.dir}">
<include name="**/*.html"/>
<include name="**/*.xml"/>
</fileset>
</copy>
</target>

<!--
********************************************************
** native2ascii : unicode ==> native code
*****************************************************
-->
<target name="native"
description="unicodeシーケンスからネイティブ・エンコーディングに変換する" >

<!-- 基本ディレクトリ -->
<property name="appl.src.dir" value="./src"/>
<property name="appl.src.unicode.dir" value="${appl.src.dir}/unicode"/>
<property name="appl.src.native.dir"
value="${appl.src.dir}/${file.encoding}"/>

<echo message="----- unicodeをネイティブ文字コードに変換 -----"/>
<echo message="入力ディレクトリ = ${appl.src.unicode.dir}"/>
<echo message="出力ディレクトリ = ${appl.src.native.dir}"/>
<echo />

<delete dir="${appl.src.native.dir}"/>
<mkdir dir="${appl.src.native.dir}" />

<native2ascii reverse="true"
src="${appl.src.unicode.dir}"
dest="${appl.src.native.dir}"
includes="**/*.java,**/*.properties" />

</target>

<!--
********************************************************
** SQL - table creation, population and deletion
*****************************************************
Oracle SQLの実行

Oracle JDBCドライバーの入手
http://otn.oracle.co.jp/software/tech/java/jdbc/

SQL文自体はCDATAセクションに記述するべきだろう。
SQL文はsrc属性でファイルから読み込めば依存性がなくなる。

-->

<target name="oracleProps">
<property name="appl.jdbc.url.oracle"
value="jdbc:oracle:thin:@192.168.0.4:1521:bach"/>
<property name="appl.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="appl.jdbc.user" value="scott"/>
<property name="appl.jdbc.password" value="tiger"/>
<property environment="env"/>
<path id="appl.jdbc.oracle.path">
<fileset dir="${env.ORACLE_HOME}">
<include name="jdbc/lib/*12.jar" />
</fileset>
</path>
</target>

<target name="createOracleCacheTables"
depends="oracleProps">

<sql driver="${appl.jdbc.driver}"
url="${appl.jdbc.url.oracle}"
userid="${appl.jdbc.user}"
password="${appl.jdbc.password}"
classpathref="appl.jdbc.oracle.path">
<![CDATA[
CREATE TABLE GeneralInfo (
State_Code CHAR(2) NOT NULL,
State VARCHAR2(40) NOT NULL,
Flower VARCHAR2(50),
Bird VARCHAR2(50),
Capital VARCHAR2(40)
);

ALTER TABLE GeneralInfo ADD CONSTRAINT GeneralInfo_pkey PRIMARY KEY
(State_Code);

CREATE TABLE Topics (
State_Code CHAR(2) NOT NULL,
State VARCHAR2(40) NOT NULL,
AutomobileDealers VARCHAR2(40),
BikeTrails VARCHAR2(50),
Gyms VARCHAR2(50),
Hospitals VARCHAR2(50),
Laundromats VARCHAR2(50),
Parks VARCHAR2(50),
Physicians VARCHAR2(50),
PetStores VARCHAR2(50),
Restaurants VARCHAR2(50),
RestAreas VARCHAR2(50),
Supermarkets VARCHAR2(50)
);

ALTER TABLE Topics ADD CONSTRAINT Topics_pkey PRIMARY KEY (State_Code);

]]>
</sql>

</target>

<target name="dropOracleCacheTables"
depends="oracleProps">

<sql driver="${appl.jdbc.driver}"
url="${appl.jdbc.url.oracle}"
userid="${appl.jdbc.user}"
password="${appl.jdbc.password}"
classpathref="appl.jdbc.oracle.path">
<![CDATA[
DROP TABLE GeneralInfo;
DROP TABLE Topics;
]]>
</sql>
</target>

<target name="populateOracleCacheTables"
depends="oracleProps">

<sql driver="${appl.jdbc.driver}"
url="${appl.jdbc.url.oracle}"
userid="${appl.jdbc.user}"
password="${appl.jdbc.password}"
classpathref="appl.jdbc.oracle.path">
<![CDATA[

INSERT INTO GeneralInfo VALUES (
'AL', 'Alabama', 'Camellia',
'Yellowhammer', 'Montgomery'
);

INSERT INTO Topics VALUES (
'AL', 'Alabama', 'KIA', 'Bama Path',
'Mr. Muscles', 'St. Lukes', 'Mr. Clean',
'Tuscaloosa', 'Dr. Nick', 'Mr. Pickles',
'Joes Pizzaria', 'Selma', 'Mr. Goodshoes'
);

COMMIT;
]]>
</sql>

</target>

</project>