Joe
Joe

Reputation: 243

how to diff files using Ant like the diff command -u on Linux

Background: Now I write some scripts to output the differences between two files into a file. Now I using Linux command diff -u. Is there a way in Ant to diff files? So that I can use groovy + ant + diff, and need not to invoke the local command.

Upvotes: 1

Views: 576

Answers (1)

tim_yates
tim_yates

Reputation: 171084

No, there is no diff command in ant.

You could just grab something like java-diff-utils and write your own though (if you want to avoid the system diff command)

@Grab('com.googlecode.java-diff-utils:diffutils:1.2.1')
import difflib.*

def fileAContents = '''Line 1
                      |Line 2
                      |Line 3'''.stripMargin().split( '\n' ).toList()

def fileBContents = '''Line 1
                      |Line Two
                      |Line 3'''.stripMargin().split( '\n' ).toList()

DiffUtils.diff( fileAContents, fileBContents ).deltas.each {
    println it
}

which prints:

[ChangeDelta, position: 1, lines: [Line 2] to [Line Two]]

Upvotes: 1

Related Questions