Java TFS SDK - diff two files
-
2012年2月20日 下午 04:20
Hi,
I've tried to work with Java TFS SDK API. It works fine. But I'm not able to find how to get unified diff of two files as it is possible for .NET API (http://blogs.msdn.com/b/buckh/archive/2006/04/06/project-diff.aspx)
So my question is: Is there a possibility how to get diff of two code changes? I need to get count of changed files and count of changed lines.
Thanks in advance for your reply.
Regards,
Petr

Petr Dousa
- 已移動 John QiaoMicrosoft Contingent Staff 2012年2月21日 上午 01:20 (From:Team Foundation Server - General)
所有回覆
-
2012年2月24日 下午 02:09擁有者
The high level approach described in Buck's blog post is also the right approach for the Java SDK, but you'll have to implement the DiffFiles method another way. The TFS SDK for Java doesn't contain DiffItem and DiffItemVersionedFile. Those classes are in the TEE CLC product, not part of the SDK libraries.
Implementing your own replacement is pretty straightforward. You'll need to download the content from the Item to some local file (GetEngine.downloadFileToTempLocation() can help here, you can pass it the result of Item.getDownloadURL()). Then you launch your diff tool, however you want to configure it.
For an better experience, our DiffItem classes create temp files with names that mix together the Item's name and version. This allows the diff tools to show differences for "file.txt;C123" instead of just "abc123456.tmp". Our classes also compute some label strings that can be passed to diff tools, for even more information. You would have to construct these if you want them (from more information in the Item class), or just not pass them to your diff tool.
- 已提議為解答 Shaw TerwilligerOwner 2012年2月24日 下午 02:10
- 已標示為解答 Petr Dousa 2012年3月8日 下午 12:02
-
2012年6月29日 上午 11:07
Dear Shaw,
My objective is to read contents of a file.
Referring to your last note, I tried to create object of GetEngine but failed to get object of Workspace.
VersionControlClient vcc = tpc.getVersionControlClient();
Workspace workSpace = vcc.getWorkspace("C:\\RTM\\");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GetEngine engine = new GetEngine(vcc, workSpace);
engine.downloadFileToStream(path, baos);Here, workspace object is NULL.
Can you provide me any clue to make this happen.
Many thanks,
Mohit(
-
2012年7月4日 上午 11:39
Hi
I have successfully read contents of file in InputStream.
I was getting downloadUrl = null & I corrected it bt getting ItemSet using different method of VCC.
This method had parameter 'downloadInfo' as true.
ItemSet itemSet = vcc.getItems(document.getRepositoryAddress(),
new DateVersionSpec(Utilities.getCurrentCalendarDate()),
RecursionType.ONE_LEVEL, DeletedState.NON_DELETED,
ItemType.FILE, true);This was my Item had download URL into them & I used
engine.downloadFileToStream(item.getDownloadURL(), baos);
to download file contents
-Mohit

