Bug 29633 - Need DirDiff Task
Summary: Need DirDiff Task
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: unspecified
Hardware: Other other
: P3 enhancement (vote)
Target Milestone: ---
Assignee: Ant Notifications List
Depends on:
Reported: 2004-06-17 08:08 UTC by Raja Nagendra Kumar
Modified: 2008-11-24 03:58 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Raja Nagendra Kumar 2004-06-17 08:08:13 UTC
When porting make to ant we need to see what is the difference between the 
build files when done from make and when done from ant. In such case it would 
be better to have DirDiff Task which takes in src and dest directories to 
compare and also the full file name(including path as we support for javac 
includes and excludes) patterns sets to compare.

I have one written see if this code helps

This code does not compare the files with-in the jar files. We may think of 
supporting this in the official ant task of DirDiff.

import org.apache.tools.ant.DirectoryScanner;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public final class DirDiff
    final DirectoryScanner masterDS;
    final DirectoryScanner childDS;

    public DirDiff( final DirectoryScanner aMasterDS,
		    final DirectoryScanner aChildDS )
	masterDS = aMasterDS;
	childDS = aChildDS;

    public void diff()
	List exactMatchers = new ArrayList();
	List missingInChild = new ArrayList();
	List differsInChild = new ArrayList();
	List extraInChild = new ArrayList();
	extraInChild.addAll( Arrays.asList( childDS.getIncludedFiles() ) );

	String[] masterFiles = masterDS.getIncludedFiles();
	for ( int j = 0; j < masterFiles.length; j++ )
	    File bMasterFile = new File( masterDS.getBasedir(), masterFiles
[j] );
	    File bChildFile = new File( childDS.getBasedir(), masterFiles[j] );
	    if ( bMasterFile.exists() )
		if ( !bChildFile.exists() )
		    missingInChild.add( masterFiles[j] + "\n" );
		else if ( bMasterFile.length() == bChildFile.length() )
		    exactMatchers.add( masterFiles[j] + "\n" );
			    masterFiles[j] + "(" + (bMasterFile.length() - 
bChildFile.length()) +
			    ")\n" );
		extraInChild.remove( masterFiles[j] );

	System.out.println( "\n\nmissing In Child:" + missingInChild );
	System.out.println( "\n\ndiffers In Child:" + differsInChild );
	System.out.println( "\n\nextra In Child:" + extraInChild );
	//System.out.println( "Exact Match files:" + exactMatchers );

    public static void main( String[] args )
	DirectoryScanner master = new DirectoryScanner();
	master.setBasedir( "c:/temp" );
	DirectoryScanner child = master;
	new DirDiff( master, child ).diff();
}//class DirDiff