I have just written a method for getting a List of differences between two IFileSpec objects, however, I do not know how to actually retrieve the differences from the IFileDiff object.
Here is the method I have written so far,
public void getFileDiff(String file1, String file2){
List<IFileSpec> fileList1 = null;
List<IFileSpec> fileList2 = null;
List<IFileDiff> fileDiff = null;
try{
fileList1 = getIFileSpecList(file1);
fileList2 = getIFileSpecList(file2);
fileDiff = iServer.getFileDiffs(fileList1.get(0), fileList2.get(0), null, DiffType.IGNORE_LINE_ENDINGS,false,true,false);
for(IFileDiff iFileDiff : fileDiff) {
System.out.println(iFileDiff.getRevision1() + " ::: " + iFileDiff.getRevision2());
}
}
catch(Exception e){e.printStackTrace();}
}
This code happily prints the correct revisions of the files but getting the actual String differences is something I have yet to come across. If anybody knows what to do I would really like to hear from you !!
I forgot to answer this, as far as I remember, there is no way to get the difference of two files using the Perforce Java API. The only way to do it is, Sync out the files to a temporary location and call the OS’s built in “diff” command. Capture the output and pipe to your application.