中转场ant打包脚本

@echo off
echo ************************************************************  
echo *                                                          *  
echo *                   临时JDK 系统环境变量设置               *  
echo *                                                          *  
echo ************************************************************
set JAVA_HOME=D:\Program Files\Java\jdk1.6.0_26
echo %JAVA_HOME%
cmd /k ant -f build_int_dis.xml


<project name="sf" default="all" basedir="../../">

	<description>SF-Express Framework</description>
	
	<target name="clean" >
		<delete dir="build/dist" failonerror="true" />
		<mkdir dir="build/dist" />
	</target>
	<taskdef resource="net/sf/antcontrib/antlib.xml"/>
	<target name="all" depends="clean">
		
		<!-- 解压老版本的源代码 -->
		<if>
			<available file="build/lib/dist/code.zip"/>
			<then>
		<unzip src="build/lib/dist/code.zip"
       dest="build/dist/code/old" >
       <patternset>
       	<exclude name="**/.svn/**"/>
    		</patternset>
    </unzip>
    </then>
    </if>
		<property name="project.version" value="9.9sonar" />
		<property name="release.type" value="UAT" /> <!--发布类型可以为dev(开发),sit(集成),uat(用户测试),product(上线),rongz(容灾) -->
		<property name="release.date" value="2016-02-24" /> <!--发布日期 -->
		
		 <!-- 构建分中心内部接口包 jar-->
		<ant antfile="build/scripts/subtasks/server-build-int-dis.xml" target="dist">			
			<property name="release.type" value="${release.type}" />
			<property name="app.name" value="int_dis" />
			<property name="pkg.name" value="sss-new-int_dis" />
			<property name="version" value="${project.version}" />
			<property name="release.date" value="${release.date}" />
			<property name="version.accepted" value="${exp.version.accepted}" />			
			<property name="modules" value="" />
			<property name="interfaces" value="inidentrs,loginmgmt,common,outidentrs,rms,launch,waybilladdr,dtx5users,waybilldes,uploadsortfaillog,telhisDist,pkginfo,sortlog,bagdestcitycode,barcheckConfig,uploadimagelog,cityweightcfg,billhasrchd,uploadttidentrsfullup,cartask,uploadbarlogininfo" />
		</ant>	
		
	 </target>

</project>


