<?xml version="1.0" encoding="UTF-8"?>
<!--
###############################################################################
#
# Copyright (c) 2005- Shinji Kashihara. All rights reserved.
# This program and the accompanying materials except for /lib directory are
# made available under the terms of the Eclipse Public License v1.0 which
# accompanies this distribution, and is available at /epl-v10.html.
#
###############################################################################
#
# Pleiades Ant ビルド・ファイル
#
###############################################################################
-->
<project default="build">

	<!-- Pleiades バージョン -->
	<property name="version" value="1.3.2"/>

	<!-- コピー先ディレクトリー -->
	<property name="dist.dir" location="../../dist/e3.6"/>
	<property name="this.eclipse.dir" location="../../Tools/Eclipse3.6.0/dropins/MergeDoc/eclipse"/>

	<!-- プロダクト定数定義 -->
	<property name="project.name" value="pleiades"/>
	<property name="project.id" value="jp.sourceforge.mergedoc.${project.name}"/>
	<property name="agent.jar.name" value="${project.name}.jar"/>

	<!-- ディレクトリー・ファイル定義 -->
	<property name="bin.dir" value="bin"/>
	<property name="build.dir" value="build"/>
	<property name="pleiades.zip.file" location="${build.dir}/${project.name}.zip"/>
	<property name="pleiades.src.zip.file" location="${build.dir}/${project.name}-src.zip"/>
	<property name="test.eclipse.plugin.dir" location="${test.eclipse.dir}/plugins"/>

	<!-- プロジェクト・クラスパス -->
	<path id="project.classpath">
		<pathelement location="bin"/>
		<pathelement location="bintest"/>
		<pathelement location="srctest"/>
		<pathelement location="conf"/>
		<pathelement location="lib/javassist/javassist.jar"/>
		<pathelement location="lib/apache/commons-io.jar"/>
		<pathelement location="lib/apache/commons-lang.jar"/>
		<pathelement location="${eclipse.home}/plugins/org.junit_3.8.2.v20090203-1005/junit.jar"/>			<!-- Eclipse3.5 -->
		<pathelement location="${eclipse.home}/plugins/org.junit_3.8.2.v3_8_2_v20100427-1100/junit.jar"/>	<!-- Eclipse3.6 -->
	</path>

	<!-- 翻訳プロパティーの生成（各プロパティーのマージ） -->
	<target name="generate" description="">
		<java
			classname="jp.sourceforge.mergedoc.pleiades.generator.Generator"
			failonerror="true"
			fork="yes"
			maxmemory="256m">
			<classpath refid="project.classpath"/>
		</java>
	</target>

	<!-- 翻訳プロパティーの生成（各プロパティーのマージ）既存訳を再最適化 -->
	<target name="generate-clean" description="">
		<java
			classname="jp.sourceforge.mergedoc.pleiades.generator.Generator"
			failonerror="true"
			fork="yes"
			maxmemory="256m">
			<classpath refid="project.classpath"/>
			<arg value="-clean"/>
		</java>
	</target>

	<!-- ヘルプ翻訳プロパティーの生成、翻訳プロパティーの生成 -->
	<!-- 再生成はもうしない。FIX する。
	<target name="generate-clean-help" description="">
		<java
			classname="jp.sourceforge.mergedoc.pleiades.generator.nls.HelpExtractor"
			failonerror="true"
			fork="yes"
			maxmemory="256m">
			<classpath refid="project.classpath"/>
		</java>
		<antcall target="generate-clean"/>
	</target>
	-->

	<!-- ビルド (SVN 管理) -->
	<target name="build" depends="" description="">

		<!-- Agent jar ファイル作成 -->
		<jar destfile="${agent.jar.name}">
			<fileset dir="${bin.dir}">
				<include name="**/${project.name}/**/*.class"/>
			</fileset>
			<manifest>
				<attribute name="Premain-Class"
					value="${project.id}.Pleiades"/>
				<attribute name="Boot-Class-Path"
					value="./${agent.jar.name} ./conf ./lib/javassist/javassist.jar ./lib/apache/commons-io.jar ./lib/apache/commons-lang.jar"/>
			</manifest>
		</jar>

		<!-- Agent jar を含んだリリース用作業フォルダー作成 -->
		<copy tofile="META-INF/MANIFEST.MF" file="META-INF/MANIFEST.MF.template" overwrite="true"/>
		<copy todir="plugins/${project.id}">
			<fileset dir="${basedir}">
				<exclude name="debian/"/>
				<exclude name=".settings/*"/>
				<exclude name="about/"/>
				<exclude name="bin/"/>
				<exclude name="bintest/"/>
				<exclude name="nls/"/>
				<exclude name="report/"/>
				<exclude name="conf/props/additions/"/>
				<exclude name="conf/props/history/"/>
				<exclude name="conf/props/temp/"/>
				<exclude name="conf/props/no-*.properties"/>
				<exclude name="conf/props/nls-*.properties"/>
				<exclude name="conf/props/temp-*.properties"/>
				<exclude name="conf/props/validation-help-*.properties"/>
				<exclude name="conf/props/.*"/>
				<exclude name="conf/splash*.png"/>
				<exclude name="lib/**/*-src.zip"/>
				<exclude name="META-INF/MANIFEST.MF.template"/>
				<exclude name="src/"/>
				<exclude name="srctest/"/>
				<exclude name="readme/"/>
				<exclude name="build/"/>
				<exclude name=".*"/>
				<exclude name="build.xml"/>
				<exclude name="eclipse.*"/>
				<exclude name="pleiades_*.zip"/>
			</fileset>
		</copy>
		<copy todir="plugins/${project.id}">
			<fileset dir="${basedir}/about/plugins">
				<include name="**/*"/>
			</fileset>
		</copy>
		<copy todir="features/${project.id}">
			<fileset dir="${basedir}/about/features">
				<include name="**/*"/>
			</fileset>
		</copy>

		<!-- Agent jar ファイルの削除 -->
		<delete file="${agent.jar.name}"/>

		<!-- バージョンを設定 -->
		<replace file="plugins/${project.id}/META-INF/MANIFEST.MF"
			token="@version" value="${version}"/>
		<replace file="plugins/${project.id}/about.properties"
			token="@version" value="${version}"/>
		<replace file="plugins/${project.id}/plugin.xml"
			token="@version" value="${version}"/>
		<replace file="features/${project.id}/feature.xml"
			token="@version" value="${version}"/>

		<!-- 署名 -->
		<jar destfile="plugins/${project.id}.jar" basedir="./plugins/${project.id}"/>
		<jar destfile="features/${project.id}.jar" basedir="./features/${project.id}"/>
		<signjar keystore=".keystore" alias="MergeDoc" storepass="mergedoc">
			<fileset dir=".">
				<include name="*/${project.id}.jar"/>
			</fileset>
		</signjar>
		<unjar src="plugins/${project.id}.jar" dest="./plugins/${project.id}">
			<patternset>
				<include name="META-INF/*"/>
			</patternset>
		</unjar>
		<unjar src="features/${project.id}.jar" dest="./features/${project.id}">
			<patternset>
				<include name="META-INF/*"/>
			</patternset>
		</unjar>

		<!-- Pleiades zip ファイルの作成 -->
		<mkdir dir="${build.dir}"/>
		<delete file="${pleiades.zip.file}"/>
		<zip destfile="${pleiades.zip.file}">
			<fileset dir="${basedir}">
				<include name="plugins/${project.id}/**"/>
				<include name="features/${project.id}/**"/>
				<include name="eclipse.*"/>
				<include name="readme/*"/>
			</fileset>
		</zip>
		<delete dir="plugins"/>
		<delete dir="features"/>

		<!-- Pleiades zip ソース・ファイルの作成 -->
		<delete file="${pleiades.src.zip.file}"/>
		<zip destfile="${pleiades.src.zip.file}">
			<fileset dir="${basedir}">
				<!-- コマンド・ラインからビルド可能とするため class を含めておく
				<exclude name="bin/**/*"/>
				-->
				<exclude name="bintest/**/*"/>
				<exclude name="conf/props/history/"/>
				<exclude name="conf/props/temp/"/>
				<exclude name="conf/props/.*"/>
				<exclude name="nls/"/>
				<exclude name="report/"/>
				<exclude name="build/"/>
				<!-- コマンドでエラーになるため追加 -->
				<exclude name="features/"/>
				<exclude name="plugins/"/>
			</fileset>
		</zip>

	</target>

	<!-- クリーン (コマンドライン用) -->
	<target name="clean" depends="" description="">

		<delete dir="${bin.dir}" />
		<mkdir dir="${bin.dir}" />

		<delete dir="${build.dir}" />
		<mkdir dir="${build.dir}" />

	</target>

	<!-- ビルド (コマンドライン用) -->
	<target name="javac" depends="" description="">

		<mkdir dir="${bin.dir}" />
		<javac
			srcdir="src"
			destdir="${bin.dir}"
			classpathref="project.classpath"
			encoding="UTF-8"
			source="1.5"
			target="1.5"
			debug="on" />

	</target>

	<!-- ビルド (コマンドライン用) -->
	<target name="build.full" depends="clean, javac, build" description="">
	</target>

	<!-- リリース・ビルド (手動アップロードしてリリース一覧で管理) -->
	<target name="build.release" depends="test.unit, build" description="">

		<copy tofile="../pleiades_${version}.zip"		file="${pleiades.zip.file}"		overwrite="true" />
		<copy tofile="../pleiades_${version}-src.zip"	file="${pleiades.src.zip.file}"	overwrite="true" />

	</target>

	<!-- ビルド - この Eclipse に zip ファイルをコピー -->
	<target name="build.this.eclipse" depends="build, test.unit" description="">

		<copy todir="${this.eclipse.dir}"		file="${pleiades.zip.file}"		overwrite="true"/>

	</target>

	<!-- ユニット・テスト -->
	<target name="test.unit" description="">

		<mkdir dir="report"/>

		<junit printsummary="yes" haltonfailure="yes" fork="yes" maxmemory="256m" showoutput="no">
			<formatter type="xml" />
			<classpath refid="project.classpath"/>
			<batchtest fork="yes" todir="report">
				<fileset dir="srctest">
					<include name="**/*Test.java" />
					<exclude name="**/TestAll.java" />
				</fileset>
			</batchtest>
		</junit>

		<!-- Eclipse 3.6 から NPE 発生、とりあえずコメントアウト
		<junitreport todir="report">
			<fileset dir="report">
				<include name="TEST-*.xml" />
			</fileset>
			<report format="frames" todir="report" />
		</junitreport>
		-->

	</target>

	<!-- Eclipse 実行テスト (全バージョン) -->
	<target name="test.all.version" description=""
		depends="
			build.this.eclipse,
			test.3.1.2,
			test.3.2.2,
			test.3.3.2,
			test.3.4.2,
			test.3.5.2
		">
	</target>

	<!-- Eclipse 実行テスト -->
	<target name="test.ultimate" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse.dropins">
			<param name="test.eclipse.dir" value="${dist.dir}/ultimate/eclipse"/>
			<param name="test.eclipse.exe" value="eclipse.exe"/>
		</antcall>
	</target>
	<target name="test.platform" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse.dropins">
			<param name="test.eclipse.dir" value="${dist.dir}/platform/eclipse"/>
			<param name="test.eclipse.exe" value="eclipse.exe"/>
		</antcall>
	</target>
	<target name="test.java" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse.dropins">
			<param name="test.eclipse.dir" value="${dist.dir}/java/eclipse"/>
			<param name="test.eclipse.exe" value="eclipse.exe"/>
		</antcall>
	</target>
	<target name="test.cpp" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse.dropins">
			<param name="test.eclipse.dir" value="${dist.dir}/cpp/eclipse"/>
			<param name="test.eclipse.exe" value="eclipse.exe"/>
		</antcall>
	</target>
	<target name="test.php" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse.dropins">
			<param name="test.eclipse.dir" value="${dist.dir}/php/eclipse"/>
			<param name="test.eclipse.exe" value="eclipse.exe"/>
		</antcall>
	</target>
	<target name="test.ruby" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse.dropins">
			<param name="test.eclipse.dir" value="${dist.dir}/ruby/eclipse"/>
			<param name="test.eclipse.exe" value="eclipse.exe"/>
		</antcall>
	</target>
	<target name="test.python" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse.dropins">
			<param name="test.eclipse.dir" value="${dist.dir}/python/eclipse"/>
			<param name="test.eclipse.exe" value="eclipse.exe"/>
		</antcall>
	</target>
	<target name="test.3.1.2" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse">
			<param name="test.eclipse.dir" value="../../Tools/Eclipse3.1.2Test"/>
			<param name="test.eclipse.exe" value="eclipse.exe"/>
		</antcall>
	</target>
	<target name="test.3.2.1" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse">
			<param name="test.eclipse.dir" value="../../Tools/Eclipse3.2.1Test"/>
			<param name="test.eclipse.exe" value="eclipse.exe"/>
		</antcall>
	</target>
	<target name="test.3.2.2" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse">
			<param name="test.eclipse.dir" value="../../Tools/Eclipse3.2.2Test"/>
			<param name="test.eclipse.exe" value="eclipse.exe"/>
		</antcall>
	</target>
	<target name="test.3.3.2" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse">
			<param name="test.eclipse.dir" value="../../Tools/Eclipse3.3.2Test"/>
			<param name="test.eclipse.exe" value="eclipse.exe"/>
		</antcall>
	</target>
	<target name="test.3.4.2" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse.dropins">
			<param name="test.eclipse.dir" value="../../Tools/Eclipse3.4.2Test"/>
			<param name="test.eclipse.exe" value="eclipse.exe"/>
		</antcall>
	</target>
	<target name="test.3.5.2" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse.dropins">
			<param name="test.eclipse.dir" value="../../Tools/Eclipse3.5.2Test"/>
			<param name="test.eclipse.exe" value="eclipse.exe"/>
		</antcall>
	</target>
	<target name="test.3.6.0" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse.dropins">
			<param name="test.eclipse.dir" value="../../Tools/Eclipse3.6.0Test"/>
			<param name="test.eclipse.exe" value="eclipse.exe"/>
		</antcall>
	</target>
	<target name="test.3.6.1" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse.dropins">
			<param name="test.eclipse.dir" value="../../Tools/Eclipse3.6.1Test"/>
			<param name="test.eclipse.exe" value="eclipse.exe"/>
		</antcall>
	</target>
	<target name="test.Aptana" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse">
			<param name="test.eclipse.dir" value="../../Tools/aptana"/>
			<param name="test.eclipse.exe" value="AptanaStudio.exe"/>
		</antcall>
	</target>
	<target name="test.FlexBuilder" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse">
			<param name="test.eclipse.dir" value="../../Tools/FlexBuilder3"/>
			<param name="test.eclipse.exe" value="FlexBuilder.exe"/>
		</antcall>
	</target>
	<target name="test.ApacheDirectoryStudio" description="" depends="build.this.eclipse">
		<antcall target="test.eclipse">
			<param name="test.eclipse.dir" value="../../Tools/Apache Directory Studio"/>
			<param name="test.eclipse.exe" value="Apache Directory Studio.exe"/>
		</antcall>
	</target>

	<!-- ビルドして Eclipse 実行（テスト環境を一旦削除してからコピー） -->
	<target name="test.eclipse">

		<delete includeemptydirs="true">
			<fileset dir="${test.eclipse.dir}">
				<include name="plugins/${project.id}/"/>
				<include name="features/${project.id}/"/>
				<include name="configuration/${project.id}/"/>
			</fileset>
		</delete>
		<unzip src="${pleiades.zip.file}" dest="${test.eclipse.dir}"/>

		<exec executable="${test.eclipse.dir}/${test.eclipse.exe}" dir="${test.eclipse.dir}" spawn="true">
			<arg value="-clean"/>
		</exec>

	</target>

	<!-- ビルドして Eclipse 実行（テスト環境を一旦削除してからコピー） -->
	<target name="test.eclipse.dropins">

		<delete includeemptydirs="true">
			<fileset dir="${test.eclipse.dir}/dropins">
				<include name="MergeDoc/eclipse/plugins/${project.id}/"/>
				<include name="MergeDoc/eclipse/features/${project.id}/"/>
			</fileset>
			<fileset dir="${test.eclipse.dir}">
				<include name="configuration/${project.id}/"/>
			</fileset>
		</delete>
		<unzip src="${pleiades.zip.file}" dest="${test.eclipse.dir}/dropins/MergeDoc/eclipse">
			<patternset>
				<exclude name="readme/" />
				<exclude name="*.cmd" />
			</patternset>
		</unzip>
		<copy todir="${test.eclipse.dir}/readme">
			<fileset dir="${basedir}/readme">
				<include name="**/*"/>
			</fileset>
		</copy>

		<exec executable="${test.eclipse.dir}/${test.eclipse.exe}" dir="${test.eclipse.dir}" spawn="true">
			<arg value="-clean"/>
		</exec>

	</target>

	<!--
	nls フォルダーのバックアップ時の長すぎるパスを回避するために不要な
	ファイルとディレクトリーを削除

		必要なファイルは下記のみ
			*.jar
			*.properties
			MANIFEST.MF
			fragment.xml
	-->
	<target name="clean.nls.dir" description="">
		<delete includeemptydirs="true">
			<fileset dir="${basedir}/nls">
				<exclude name="**/*.jar"/>
				<exclude name="**/*.properties"/>
				<exclude name="**/MANIFEST.MF"/>
				<exclude name="**/fragment.xml"/>
			</fileset>
		</delete>
	</target>

</project>
