builder.xml 13.2 KB
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="help" name="Custom builder">
	<!-- Build.xml - versione 2.0.0 -->

	<property name="project.name" value="FileProxyServer" />

	<tstamp>
		<format property="today" pattern="yyyy-MM-dd HH:mm:ss" />
	</tstamp>

	<property environment="env"/>


	<target name="help">
		<echo message="Help.." />

	</target>




	<!-- File di configurazione 1 -->
	<target name="sub-environment" >
		<!-- description="Routine di configurazione variabili d'ambiente" -->
		<echo message="Set environment...." />

		<property name="project.src" value="${basedir}/src" />
		<property name="project.build" value="${basedir}/build/classes" />
		<property name="project.lib" value="${basedir}/lib" />
		<condition property="project.dist" value="${basedir}/dist/${config.cliente}" else="${basedir}/dist">
			<isset property="config.cliente"/>
		</condition>

		<!--property name="project.conf" value="${basedir}/conf" / -->
		<property name="project.conf" value="conf" />

		<!-- Nome del progetto a cui sono legati i file di configurazione - FIXME -->
		<property name="application.name" value="fproxy" />

		<!-- Nome base del file war a cui saranno concatenati versione e release -->
		<property name="project.warfile" value="${application.name}" />

		<!-- Cartella in cui deve essere copiato il file di versione -->
		<property name="version.package" value="it/softecspa/portal" />

	</target>

	<!-- File di configurazione 2 -->
	<target name="sub-configuration" depends="sub-environment" >
		<!-- description="Routine di configurazione variabili d'ambiente" -->
		<echo message="Load configuration...." />

		<property name="project.version.file" value="${project.conf}/version.properties" />
		<property file="${project.version.file}" />
		<antcallback target="sub-version" return="real.version.number"/>

		<!-- Estrazione della versione -->
		<echo message="Versione ${real.version.number} ${version.release}" />
		<echo message="Build ${build.number}" />
	</target>


	<!-- Gestisce il numero di versione -->
	<target name="sub-version" >
		<!-- description="Calcolo versione e progressivo compilazione" -->
		<echo message="Update library version file" />
		<propertyfile file="${project.version.file}" comment="Versionamento">
			<entry  key="version.number" default="0.0.1"/>
			<entry  key="version.release" default="beta"/>
			<entry  key="build.number" default="0"/>
			<entry  key="build.date" type="date" value="now" pattern="dd/MM/yyyy HH:mm"/>
		</propertyfile>

		<!-- Richiesta di conferma -->
		<input message="Building ${project.name} with version:" 
			   addproperty="input.version"
			   defaultvalue="${version.number}"/>

		<if>
			<not>
				<equals arg1="${version.number}" arg2="${input.version}" />
			</not>
			<then>

				<!-- Richiesta di conferma -->
				<input message="Confermi il cambio di versione (old '${version.number}' vs new '${input.version}')?" 
					   validargs="S,n" 
					   addproperty="input.response"
					   defaultvalue="S"/>
				<condition property="do.abort">
					<not>
						<equals arg1="S" arg2="${input.response}" />
					</not>
				</condition>
				<fail if="do.abort">Operazione annullata dall'utente</fail>


				<!-- Aggiornamento versione -->
				<echo message="New version number, update file ${project.version.file}" />
				<propertyfile file="${project.version.file}" comment="Versionamento">
					<entry key="version.number" value="${input.version}" />
				</propertyfile>

				<property name="real.version.number" value="${input.version}" />
			</then>
			<else>
				<property name="real.version.number" value="${version.number}" />
			</else>
		</if>


		<!-- Incrementa il numero di compilazione -->
		<buildnumber file="${project.version.file}"/>
	</target>


	<!-- Gestisce il numero di versione -->
	<target name="sub-version-XML2">
		<!-- description="Gestione file info.xml" -->
		<property name="infoxml.name" value="version.xml" />
		<property name="infoxml.source" value="${project.conf}/${infoxml.name}" />
		<property name="infoxml.target" value="${project.build}/${infoxml.package}/${infoxml.name}" />
		<echo message="Updating file ${infoxml.name}" />

		<copy file="${infoxml.source}" tofile="${infoxml.target}" overwrite="true" />
		<condition property="installation" value="${config.cliente}/${config.dir}" else="${config.dir}">
			<isset property="config.cliente"/>
		</condition>
		<replace file="${infoxml.target}" value="Value not found in version.properties"  propertyFile="${project.version.file}">
			<replacefilter token="@version.number@"   		value="${real.version.number}"/>
			<replacefilter token="@version.release@"  		value="${version.release}"/>
			<replacefilter token="@build.number@"     		value="${build.number}"/>
			<replacefilter token="@build.date@"       		property="build.date"/>
			<replacefilter token="@build.installation@" 	value="${installation}"/>
		</replace>

		<!-- Aggiungo una copia del file di versione nella cartella di configurazione -->
		<copy file="${infoxml.target}"   tofile="${project.conf}/${installation}/${infoxml.name}" overwrite="true" />



		<!-- Aggiorno gli stessi dati nel WEB.XML  -->
		<property name="webxml.name" value="web.xml" />
		<property name="webxml.source" value="${project.conf}/web.xml" />
		<property name="webxml.target" value="${project.conf}/${installation}/WEB-INF/web.xml" />
		<echo message="Updating file ${webxml.name}" />

		<copy file="${webxml.source}" tofile="${webxml.target}" overwrite="true" />
		<replace file="${webxml.target}" value="Value not found in version.properties"  propertyFile="${project.version.file}">
			<replacefilter token="@version.number@"   		value="${real.version.number}"/>
			<replacefilter token="@version.release@"  		value="${version.release}"/>
			<replacefilter token="@build.number@"     		value="${build.number}"/>
			<replacefilter token="@build.date@"       		property="build.date"/>
			<replacefilter token="@build.installation@" 	value="${installation}"/>
			<!-- Varaibile custom per app New Relic-->
			<replacefilter token="@new.relic@" 				value="${new.relic}"/>
		</replace>


	</target>





	<!-- Funzione di servizio, pulisce la cartella dove viene creata la distribuzione -->
	<target name="cleardist" if="file.includes" depends="sub-environment">
		<!-- description="Pulisce la cartella dove viene creata la distribuzione" -->

		<property name="todelete" value="${file.includes}*.*.*_*.war" />
		<echo message="Clearing dist folder for file '${todelete}'" />

		<delete failonerror="false" verbose="true">
			<fileset dir="${project.dist}"  includes="${todelete}"/>
		</delete>

	</target>




	<!-- Routine generale di generazione del pacchetto -->
	<target name="dist" if="config.dir" depends="sub-configuration" >

		<condition property="project.warfile.standardaname" value="${project.warfile}_${config.cliente}_${config.prefix}" else="${project.warfile}_${config.prefix}">
			<isset property="config.cliente"/>
		</condition>

		<echo message="Deleting and creating dist dir ${project.dist}" />
		<antcall target="cleardist">
			<param name="file.includes" value="${project.warfile.standardaname}" />
		</antcall>
		<mkdir dir="${project.dist}"/>

		<!-- Ricostruisco i JAR per le librerie nazca -->
		<!-- <antcall target="subBuild"><param name="SubProject" value="${nazca 3.0.0.location}"/></antcall> -->
		<!-- <antcall target="subBuild"><param name="SubProject" value="${nazca 3.0.0 web.location}"/></antcall> -->


		<!-- Creazione file informazioni distribuzione -->
		<antcall target="sub-version-XML2">
			<param name="infoxml.package" value="${version.package}"/>
		</antcall>

		<!-- Valorizzazione del nome del file WAR -->
		<mkdir dir="lib"/>
		<property name="warfile.name" value="${project.warfile.standardaname}${real.version.number}_${build.number}.war" />


		<!-- Escludo le pagine jsp di test per tutte le installazioni eccetto che per "develop" 
		<condition property="test.dir" value="test/**" else="cartella_inesistente">
			<not>
				<equals arg1="${config.dir}" arg2="develop" casesensitive="false"/>
			</not>
		</condition>
		-->

		<echo message="Exporting project in '${warfile.name}'" />
		<condition property="installation" value="${config.cliente}/${config.dir}" else="${config.dir}">
			<isset property="config.cliente"/>
		</condition>
		<war destfile="${project.dist}/${warfile.name}" webxml="${project.conf}/${installation}/WEB-INF/web.xml">
			<manifest>
				<attribute name="Release"         value="${installation}"/>
				<attribute name="Release-Date"    value="${today}"/>
				<attribute name="Release-Version" value="${real.version.number} ${version.release}"/>
				<attribute name="Release-Build"   value="${build.number}"/>
				<attribute name="Release-User"    value="${env.USERNAME}"/>
				<attribute name="Release-Host"    value="${env.COMPUTERNAME}"/>
			</manifest>

			<!-- PERSONALIZZAZIONE - INIZIO -->
			<fileset dir="WebContent">
				<include name="**"/>

				<!-- Lista di esclusione -->
				<!-- <exclude name="${test.dir}"/> -->
				<exclude name="WEB-INF/web.xml"/>
				<exclude name="META-INF/context.xml"/>
				<exclude name="META-INF/**.txt"/>
				<exclude name="image-pack/**"/>
				<exclude name="Thumbs.db"/>
			</fileset>

			<fileset dir="${project.conf}/${installation}/">
				<include name="META-INF/context.xml"/>
				<!-- <include name="image-pack/**"/> -->
				<!-- <include name="config.local/version.txt"/> -->
			</fileset>


			<!-- COMMON -->
			<lib dir="${project.lib}/common" >
				<exclude name="indexer/**"/>
				<exclude name="analyzer**"/>
				<exclude name="local/**"/>
			</lib>
			<!-- COMMON - LOCAL -->
			<lib dir="${project.lib}/common/local" >
			</lib>
			<!-- JACKSON -->
			<lib dir="${project.lib}/jackson" >
			</lib>
			<!-- UPLOADBEAN -->
			<lib dir="${project.lib}/uploadbean" >
				<exclude name="fileupload.jar"/>
			</lib>
			<!-- JAVA APNS -->
			<lib dir="${project.lib}/java-apns" >
				<include name="apns-0.1.5-jar-with-dependencies.jar"/>
			</lib>
			<!-- GCM (Google) -->
			<lib dir="${project.lib}/gcm" >
			</lib>

			<!-- Amazon S3 -->
			<lib dir="${project.lib}/amazon.s3">
				<include name="aws-java-sdk-1.0.11.jar"/>
			</lib>
			<lib dir="${project.lib}/amazon.s3/lib.required">
				<include name="jackson-core-asl-1.4.3.jar"/>
				<include name="stax-1.2.0.jar"/>
				<include name="stax-api-1.0.1.jar"/>
			</lib>
			<!-- C3P0, escluso perchè già presente nella commonlib, ma non i produzione! -->
			<lib dir="${project.lib}/c3p0">
				<exclude name="**.zip"/>
			</lib>
			<!-- DBCP 
			<lib dir="${project.lib}/dbcp">
				<exclude name="commons-dbcp-1.2.2-src.zip"/>
				<exclude name="commons-pool-1.4-src.zip"/>
			</lib> -->


			<!-- Classes, sono esclusi i file di configurazione -->
			<classes dir="${project.build}">
				<include name="**"/>

				<exclude name="conf/log4j.xml" />
				<exclude name="conf/portal_settings.xml"/>
				<exclude name="conf/sso**.xml" />
			</classes>
			<!-- Sono inclusi i file di configurazione specifici -->
			<classes dir="${project.conf}/${installation}">

				<include name="conf/log4j.xml" />
				<include name="conf/portal_settings.xml"/>
				<include name="conf/sso**.xml" />
			</classes>
			<!-- PERSONALIZZAZIONE - FINE -->
			
		</war>

		<antcall target="refresh" />
	</target>




	<target name="refresh" depends="sub-include-AntContrib">

		<trycatch reference="exception_ref">
			<try>
				<echo>Eclipse refresh in progress...</echo>
				<!-- Refresh del progetto 
				  Per funzionare deve essere impostato il seguente flag in "External tool configuration"
				  JRE >	Run in the same JRE as the workspace  
				-->
				<eclipse.refreshLocal resource="${project.name}" depth="infinite"/>
				<echo>Eclipse refreshed!</echo>

			</try>
			<catch>
				<echo>Per funzionare deve essere impostato il seguente flag in "External tool configuration"
					  JRE >	Run in the same JRE as the workspace</echo>
			</catch>
			<finally>
				<!-- <echo>Finally</echo> -->
			</finally>
		</trycatch>
	</target>





	<target name="sub-include-AntContrib">
		<!-- description="Include le librerie (JAR) per gestire il TRY/CATCH/FINALLY" -->
		<echo>Include ANT-contrib jar</echo>

		<!-- Include le librerie ant-contrib-0.6.jar 
					     http://ant-contrib.sourceforge.net/ -->
		<taskdef resource="net/sf/antcontrib/antcontrib.properties">
			<classpath>
				<pathelement location="${basedir}/lib/ant/ant-contrib-0.6.jar"/>
			</classpath>
		</taskdef>

	</target>

	<target name="sub-include-JSCH">
		<echo>Include JSCH jar</echo>
		<!--
		<taskdef name="scp" classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp" >
			<classpath>
				<pathelement location="${basedir}/lib/ant/ant-jsch-1.9.2.jar" />
				<pathelement location="${basedir}/lib/ant/jsch-0.1.50.jar" />
			</classpath>
		</taskdef>
		<taskdef name="sshexec" classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec"  >
			<classpath>
				<pathelement location="${basedir}/lib/ant/ant-jsch-1.9.2.jar" />
				<pathelement location="${basedir}/lib/ant/jsch-0.1.50.jar" />
			</classpath>
		</taskdef>
		-->

	</target>



</project>