Subversion Repositories DevTools

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<project name="ant-subversion">
        
        <description>
        This ant file requires the use of jars in JavaSVN and svnant.
        
        This ant file provides a macro for sync'ing between a subversion
        checkout and another (newer) directory. The idea being that you
        want subversion to look like the sync directory. Refer to the 
        documentation above the macrodef for the svnsync macro for more
        information.
        
        In addition, this will only work with JavaSVN version 
        1.0.4005.cots or later due to the fact that previous versions
        of JavaSVN has a verion number in the svnClientAdapter jar.
        </description>
        
        <!-- define the subversion tasks -->
        <taskdef resource="svntask.properties">
                <classpath>
                        <pathelement path="${using.JavaSVN.basedir}/jar/javasvn.jar"/>
                        <pathelement path="${using.JavaSVN.basedir}/jar/javasvn-javahl.jar"/>
                        <pathelement path="${using.JavaSVN.basedir}/jar/svnClientAdapter-0.9.32.jar"/>
                        <pathelement path="${using.svnant.basedir}/jar/svnant.jar"/>
                </classpath>
        </taskdef>
        
        
        <!-- svnsync
        
                This macro will sync between a checked out copy of a repository 
                with another directory.
                
                Files that exist in both directories will be copied from the 
                syncdir to the checkout dir.
                
                Files and directories that ARE NOT in the syncdir but are in the 
                checkout dir will be deleted from subversion.
                
                Files and directories that ARE in the syncdir but not in the 
                checkout dir will be added to subversion.
                
                NOTE:   This macro does not checkout the files from subversion (do 
                                that prior to calling the macro). In addition, this macro 
                                does not commit any changes (do that after calling this macro).
        -->
        <macrodef name="svnsync">
                <attribute name="checkoutdir" default=".checkout"/> <!-- Keep this as a single directory. 
                                                                                                                                If you change to to something else it may not work.-->
                <attribute name="syncdir" default=".release"/>          <!-- Points to the new source from dpkg_archive-->
                
                <sequential>
                        <echo message="" file=".svnfileadd.txt"/>       <!-- blank out the .svnfileadd.txt file-->
                        <echo message="" file=".svndiradd.txt"/>        <!-- blank out the .svndiradd.txt file-->
                        <echo message="" file=".svndel.txt"/>           <!-- blank out the .svndel.txt file-->
                        <echo message="" file=".svndeldir.txt"/>        <!-- blank out the .svndeldir.txt file-->
                        
                        <!--update files in dest that exist in source-->
                        <copy todir="@{checkoutdir}" overwrite="true">
                                <fileset dir="@{syncdir}">
                                        <present present="both" targetdir="@{checkoutdir}"/>
                                </fileset>
                        </copy>
                        
                        <!-- determine all files in svn that are not in release
                                that need to be deleted. Write this information to a file for later 
                                processing -->
                        <for param="svn.delete">
                                <path>
                                        <fileset dir="@{checkoutdir}">
                                                <present present="srconly" targetdir="@{syncdir}"/>
                                        </fileset>
                                </path>
                                <sequential>
                                        <echo message="@{svn.delete}${line.separator}" file=".svndel.txt" append="true"/>
                                </sequential>
                        </for>
                        
                        <!-- determine all directories in svn that are not in release
                                that need to be deleted. Write this information to a file for later 
                                processing -->
                        <for param="svn.delete">
                                <path>
                                        <dirset dir="@{checkoutdir}">
                                                <present present="srconly" targetdir="@{syncdir}"/>
                                        </dirset>
                                </path>
                                <sequential>
                                        <echo message="@{svn.delete}${line.separator}" file=".svndeldir.txt" append="true"/>
                                </sequential>
                        </for>
                        
                        <!-- load the list of files to delete from subversion into a property.
                                loop through the list calling subversion delete on the files. 
                                
                                NOTE:   Ensure that the file does contain some files, otherwise
                                                the subversion command will fail. -->
                        <loadfile srcFile=".svndel.txt" property="svn.del.list"/>
                        <if>
                                <not>
                                        <equals arg1="${svn.del.list}" arg2="$${svn.del.list}"/>
                                </not>
                                <then>
                                        <for param="svn.del.file" list="${svn.del.list}" delimiter="${line.separator}">
                                                <sequential>
                                                        <echo message="svn delete @{svn.del.file}"/>
                                                        <svn>
                                                                <delete file="@{svn.del.file}"/>
                                                        </svn>
                                                </sequential>
                                        </for>
                                </then>
                        </if>
                        
                        <!-- load the list of directories to delete from subversion into a property.
                                loop through the list calling subversion delete on the directories. 
                                
                                NOTE:   Ensure that the file does contain some files, otherwise
                                                the subversion command will fail. -->
                        <loadfile srcFile=".svndeldir.txt" property="svn.del.list"/>
                        <if>
                                <not>
                                        <equals arg1="${svn.del.list}" arg2="$${svn.del.list}"/>
                                </not>
                                <then>
                                        <for param="svn.del.file" list="${svn.del.list}" delimiter="${line.separator}">
                                                <sequential>
                                                        <echo message="svn delete @{svn.del.file}"/>
                                                        <svn>
                                                                <delete dir="@{svn.del.file}"/>
                                                        </svn>
                                                </sequential>
                                        </for>
                                </then>
                        </if>
                        
                        <!-- determine all the directories to add source that are not in dest
                                and write them to a file for later processing -->
                        <for param="svn.add">
                                <path>
                                        <dirset dir="@{syncdir}">
                                                <present present="srconly" targetdir="@{checkoutdir}"/>
                                        </dirset>
                                </path>
                                <sequential>
                                        <echo message="@{svn.add}${line.separator}" file=".svndiradd.txt" append="true"/>
                                </sequential>
                        </for>
                        
                        <!-- determine all the files to add source that are not in dest
                                and write them to a file for later processing -->
                        <for param="svn.add">
                                <path>
                                        <fileset dir="@{syncdir}">
                                                <present present="srconly" targetdir="@{checkoutdir}"/>
                                        </fileset>
                                </path>
                                <sequential>
                                        <echo message="@{svn.add}${line.separator}" file=".svnfileadd.txt" append="true"/>
                                </sequential>
                        </for>
                        
                        <!-- copy all the files to add source that are not in dest to that when 
                                the files containing the directories and files to add to subversion
                                added the files are in the checkout location -->
                        <copy todir="@{checkoutdir}">
                                <fileset dir="@{syncdir}">
                                        <present present="srconly" targetdir="@{checkoutdir}"/>
                                </fileset>
                        </copy>
                        
                        <!-- fix up the svn add paths to point to the correct directories
                                by replacing the syncdir name with the checkout dir name -->
                        <replaceregexp file=".svndiradd.txt"
                         match="@{syncdir}"
                         replace="@{checkoutdir}"
                         byline="true"/>
                        <!-- fix up the svn add paths to point to the correct files
                                by replacing the syncdir name with the checkout dir name -->
                        <replaceregexp file=".svnfileadd.txt"
                         match="@{syncdir}"
                         replace="@{checkoutdir}"
                         byline="true"/>
                                                 
                        <!-- load the list of directories to add to subversion into a
                                property, and then iterate through them performing a
                                subversion add command on each directory. 
                                
                                NOTE:   Check that there are directories to add, otherwise
                                                the subversion add command will report and error -->
                        <loadfile srcFile=".svndiradd.txt" property="svn.dir.add.list"/>
                        <if>
                                <not>
                                        <equals arg1="${svn.dir.add.list}" arg2="$${svn.dir.add.list}"/>
                                </not>
                                <then>
                                        <for param="svn.dir.add.file" list="${svn.dir.add.list}" delimiter="${line.separator}">
                                                <sequential>
                                                        <echo message="svn add @{svn.dir.add.file}"/>
                                                        <svn>
                                                                <add dir="@{svn.dir.add.file}" recurse="false"/>
                                                        </svn>
                                                </sequential>
                                        </for>
                                </then>
                        </if>
                        
                        <!-- load the list of files to add to subversion into a 
                                property, and iterate through them performing a
                                subversion add command on each file. 
                                
                                NOTE:   Check that there are files to add, otherwise
                                                the subversion add command will report and error -->
                        <loadfile srcFile=".svnfileadd.txt" property="svn.file.add.list"/>
                        <if>
                                <not>
                                        <equals arg1="${svn.file.add.list}" arg2="$${svn.file.add.list}"/>
                                </not>
                                <then>
                                        <for param="svn.file.add.file" list="${svn.file.add.list}" delimiter="${line.separator}">
                                                <sequential>
                                                        <echo message="svn add @{svn.file.add.file}"/>
                                                        <svn>
                                                                <add file="@{svn.file.add.file}"/>
                                                        </svn>
                                                </sequential>
                                        </for>
                                </then>
                        </if>
                </sequential>
        </macrodef>
        
</project>