Folder comparison that supports internal/external tool in IDEA 12/13?

In IDEA 14 I can easily launch a folder comparison that will use the configured external diff tool if present and the internal diff tool if not by calling com.intellij.diff.DiffManager.getInstance().showDiff().  That exact functionality is not present in earlier versions of IDEA, e.g., 12 and 13.  In those versions it seems I can use com.intellij.openapi.diff.DiffManager to get the DiffTool and then can ask the DiffTool to show a configured DiffRequest, or I can use DirDiffManager.  The latter launches the internal comparison tool fine, but it doesn't seem to be aware of the configured external tool for folder comparisons.  The former launches the external comparison tool fine when configured, but the internal tool says "Can not show diff" when launched.

Here's how I'm invoking it:

VirtualFile dir1 = ...;
VirtualFile dir2 = ...;
DiffTool diffTool = DiffManager.getInstance().getDiffTool();
DiffRequest diffRequest = new SimpleDiffRequest(project, "Comparing " + dir1.getName() + " to " + dir2.getName());
diffRequest.setContentTitles(dir1.getPath(), dir2.getPath());
diffRequest.setContents(new FileContent(project, dir1), new FileContent(project, dir2));;  // NOTE: I actually use invokeLater() to put this on the EDT

Like I said, when IDEA is configured for an external tool, e.g., Beyond Compare, this works.  When it's not, the internal tool is shown with "Can not show diff" in the body.

I've tried to see if there's some way for me to inspect the diff tool configuration, but I'm hitting dead ends on all fronts.  DiffManagerImpl.ENABLE_FOLDERS and DiffManagerImpl.FOLDERS_TOOL seem to be the settings I want, but unfortunately those are package visibility in IDEA 12/13 (though they're promoted to public in IDEA 14, so perhaps this was "fixed").  I thought perhaps DiffManagerImpl.getInstanceEx().getProperties() might save me, but unfortunately AbstractPropertyContainer.getValueOf() is protected visibility.

Hopefully I'm just doing something wrong here.  Any thoughts are greatly appreciated!

UPDATE: Hmmmm...looking at this a little more, I'm not sure if this was supported prior to IDEA 14.  Even the built-in CompareDirectoriesAction calls DirDiffManager which doesn't respect any configured folder comparison tool.  Hopefully someone will have some thoughts on how I might be able to do this, but it's looking less and less likely to be possible in a sanctioned manner.

Comment actions Permalink

Well, you can always take the code from IDEA 14 and copy it to your plugin project and use it that way. It may well be the case that no other solution would work.

Comment actions Permalink

Thanks for the reply.  Yeah, I considered that, but unfortunately it's all based on a different core configuration for diff in IDEA 14 vs. IDEA 12/13.  I'd have to drag in a non-trivial amount of code including a PersistedStateComponent (com.intellij.openapi.diff.impl.external.DiffManagerImpl).  I think I may just add a single config option to my own plugin in the older versions that tells it whether to use the external diff tool.  It's duplicate configuration, but it would be if I back-ported the IDEA 14 stuff as well.


Please sign in to leave a comment.