Maintenance

  • Home
  • Log in
  • « Staff ports in Lib A316
  • Docker Jenkins image pushed to hub.docker.com »

Doing file diffs during ant builds

Posted by mholmes on 01 Jan 2017 in R & D, Activity log, Documentation
I've been working on ways of moving all TEI build functionality from Makefiles into ant tasks, for various reasons including portability and simplicity (currently Makefiles call ant tasks at various points, which is mighty confusing). One issue I hadn't looked at yet is the best way to do the extensive file diffing which is part of build tests (testing process output against expected results). As a note-to-self, this is a test file which does file diffing between two different directories of files; the most effective approach uses filesets and depends initially on the ant filesmatch condition (a straight byte-for-byte comparison); if that fails, then an external diff tool is called (ant doesn't have one built in), giving detailed differences. The external diff tool call could be switchable by OS, so this could run on Windows in the distant future.

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="all" name="test">
    
<!-- This is a test file for figuring out how best to 
     integrate file diffing checks into ant build files. -->
    
<!-- We need ant-contrib to do foreach.   -->
    <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
    
    
<!--    Two filesets to diff. -->
    <fileset id="files1" dir="${basedir}/files1" includes="*.txt"/>
    
    <fileset id="files2" dir="${basedir}/files2" includes="*.txt"/>
    
    <target name="diffOneFile">
        <propertyregex property="otherFile" input="${inFile}" regexp="files1" replace="files2" global="true"/>
        <echo message="diffing ${inFile} against ${otherFile}"/>
        <trycatch>
            <try>
                <fail message="${inFile} is different from ${otherFile}.">    
                    <condition>
                        <not>
                            <filesmatch file1="${inFile}" file2="${otherFile}"/>
                        </not>
                    </condition>
                </fail>
            </try>
            <catch>
                <echo message="ERROR: DIFF FAILURE..."/>
                <exec dir="." executable="diff">
                    <arg line="-u"/>
                    <arg file="${inFile}"/>
                    <arg file="${otherFile}"/>
                </exec>
                <fail message="Build failed because of differences between  ${inFile} and ${otherFile}. See diff output above."/>
            </catch>
        </trycatch>
        
    </target>
    
    <target name="diffFileSets">
        <foreach target="diffOneFile" param="inFile">
            <path>
                <fileset refid="files1"/>                
            </path>
        </foreach>
    </target>
    
    <target name="all">
        <antcall target="diffFileSets"/>
    </target>
    
</project>

This entry was posted by Martin and filed under R & D, Activity log, Documentation.

Maintenance

This blog is the location for all work involving software and hardware maintenance, updates, installs, etc., both routine and urgent.
  • Home
  • Recently
  • Archives
  • Categories

Search

Categories

  • All
  • Announcements
  • Hit by a bus
  • Labs
    • Activity log
    • Documentation
  • Notes
  • R & D
    • Activity log
    • Documentation
  • Servers
    • Activity log
    • Documentation
  • Tasks

All blogs

  • Academic
  • AdaptiveDB
  • Admin
  • Announcements
  • CanMys
  • Cascade
  • CGWP
  • ColDesp
  • Depts
  • DVPP
  • Endings
  • HCMC Blogs
  • Landscapes
  • LEMDO
  • Linguistics
  • Maint
  • LondonMap
  • Mariage
  • MoM
  • Moses
  • Pro-D
  • Projects
  • ScanCan
  • HumsSites
  • Wendat

This collection ©2022 by admin • Help • Run your own website!