venerdì 16 novembre 2012

to make the diff

How to export from SVN repository only modified files between two tags with Ant?

here a simple script... URL1 and URL2 are the urls of the tags, "tmpDir" is a temporary folder(write permissions are necessary), "targetDir" is the destination folder.

USAGE: Simply run ant in the folder where you put the script (save the script as build.xml)
<project name="export diff" basedir="." default="diff">
<property name="tmpDir" value="/Temp" />
<property name="targetDir" value="/Target" />
<!-- svn -->
<property name="svn_client" value="svn" />
<property name="Url1" value="http://svn.apache.org/repos/asf/ant/core/tags/ANT_183/" />
<property name="Url2" value="http://svn.apache.org/repos/asf/ant/core/tags/ANT_184/" />
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<target name="export_new" description="checkout del target" depends="">
<echo message=" - export ${Url2} in ${basedir}${tmpDir}" />
<echo message=" from : ${Url2}" />
<echo message=" to : ${basedir}${tmpDir}" />
<exec executable="${svn_client}" failonerror="true">
<arg value="export" />
<arg value="--force" />
<arg value="${Url2}" />
<arg value="${basedir}${tmpDir}" />
</exec>
</target>
<target name="diff" description="esegue la differenza tra ${Url2} e ${Url1}" depends="export_new">
<echo message=" - diff --summarize ${Url1} ${Url2}" />
<exec executable="${svn_client}" output="${basedir}/diff.patch" failonerror="true">
<arg value="diff" />
<arg value="--summarize" />
<arg value="${Url1}" />
<arg value="${Url2}" />
</exec>
<loadfile srcFile="${basedir}/diff.patch" property="file_diff" failonerror="true">
<filterchain>
<tokenfilter>
<replacestring from="M " to="" />
<replacestring from="A " to="" />
<replacestring from="MM " to="" />
<replacestring from=" " to="" />
<replacestring from="${Url1}" to="" />
</tokenfilter>
<striplinecomments>
<comment value="[exec]D" />
</striplinecomments>
<suffixlines suffix="," />
<striplinebreaks />
<deletecharacters chars="\n" />
</filterchain>
</loadfile>
<condition property="there_is_file">
<isset property="file_diff" />
</condition>
<if>
<equals arg1="${there_is_file}" arg2="true" />
<then>
<antcall target="copy_filediff_to_dir">
<param name="file_diff" value="${file_diff}" />
</antcall>
</then>
<else>
<echo message="No differences between ${URL1} e ${URL2}" />
</else>
</if>
</target>
<target name="copy_filediff_to_dir" if="there_is_file" description="copia i file sul server" depends="">
<echo message=" - copy different files to dir ${targetDir}" />
<echo message="${file_diff}" />
<echo message=" - copy modified file - " />
<echo message=" from : ${basedir}${tmpDir}" />
<echo message=" to : ${targetDir}/" />
<mkdir dir="${basedir}${targetDir}" />
<for list="${file_diff}" param="letter">
<sequential>
<echo message="@{letter}" />
<copy todir="${basedir}${targetDir}" filtering="true" verbose="true" failonerror="true">
<fileset dir="${basedir}${tmpDir}">
<include name="@{letter}" />
<exclude name="*/*.cs" />
</fileset>
</copy>
</sequential>
</for>
<delete dir="${basedir}${tmpDir}" />
</target>
</project>
view raw build.xml hosted with ❤ by GitHub