<?xml version="1.0" encoding="UTF-8"?>
<project name="fuzhuang1" basedir=".">
	<!-- 变量设置-->
	<property file="build.properties" />
	<property name="debug" value="true" />
	<property name="project.name" value="${project.name}" />
	<property name="project.version" value="${project.version}" />
	<property name="web" value="WebRoot" />
	<property name="lib.dir" value="${lib.dir}" />
	<property name="src.dir" value="src" />
	<property name="classes" value="${web}/WEB-INF/classes" />
	<property name="release.dir" value="dist" />
	<property name="ear.exploded.dir" location="${release.dir}/${project.name}" />
	<property name="context.tomcat.dir" location="${tomcat.dir}/webapps" />
	<property name="deploy.exploded.dir" location="${release.dir}/${project.name}" />
	<property name="context.weblogic.dir" location="${weblogic.dir}/autodeploy" />

	<!-- project.class.path-->
	<path id="project.class.path">
		<fileset dir="${lib.dir}">
			<include name="**/*.jar" />
		</fileset>
	</path>

	<target name="clean">
		<!--clean-->
		<delete file="${release.dir}/${project.name}.war" />
		<delete dir="${release.dir}/weblogic" />
		<delete dir="${tomcat.dir}/webapps/${project.name}" />
		<delete dir="${tomcat.dir}/work/Catalina/" />
	</target>
	<target name="init">
		<!--clean-->
		<delete dir="${classes}" />
	</target>

	<target name="compile">
		<mkdir dir="${classes}" />
		<mkdir dir="${release.dir}" />

		<!--compile-->
		<javac encoding="utf-8" deprecation="on" debug="${debug}" srcdir="${src.dir}" destdir="${classes}" target="1.8">
			<classpath refid="project.class.path" />
		</javac>
	</target>

	<target name="exploded-ear" depends="compile">
		<!--<copy todir="${ear.exploded.dir}/META-INF">
			<fileset dir="config/app" />
		</copy>-->
		<!--init-->
		<tstamp />

		<copy todir="${classes}">
			<fileset dir="${src.dir}">
				<include name="**/*.xml" />
				<include name="**/*.properties" />
			</fileset>
		</copy>

		<!--exploded-ear-->
		<mkdir dir="${ear.exploded.dir}/${project.name}.war" />
		<copy todir="${ear.exploded.dir}/${project.name}.war">
			<fileset dir="${web}" />
		</copy>

		<copy todir="${ear.exploded.dir}/${project.name}.war/WEB-INF/lib">
			<fileset dir="${lib.dir}" >
				<exclude name="${project.name}-dto-${project.version}.jar" />
			</fileset>
		</copy>

	</target>
	
	<target name="deploy_uat" depends="init,compile,exploded-ear">
		<property name="host" value="${ssh.remote.host.uat}" />
		<property name="user" value="${ssh.remote.username.uat}" />
		<property name="pass" value="${ssh.remote.password.uat}" />
		<property name="app.dir" value="${ssh.remote.app.dir.uat}" />

		<!-- 配置文件调整 -->
		<copy todir="${ear.exploded.dir}/${project.name}.war/WEB-INF/classes" overwrite="true">
			<fileset dir="config/${project.config.uat}" />
		</copy>
		<!--前端授权文件调整-->
		<copy todir="${ear.exploded.dir}/${project.name}.war/static/public/js" overwrite="true">
			<fileset dir="config/${project.config.uat}/jsp" />
		</copy>
		<!--build-ear-->
		<delete file="${release.dir}/${project.name}.war" />
		<jar jarfile="${release.dir}/${project.name}.war" basedir="${ear.exploded.dir}/${project.name}.war">
			<manifest>
				<attribute name="Built-By" value="${user.name}" />
				<attribute name="Specification-Version" value="${project.version}" />
				<attribute name="CreateTime" value="${DSTAMP} ${TSTAMP}" />
			</manifest>
		</jar>

		<delete dir="${release.dir}/${project.name}.war" />

		<!--_deploy-->
		<tstamp />
		<echo message="上传打包文件...开始" />
		<scp file="${release.dir}/${project.name}.war" todir="${user}:${pass}@${host}:${app.dir}" trust="true" />
		<echo message="上传打包文件...结束" />

	</target>

	<target name="deploy-to-local" depends="exploded-ear">
		<!-- 配置文件调整
		<copy todir="${ear.exploded.dir}/${project.name}.war" overwrite="true">
			<fileset dir="src/config/${project.config.dev}" />
		</copy> -->
		
		<copy todir="${context.tomcat.dir}/${project.name}">
			<fileset dir="${deploy.exploded.dir}/${project.name}.war" />
		</copy>
	</target>
	<target name="deploy-to-tomcat" depends="exploded-ear">
		<mkdir dir="${context.tomcat.dir}/${project.name}" />
		<copy todir="${context.tomcat.dir}/${project.name}">
			<fileset dir="${ear.exploded.dir}" />
		</copy>
	</target>
	
</project>