<project name="server" default="dist" basedir="../../../">

	<!-- 构建属性定义 -->
	<property environment="env" />
	
	<property name="vendor" value="http://www.sf-express.com" />
	
	<!--构建临时目录相关属性定义 -->
	<property name="tmp" location="build/tmp" />
	<property name="src" location="${tmp}/src" />

	<property name="classes" location="${tmp}/classes" />
	
	<!--构建依赖源相关属性定义 -->
	<property name="dist" location="build/dist" />
	<property name="dependon" location="build/lib" />
	<property name="module_code" location="module" />
	<property name="interface_code" location="interface/${app.name}" />
	<!--
	<property name="project_code" location="project/${app.name}/web" />
	-->
	
	<path id="project.class.path">

		<pathelement path="${env.classpath}" />
		<!--<fileset dir="${dependon}/framework/server" includes="*.jar" />-->
		<fileset dir="${dependon}/develop" includes="*.jar" />
		<fileset dir="${dependon}/share" includes="*.jar" />
		<fileset dir="${dependon}/int_i" includes="*.jar" />

	</path>
	
	<!-- 过滤器替换TOKEN定义 -->
	<filter token="version.accepted" value="${version.accepted}"/>
	<filter token="version.number" value="${version}"/>
	<filter token="release.date" value="${release.date}"/>


  <taskdef resource="net/sf/antcontrib/antlib.xml"/>
  
	<!-- 初始化应用临时目录 -->
	<target name="init">
		<delete dir="${tmp}" failonerror="false" />
		<!-- 初始化web临时目录-->

		<!--拷贝替换对应发布类型的配置文件,并进行过滤 -->

		
		<!--初始源代码临时目录与相关模块包库文件-->
		<mkdir dir="${src}" />
		<for param="module" list="${modules}">
		<sequential>
			<condition property="module.@{module}" value="true" else="false">
	    	<and>
	      	<available file="${module_code}/@{module}/server/main" type="dir" />
	    	</and>
		  </condition>
			 <if>
			 		<equals arg1="${module.@{module}}" arg2="true" />
			 		<then>
			 			<copy todir="${src}" includeemptydirs="false">
						<fileset dir="${module_code}/@{module}/server/main" excludes="**/.svn/**" />
						</copy>
						<!--拷贝替换对应发布类型的配置文件 -->
						<condition property="meta.@{module}" value="true" else="false">
							<and>
							<available file="${src}/com/sf/module/@{module}/META-INF/" type="dir" />
							</and>
						</condition>
							 <if>
									<equals arg1="${meta.@{module}}" arg2="true" />
									<then>

										<move todir="${src}/com/sf/module/@{module}/META-INF/" includeemptydirs="false">
										<fileset dir="${src}/com/sf/module/@{module}/META-INF/">
										  <include name="**/*.${release.type}"/>
										</fileset>
										<mapper type="regexp" from="^(.*)\.${release.type}" to="\1"/>
										</move>


									</then>
									</if>

						
			 		</then>
			 		<else>
			 			
			 		</else>
			 </if>
		</sequential>
		</for>
		<for param="interface" list="${interfaces}">
		<sequential>
			<condition property="interface.tw.@{interface}">
  			<matches pattern=".*-tw$" string="@{interface}"/>
			</condition>

			<if>
				<equals arg1="${interface.tw.@{interface}}" arg2="true" />
				<!--台湾接口版本处理 -->
				<then>
				<!-- 获取接口名 -->
					<loadresource property="interface.name.@{interface}">
  						<string value="@{interface}" />
  						<filterchain>
	  						<tokenfilter>
	    						<replaceregex pattern="-tw$" />
								</tokenfilter>
							</filterchain>
					</loadresource>
					<!--接口源代码查找-->
					<condition property="interface.@{interface}" value="true" else="false">
	    		<and>
	      	<available file="${interface_code}/${interface.name.@{interface}}/main" type="dir" />
	    		</and>
		  		</condition>
		  		
				 	<if>
				 		<equals arg1="${interface.@{interface}}" arg2="true" />
				 		<!--有接口源代码 -->
				 		<then>
				 			<copy todir="${src}" includeemptydirs="false">
							<fileset dir="${interface_code}/${interface.name.@{interface}}/main" excludes="**/.svn/**" />
							</copy>
							<move todir="${src}/com/sf/integration/${interface.name.@{interface}}/META-INF/config" includeemptydirs="false">
						    <fileset dir="${src}/com/sf/integration/${interface.name.@{interface}}/META-INF/config">
						      <include name="**/*-tw.*"/>
						    </fileset>
						    <mapper type="regexp" from="^(.*)-tw\.(.*)" to="\1.\2"/>
						  </move>
				 		</then>
				 		<!--无接口源代码-->
				 		<else>

				 		</else>
				 </if>	
				 
				</then>
				<!--非台湾接口版本处理 -->
				<else>
					<!--接口源代码查找-->
					<condition property="interface.@{interface}" value="true" else="false">
	    		<and>
	      	<available file="${interface_code}/@{interface}/main" type="dir" />
	    		</and>
		  		</condition>
		  		
				 	<if>
				 		<equals arg1="${interface.@{interface}}" arg2="true" />
				 		<!--有接口源代码 -->
				 		<then>
				 			<copy todir="${src}" includeemptydirs="false">
							<fileset dir="${interface_code}/@{interface}/main">
								<exclude name="**/.svn/**" />
								<exclude name="**/*-tw.xml" />
							</fileset>
							</copy>
							<move todir="${src}/com/sf/integration/@{interface}/META-INF/config" includeemptydirs="false">
					    	<fileset dir="${src}/com/sf/integration/@{interface}/META-INF/config">
					      	<include name="**/*.${release.type}"/>
					    	</fileset>
					    	<mapper type="regexp" from="^(.*)\.${release.type}" to="\1"/>
							</move>
				 		</then>
				 		<!--无接口源代码-->
				 		<else>

				 		</else>
				 </if>	
				</else>
			</if>
			
		</sequential>
		</for>
	</target>
	
	<!-- 编译模块与接口的源代码 -->
	<target name="compile" depends="init">
		<mkdir dir="${classes}" />
		<javac srcdir="${src}" destdir="${classes}" classpathref="project.class.path" source="1.6" target="1.6" encoding="UTF-8" debug="true" fork="true" />
		<copy todir="${classes}" includeemptydirs="false">
			<fileset dir="${src}">
				<!--exclude name="**/*.java" /-->
				<exclude name="com/sf/module/**/META-INF/i18n/**" />
			</fileset>
		</copy>
		<native2ascii src="${src}" dest="${classes}">
			<include name="com/sf/module/**/META-INF/i18n/*.properties" />
		</native2ascii>
	</target>

	<!-- 打包模块与接口 -->
	<target name="dist" depends="compile">

			 			<jar destfile="${dist}/${pkg.name}-${version}.jar" basedir="${classes}" encoding="UTF-8">
			 				
			 			</jar>

		<for param="interface" list="${interfaces}">
		<sequential>
			
			<condition property="interface.tw.@{interface}">
  			<matches pattern=".*-tw$" string="@{interface}"/>
			</condition>
		
			<if>
				<equals arg1="${interface.tw.@{interface}}" arg2="true" />
				<!--台湾接口版本处理 -->
				<then>
					<!-- 获取接口名 -->
					<loadresource property="interface.name.@{interface}">
  						<string value="@{interface}" />
  						<filterchain>
	  						<tokenfilter>
	    						<replaceregex pattern="-tw$" />
								</tokenfilter>
							</filterchain>
					</loadresource>
					
					<!-- 判断接口生成类目录是否存在-->
					<condition property="interface.class.@{interface}" value="true" else="false">
	    			<and>
	      		<available file="${classes}/com/sf/integration/${interface.name.@{interface}}" type="dir" />
	    			</and>
		  		</condition>
					 <if>
					 		<equals arg1="${interface.class.@{interface}}" arg2="true" />
					 		<!--接口生成类目录存在,才打包 -->
					 		<then>
					 			<!--判断接口绑定配置文件是否存在 -->
					 			<condition property="interface.binding.@{interface}" value="true" else="false">
						    	<and>
						      	<available file="${interface_code}/${interface.name.@{interface}}/binding/binding.xml"/>
						    	</and>
				  			</condition>
				  			<if>
				  				<equals arg1="${interface.binding.@{interface}}" arg2="true" />
				  				<!--接口绑定配置文件存在,才生成绑定类-->
					 				<then>
							 			<java classname="org.jibx.binding.Compile" fork="true" dir="${classes}" failonerror="true">
											<classpath refid="project.class.path" />
											<arg value="${interface_code}/${interface.name.@{interface}}/binding/binding.xml" />
										</java>
									</then>
								</if>
								<!--打包台湾接口版本JAR 
					 			<jar destfile="${web}/WEB-INF/lib/sf-interface-@{interface}-${version}.jar" basedir="${classes}" encoding="UTF-8">
					 				<include name="com/sf/integration/${interface.name.@{interface}}/**" />
					 			</jar>
					 			-->
					 		</then>
					 </if>
					
				
				</then>
				
				<else>
					<!-- 判断接口生成类目录是否存在-->
					<condition property="interface.class.@{interface}" value="true" else="false">
	    			<and>
	      		<available file="${classes}/com/sf/integration/@{interface}" type="dir" />
	    			</and>
		  		</condition>
					 <if>
					 		<equals arg1="${interface.class.@{interface}}" arg2="true" />
					 		<!--接口生成类目录存在,才打包 -->
					 		<then>
					 			<!--判断接口绑定配置文件是否存在 -->
					 			<condition property="interface.binding.@{interface}" value="true" else="false">
						    	<and>
						      	<available file="${interface_code}/@{interface}/binding/binding.xml"/>
						    	</and>
				  			</condition>
				  			<if>
				  				<equals arg1="${interface.binding.@{interface}}" arg2="true" />
				  				<!--接口绑定配置文件存在,才生成绑定类-->
					 				<then>
							 			<java classname="org.jibx.binding.Compile" fork="true" dir="${classes}" failonerror="true">
											<classpath refid="project.class.path" />
											<arg value="${interface_code}/@{interface}/binding/binding.xml" />
										</java>
									</then>
								</if>
								<!--
					 			<jar destfile="${web}/WEB-INF/lib/sf-interface-@{interface}-${version}.jar" basedir="${classes}" encoding="UTF-8">
					 				<include name="com/sf/integration/@{interface}/**" />
					 			</jar>
					 			-->
					 		</then>
					 </if>
				</else>
			</if>
		</sequential>
		</for>
	</target>
	
	
</project>

  

posted @ 2017-12-20 15:04  杯子茶壶  阅读(104)  评论(0)    收藏  举报