Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to diff files/folders in Gradle?

I need to write a script in Gradle that takes as an input 2 folders. Both folders contain <1000 files (mostly images) with reasonably similar structure. The output should be a list of files that changed and what kind of difference it is (added file/deleted file/changed file).

Edit: Heres a sample script https://gist.github.com/igormukhin/71d780c4274336eeb297 . The only problem is that it compares by timestamp.

like image 293
sydd Avatar asked May 22 '15 16:05

sydd


People also ask

How do I find the .Gradle folder?

The default location for the files for a Windows user is under the Users directory on the C: drive. So a user called John Doe would have a folder at C:\Users\John Doe. This user directory is where the Windows . gradle folder is located.

What is .Gradle directory?

The Gradle user home directory ( $USER_HOME/.gradle by default) is used to store global configuration properties and initialization scripts as well as caches and log files.

What is FileTree in Gradle?

A FileTree represents a hierarchy of files. It extends FileCollection to add hierarchy query and manipulation methods. You typically use a FileTree to represent files to copy or the contents of an archive. You can obtain a FileTree instance using Project.


2 Answers

I have recently coded up something similar to what you are asking for: DirectoryDifferenceCollector; however, it actually compares the contents of the files (as a hash) and not the timestamp. I would be willing to update it to accept a configurable strategy if that would suit your needs, or you can just use the concepts involved.

Basically it scans both directories and determines the missing files in both A and B and then it also determines which files are common to both directories, but have different content.

The results are collected in a DirectoryDifference object with the respective file paths for each category.

like image 166
cjstehno Avatar answered Nov 15 '22 08:11

cjstehno


I'd be tempted to use diff:

def process = 'diff x y'.execute()

You can then access the output of the command as text:

println process.err.text
println process.in.text

And get the exit status via:

int status = process.waitFor()

Many common operating systems will come with diff installed, but Windows probably does not.

like image 31
Armand Avatar answered Nov 15 '22 08:11

Armand