From 616bb51340d2976dad14b8b80019ffd179f2c0e3 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Thu, 10 Oct 2013 20:09:42 +0400 Subject: [PATCH 1/9] GitRootDetectInfo renamed to VcsRootDetectInfo --- plugins/git4idea/src/git4idea/GitVcs.java | 4 ++-- .../src/git4idea/roots/GitIntegrationEnabler.java | 2 +- .../src/git4idea/roots/GitRootDetector.java | 14 +++++++------- .../git4idea/src/git4idea/roots/GitRootFinder.java | 2 +- ...tRootDetectInfo.java => VcsRootDetectInfo.java} | 4 ++-- .../roots/GitIntegrationEnablerTest.groovy | 6 +++--- .../git4idea/roots/GitRootDetectorTest.groovy | 4 ++-- 7 files changed, 18 insertions(+), 18 deletions(-) rename plugins/git4idea/src/git4idea/roots/{GitRootDetectInfo.java => VcsRootDetectInfo.java} (95%) diff --git a/plugins/git4idea/src/git4idea/GitVcs.java b/plugins/git4idea/src/git4idea/GitVcs.java index 16f6db1bb59e..7f2c1c11fd9e 100644 --- a/plugins/git4idea/src/git4idea/GitVcs.java +++ b/plugins/git4idea/src/git4idea/GitVcs.java @@ -78,7 +78,7 @@ import git4idea.merge.GitMergeProvider; import git4idea.rollback.GitRollbackEnvironment; import git4idea.roots.GitIntegrationEnabler; import git4idea.roots.GitRootChecker; -import git4idea.roots.GitRootDetectInfo; +import git4idea.roots.VcsRootDetectInfo; import git4idea.roots.GitRootDetector; import git4idea.status.GitChangeProvider; import git4idea.ui.branch.GitBranchWidget; @@ -592,7 +592,7 @@ public class GitVcs extends AbstractVcs { public void enableIntegration() { ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { public void run() { - GitRootDetectInfo detectInfo = new GitRootDetector(myProject, myPlatformFacade).detect(); + VcsRootDetectInfo detectInfo = new GitRootDetector(myProject, myPlatformFacade).detect(); new GitIntegrationEnabler(myProject, myGit, myPlatformFacade).enable(detectInfo); } }); diff --git a/plugins/git4idea/src/git4idea/roots/GitIntegrationEnabler.java b/plugins/git4idea/src/git4idea/roots/GitIntegrationEnabler.java index 32c3b686f578..69c105e5a08b 100644 --- a/plugins/git4idea/src/git4idea/roots/GitIntegrationEnabler.java +++ b/plugins/git4idea/src/git4idea/roots/GitIntegrationEnabler.java @@ -51,7 +51,7 @@ public class GitIntegrationEnabler { myPlatformFacade = platformFacade; } - public void enable(@NotNull GitRootDetectInfo detectInfo) { + public void enable(@NotNull VcsRootDetectInfo detectInfo) { Notificator notificator = myPlatformFacade.getNotificator(myProject); Collection roots = detectInfo.getRoots(); VirtualFile projectDir = myProject.getBaseDir(); diff --git a/plugins/git4idea/src/git4idea/roots/GitRootDetector.java b/plugins/git4idea/src/git4idea/roots/GitRootDetector.java index 7a7c332d0000..3c5708714b2c 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootDetector.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootDetector.java @@ -29,7 +29,7 @@ import java.util.Set; /** *

* Scans the file system looking for Git roots, which contain the Project or its parts, - * and returns the information enclosed to the {@link GitRootDetectInfo}. + * and returns the information enclosed to the {@link VcsRootDetectInfo}. * The main part of the information are Git roots which will be proposed to the user to be added as VCS roots. *

*

@@ -51,29 +51,29 @@ public class GitRootDetector { } @NotNull - public GitRootDetectInfo detect() { + public VcsRootDetectInfo detect() { return detect(myProject.getBaseDir()); } @NotNull - public GitRootDetectInfo detect(@Nullable VirtualFile startDir) { + public VcsRootDetectInfo detect(@Nullable VirtualFile startDir) { if (startDir == null) { - return new GitRootDetectInfo(Collections.emptyList(), false, false); + return new VcsRootDetectInfo(Collections.emptyList(), false, false); } final Set roots = scanForRootsInsideDir(startDir); roots.addAll(scanForRootsInContentRoots()); if (roots.contains(startDir)) { - return new GitRootDetectInfo(roots, true, false); + return new VcsRootDetectInfo(roots, true, false); } VirtualFile rootAbove = scanForSingleRootAboveDir(startDir); if (rootAbove != null) { roots.add(rootAbove); - return new GitRootDetectInfo(roots, true, true); + return new VcsRootDetectInfo(roots, true, true); } - return new GitRootDetectInfo(roots, false, false); + return new VcsRootDetectInfo(roots, false, false); } private Set scanForRootsInContentRoots() { diff --git a/plugins/git4idea/src/git4idea/roots/GitRootFinder.java b/plugins/git4idea/src/git4idea/roots/GitRootFinder.java index cd88027a78e5..281e02b49de6 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootFinder.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootFinder.java @@ -29,7 +29,7 @@ public class GitRootFinder implements VcsRootFinder { @NotNull @Override public Collection findRoots(@NotNull VirtualFile root) { - GitRootDetectInfo info = new GitRootDetector(myProject, myPlatformFacade).detect(root); + VcsRootDetectInfo info = new GitRootDetector(myProject, myPlatformFacade).detect(root); Collection roots = info.getRoots(); if (roots.isEmpty()) { return Collections.emptyList(); diff --git a/plugins/git4idea/src/git4idea/roots/GitRootDetectInfo.java b/plugins/git4idea/src/git4idea/roots/VcsRootDetectInfo.java similarity index 95% rename from plugins/git4idea/src/git4idea/roots/GitRootDetectInfo.java rename to plugins/git4idea/src/git4idea/roots/VcsRootDetectInfo.java index 6995de9bcfe6..4194bf533969 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootDetectInfo.java +++ b/plugins/git4idea/src/git4idea/roots/VcsRootDetectInfo.java @@ -26,7 +26,7 @@ import java.util.Collection; * * @author Kirill Likhodedov */ -public class GitRootDetectInfo { +public class VcsRootDetectInfo { private final @NotNull Collection myRoots; private final boolean myFull; @@ -38,7 +38,7 @@ public class GitRootDetectInfo { * @param below Pass true to indicate that the project dir is below Git dir, * i.e. .git is above the project dir, and there is no .git directly under the project dir. */ - GitRootDetectInfo(@NotNull Collection roots, boolean full, boolean below) { + VcsRootDetectInfo(@NotNull Collection roots, boolean full, boolean below) { myRoots = new ArrayList(roots); myFull = full; myBelow = below; diff --git a/plugins/git4idea/tests/git4idea/roots/GitIntegrationEnablerTest.groovy b/plugins/git4idea/tests/git4idea/roots/GitIntegrationEnablerTest.groovy index d026db830754..5d5a2a7ac278 100644 --- a/plugins/git4idea/tests/git4idea/roots/GitIntegrationEnablerTest.groovy +++ b/plugins/git4idea/tests/git4idea/roots/GitIntegrationEnablerTest.groovy @@ -89,7 +89,7 @@ class GitIntegrationEnablerTest extends GitLightTest { notification("Added Git roots: ${path("community")}, ${path("contrib")}")) } - private void doTest(GitRootDetectInfo detectInfo, Map map) { + private void doTest(VcsRootDetectInfo detectInfo, Map map) { // defaults if (!map.vcs_roots) { @@ -117,8 +117,8 @@ class GitIntegrationEnablerTest extends GitLightTest { assertEquals expectedVcsRoots.toSet(), actualRoots.collect() { it.path }.toSet() } - GitRootDetectInfo given(Collection roots, boolean full = true, boolean below = false) { - new GitRootDetectInfo(roots.collect { (VirtualFile)new MockVirtualFile(toAbsolute(it, myProject)) }, full, below) + VcsRootDetectInfo given(Collection roots, boolean full = true, boolean below = false) { + new VcsRootDetectInfo(roots.collect { (VirtualFile)new MockVirtualFile(toAbsolute(it, myProject)) }, full, below) } Map expect(Map map, Notification notification = null, Class dialogClass = null) { diff --git a/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy b/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy index 899ac6dbaf17..c0c90cc9624f 100644 --- a/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy +++ b/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy @@ -190,7 +190,7 @@ class GitRootDetectorTest extends AbstractGitRootTest { assertInfo(expected, detect()) } - void assertInfo(Map expected, GitRootDetectInfo actual) { + void assertInfo(Map expected, VcsRootDetectInfo actual) { assertEquals(expected.empty, actual.empty()) if (expected.full ^ actual.totallyUnderGit()) { fail("The project is unexpectedly ${actual.totallyUnderGit() ? "" : "not "}under Git${roots(actual.roots)}") @@ -213,7 +213,7 @@ class GitRootDetectorTest extends AbstractGitRootTest { files.collect { it.path } } - private GitRootDetectInfo detect() { + private VcsRootDetectInfo detect() { new GitRootDetector(myProject, myPlatformFacade).detect() } From 54d4c7a179a18c6adeaa6a500683865ad57ea9d9 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Thu, 10 Oct 2013 20:12:52 +0400 Subject: [PATCH 2/9] VcsRootDetectInfo moved to platform vcs --- .../intellij/openapi/vcs}/roots/VcsRootDetectInfo.java | 10 +++++----- plugins/git4idea/src/git4idea/GitVcs.java | 2 +- .../src/git4idea/roots/GitIntegrationEnabler.java | 1 + .../git4idea/src/git4idea/roots/GitRootDetector.java | 3 ++- plugins/git4idea/src/git4idea/roots/GitRootFinder.java | 1 + .../git4idea/roots/GitIntegrationEnablerTest.groovy | 1 + .../tests/git4idea/roots/GitRootDetectorTest.groovy | 1 + 7 files changed, 12 insertions(+), 7 deletions(-) rename {plugins/git4idea/src/git4idea => platform/vcs-impl/src/com/intellij/openapi/vcs}/roots/VcsRootDetectInfo.java (89%) diff --git a/plugins/git4idea/src/git4idea/roots/VcsRootDetectInfo.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetectInfo.java similarity index 89% rename from plugins/git4idea/src/git4idea/roots/VcsRootDetectInfo.java rename to platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetectInfo.java index 4194bf533969..43a2bb74f21f 100644 --- a/plugins/git4idea/src/git4idea/roots/VcsRootDetectInfo.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetectInfo.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package git4idea.roots; +package com.intellij.openapi.vcs.roots; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; @@ -38,7 +38,7 @@ public class VcsRootDetectInfo { * @param below Pass true to indicate that the project dir is below Git dir, * i.e. .git is above the project dir, and there is no .git directly under the project dir. */ - VcsRootDetectInfo(@NotNull Collection roots, boolean full, boolean below) { + public VcsRootDetectInfo(@NotNull Collection roots, boolean full, boolean below) { myRoots = new ArrayList(roots); myFull = full; myBelow = below; @@ -48,11 +48,11 @@ public class VcsRootDetectInfo { * @return True if the project is fully under Git. * It is true if .git is directly inside or above the project dir. */ - boolean totallyUnderGit() { + public boolean totallyUnderGit() { return myFull; } - boolean empty() { + public boolean empty() { return myRoots.isEmpty(); } @@ -66,7 +66,7 @@ public class VcsRootDetectInfo { * @return true if the uppermost interesting Git root is above the project dir, * false if all .git directories are immediately under the project dir or deeper. */ - boolean projectIsBelowGit() { + public boolean projectIsBelowGit() { return myBelow; } diff --git a/plugins/git4idea/src/git4idea/GitVcs.java b/plugins/git4idea/src/git4idea/GitVcs.java index 7f2c1c11fd9e..5a618f47b5c7 100644 --- a/plugins/git4idea/src/git4idea/GitVcs.java +++ b/plugins/git4idea/src/git4idea/GitVcs.java @@ -78,7 +78,7 @@ import git4idea.merge.GitMergeProvider; import git4idea.rollback.GitRollbackEnvironment; import git4idea.roots.GitIntegrationEnabler; import git4idea.roots.GitRootChecker; -import git4idea.roots.VcsRootDetectInfo; +import com.intellij.openapi.vcs.roots.VcsRootDetectInfo; import git4idea.roots.GitRootDetector; import git4idea.status.GitChangeProvider; import git4idea.ui.branch.GitBranchWidget; diff --git a/plugins/git4idea/src/git4idea/roots/GitIntegrationEnabler.java b/plugins/git4idea/src/git4idea/roots/GitIntegrationEnabler.java index 69c105e5a08b..0c770fcfb643 100644 --- a/plugins/git4idea/src/git4idea/roots/GitIntegrationEnabler.java +++ b/plugins/git4idea/src/git4idea/roots/GitIntegrationEnabler.java @@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.AbstractVcs; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsDirectoryMapping; +import com.intellij.openapi.vcs.roots.VcsRootDetectInfo; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ui.UIUtil; import git4idea.GitPlatformFacade; diff --git a/plugins/git4idea/src/git4idea/roots/GitRootDetector.java b/plugins/git4idea/src/git4idea/roots/GitRootDetector.java index 3c5708714b2c..8213df4f06cf 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootDetector.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootDetector.java @@ -16,6 +16,7 @@ package git4idea.roots; import com.intellij.openapi.project.Project; +import com.intellij.openapi.vcs.roots.VcsRootDetectInfo; import com.intellij.openapi.vfs.VirtualFile; import git4idea.GitPlatformFacade; import git4idea.GitUtil; @@ -29,7 +30,7 @@ import java.util.Set; /** *

* Scans the file system looking for Git roots, which contain the Project or its parts, - * and returns the information enclosed to the {@link VcsRootDetectInfo}. + * and returns the information enclosed to the {@link com.intellij.openapi.vcs.roots.VcsRootDetectInfo}. * The main part of the information are Git roots which will be proposed to the user to be added as VCS roots. *

*

diff --git a/plugins/git4idea/src/git4idea/roots/GitRootFinder.java b/plugins/git4idea/src/git4idea/roots/GitRootFinder.java index 281e02b49de6..196b2017ecf9 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootFinder.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootFinder.java @@ -3,6 +3,7 @@ package git4idea.roots; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsDirectoryMapping; import com.intellij.openapi.vcs.VcsRootFinder; +import com.intellij.openapi.vcs.roots.VcsRootDetectInfo; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.ContainerUtilRt; import git4idea.GitPlatformFacade; diff --git a/plugins/git4idea/tests/git4idea/roots/GitIntegrationEnablerTest.groovy b/plugins/git4idea/tests/git4idea/roots/GitIntegrationEnablerTest.groovy index 5d5a2a7ac278..54d063b291fe 100644 --- a/plugins/git4idea/tests/git4idea/roots/GitIntegrationEnablerTest.groovy +++ b/plugins/git4idea/tests/git4idea/roots/GitIntegrationEnablerTest.groovy @@ -18,6 +18,7 @@ package git4idea.roots import com.intellij.dvcs.test.MockVirtualFile import com.intellij.notification.Notification import com.intellij.notification.NotificationType +import com.intellij.openapi.vcs.roots.VcsRootDetectInfo import com.intellij.openapi.vfs.VirtualFile import git4idea.test.GitLightTest import git4idea.test.TestNotificator diff --git a/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy b/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy index c0c90cc9624f..34bafa92680a 100644 --- a/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy +++ b/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy @@ -16,6 +16,7 @@ package git4idea.roots import com.intellij.openapi.project.Project +import com.intellij.openapi.vcs.roots.VcsRootDetectInfo import com.intellij.openapi.vfs.VirtualFile import git4idea.test.GitGTestUtil import org.junit.After From 14e9b61662478d70e522d707d1f4fa2806937e0c Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Thu, 10 Oct 2013 20:22:58 +0400 Subject: [PATCH 3/9] GitRootDetector renamed to VcsRootDetector, git dependencies removed from RootDetector for further moving --- plugins/git4idea/src/git4idea/GitVcs.java | 4 +-- .../git4idea/roots/GitRootErrorsFinder.java | 2 +- .../src/git4idea/roots/GitRootFinder.java | 2 +- ...RootDetector.java => VcsRootDetector.java} | 26 +++++++++---------- .../git4idea/roots/GitRootDetectorTest.groovy | 4 +-- 5 files changed, 18 insertions(+), 20 deletions(-) rename plugins/git4idea/src/git4idea/roots/{GitRootDetector.java => VcsRootDetector.java} (81%) diff --git a/plugins/git4idea/src/git4idea/GitVcs.java b/plugins/git4idea/src/git4idea/GitVcs.java index 5a618f47b5c7..154fd62d19cd 100644 --- a/plugins/git4idea/src/git4idea/GitVcs.java +++ b/plugins/git4idea/src/git4idea/GitVcs.java @@ -79,7 +79,7 @@ import git4idea.rollback.GitRollbackEnvironment; import git4idea.roots.GitIntegrationEnabler; import git4idea.roots.GitRootChecker; import com.intellij.openapi.vcs.roots.VcsRootDetectInfo; -import git4idea.roots.GitRootDetector; +import git4idea.roots.VcsRootDetector; import git4idea.status.GitChangeProvider; import git4idea.ui.branch.GitBranchWidget; import git4idea.update.GitUpdateEnvironment; @@ -592,7 +592,7 @@ public class GitVcs extends AbstractVcs { public void enableIntegration() { ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { public void run() { - VcsRootDetectInfo detectInfo = new GitRootDetector(myProject, myPlatformFacade).detect(); + VcsRootDetectInfo detectInfo = new VcsRootDetector(myProject).detect(); new GitIntegrationEnabler(myProject, myGit, myPlatformFacade).enable(detectInfo); } }); diff --git a/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java b/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java index 6a1dc7fe9cc9..01c8b0e553c9 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java @@ -53,7 +53,7 @@ public class GitRootErrorsFinder { @NotNull public Collection find() { List mappings = myVcsManager.getDirectoryMappings(myVcs); - Collection gitRoots = new GitRootDetector(myProject, myPlatformFacade).detect().getRoots(); + Collection gitRoots = new VcsRootDetector(myProject).detect().getRoots(); Collection errors = new ArrayList(); Collection gitPaths = rootsToPaths(gitRoots); diff --git a/plugins/git4idea/src/git4idea/roots/GitRootFinder.java b/plugins/git4idea/src/git4idea/roots/GitRootFinder.java index 196b2017ecf9..a67e63b769f5 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootFinder.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootFinder.java @@ -30,7 +30,7 @@ public class GitRootFinder implements VcsRootFinder { @NotNull @Override public Collection findRoots(@NotNull VirtualFile root) { - VcsRootDetectInfo info = new GitRootDetector(myProject, myPlatformFacade).detect(root); + VcsRootDetectInfo info = new VcsRootDetector(myProject).detect(root); Collection roots = info.getRoots(); if (roots.isEmpty()) { return Collections.emptyList(); diff --git a/plugins/git4idea/src/git4idea/roots/GitRootDetector.java b/plugins/git4idea/src/git4idea/roots/VcsRootDetector.java similarity index 81% rename from plugins/git4idea/src/git4idea/roots/GitRootDetector.java rename to plugins/git4idea/src/git4idea/roots/VcsRootDetector.java index 8213df4f06cf..ea4e4711b7e8 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootDetector.java +++ b/plugins/git4idea/src/git4idea/roots/VcsRootDetector.java @@ -16,10 +16,9 @@ package git4idea.roots; import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.vcs.roots.VcsRootDetectInfo; import com.intellij.openapi.vfs.VirtualFile; -import git4idea.GitPlatformFacade; -import git4idea.GitUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -29,33 +28,33 @@ import java.util.Set; /** *

- * Scans the file system looking for Git roots, which contain the Project or its parts, - * and returns the information enclosed to the {@link com.intellij.openapi.vcs.roots.VcsRootDetectInfo}. - * The main part of the information are Git roots which will be proposed to the user to be added as VCS roots. + * Scans the file system looking for Git roots, which contain the Project or its parts, + * and returns the information enclosed to the {@link com.intellij.openapi.vcs.roots.VcsRootDetectInfo}. + * The main part of the information are Git roots which will be proposed to the user to be added as VCS roots. *

*

- * Linked sources are not scanned. User should add Git roots for them explicitly. + * Linked sources are not scanned. User should add Git roots for them explicitly. *

* * @author Kirill Likhodedov */ -public class GitRootDetector { +public class VcsRootDetector { private static final int MAXIMUM_SCAN_DEPTH = 2; @NotNull private final Project myProject; - @NotNull private final GitPlatformFacade myPlatformFacade; + @NotNull private final ProjectRootManager myProjectManager; - public GitRootDetector(@NotNull Project project, @NotNull GitPlatformFacade platformFacade) { + public VcsRootDetector(@NotNull Project project) { myProject = project; - myPlatformFacade = platformFacade; + myProjectManager = ProjectRootManager.getInstance(project); } @NotNull public VcsRootDetectInfo detect() { return detect(myProject.getBaseDir()); } - + @NotNull public VcsRootDetectInfo detect(@Nullable VirtualFile startDir) { if (startDir == null) { @@ -79,7 +78,7 @@ public class GitRootDetector { private Set scanForRootsInContentRoots() { Set gitRoots = new HashSet(); - VirtualFile[] roots = myPlatformFacade.getProjectRootManager(myProject).getContentRoots(); + VirtualFile[] roots = myProjectManager.getContentRoots(); for (VirtualFile contentRoot : roots) { Set rootsInsideRoot = scanForRootsInsideDir(contentRoot); if (!rootsInsideRoot.contains(contentRoot)) { @@ -135,8 +134,7 @@ public class GitRootDetector { } private static boolean hasGitDir(@NotNull VirtualFile dir) { - VirtualFile gitDir = dir.findChild(GitUtil.DOT_GIT); + VirtualFile gitDir = dir.findChild(".git"); return gitDir != null && gitDir.exists(); } - } diff --git a/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy b/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy index 34bafa92680a..d91655378052 100644 --- a/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy +++ b/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy @@ -165,7 +165,7 @@ class GitRootDetectorTest extends AbstractGitRootTest { /** * Perform test. Map contains actual Git repositories to be created on disk, - * and Git repositories expected to be detected by the GitRootDetector. + * and Git repositories expected to be detected by the VcsRootDetector. * @param map */ private void doTest(Map map) { @@ -215,7 +215,7 @@ class GitRootDetectorTest extends AbstractGitRootTest { } private VcsRootDetectInfo detect() { - new GitRootDetector(myProject, myPlatformFacade).detect() + new VcsRootDetector(myProject).detect() } } \ No newline at end of file From 45ec26a9a312b4c19807b27933cf6fa220249c05 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Thu, 10 Oct 2013 20:25:16 +0400 Subject: [PATCH 4/9] VcsRootDetector moved to Vcs platform directory --- .../src/com/intellij/openapi/vcs}/roots/VcsRootDetector.java | 2 +- plugins/git4idea/src/git4idea/GitVcs.java | 2 +- plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java | 1 + plugins/git4idea/src/git4idea/roots/GitRootFinder.java | 1 + .../git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) rename {plugins/git4idea/src/git4idea => platform/vcs-impl/src/com/intellij/openapi/vcs}/roots/VcsRootDetector.java (99%) diff --git a/plugins/git4idea/src/git4idea/roots/VcsRootDetector.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetector.java similarity index 99% rename from plugins/git4idea/src/git4idea/roots/VcsRootDetector.java rename to platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetector.java index ea4e4711b7e8..c5aae821fac0 100644 --- a/plugins/git4idea/src/git4idea/roots/VcsRootDetector.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetector.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package git4idea.roots; +package com.intellij.openapi.vcs.roots; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectRootManager; diff --git a/plugins/git4idea/src/git4idea/GitVcs.java b/plugins/git4idea/src/git4idea/GitVcs.java index 154fd62d19cd..12996da38d89 100644 --- a/plugins/git4idea/src/git4idea/GitVcs.java +++ b/plugins/git4idea/src/git4idea/GitVcs.java @@ -79,7 +79,7 @@ import git4idea.rollback.GitRollbackEnvironment; import git4idea.roots.GitIntegrationEnabler; import git4idea.roots.GitRootChecker; import com.intellij.openapi.vcs.roots.VcsRootDetectInfo; -import git4idea.roots.VcsRootDetector; +import com.intellij.openapi.vcs.roots.VcsRootDetector; import git4idea.status.GitChangeProvider; import git4idea.ui.branch.GitBranchWidget; import git4idea.update.GitUpdateEnvironment; diff --git a/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java b/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java index 01c8b0e553c9..31b75f923216 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java @@ -21,6 +21,7 @@ import com.intellij.openapi.vcs.AbstractVcs; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsDirectoryMapping; import com.intellij.openapi.vcs.VcsRootError; +import com.intellij.openapi.vcs.roots.VcsRootDetector; import com.intellij.openapi.vfs.VirtualFile; import git4idea.GitPlatformFacade; import git4idea.GitUtil; diff --git a/plugins/git4idea/src/git4idea/roots/GitRootFinder.java b/plugins/git4idea/src/git4idea/roots/GitRootFinder.java index a67e63b769f5..99f7ae277faf 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootFinder.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootFinder.java @@ -4,6 +4,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsDirectoryMapping; import com.intellij.openapi.vcs.VcsRootFinder; import com.intellij.openapi.vcs.roots.VcsRootDetectInfo; +import com.intellij.openapi.vcs.roots.VcsRootDetector; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.ContainerUtilRt; import git4idea.GitPlatformFacade; diff --git a/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy b/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy index d91655378052..500c8fda7db7 100644 --- a/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy +++ b/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy @@ -17,6 +17,7 @@ package git4idea.roots import com.intellij.openapi.project.Project import com.intellij.openapi.vcs.roots.VcsRootDetectInfo +import com.intellij.openapi.vcs.roots.VcsRootDetector import com.intellij.openapi.vfs.VirtualFile import git4idea.test.GitGTestUtil import org.junit.After From 68e50ccc8bde64266aa4fa36948cdf2392a41ff9 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Thu, 10 Oct 2013 20:38:00 +0400 Subject: [PATCH 5/9] GitRootErrorsFinder renamed to VcsRootErrorsFinder, git dependencies removed from RootErrorsFinder for future moving --- .../src/git4idea/roots/GitRootChecker.java | 4 ++-- .../git4idea/roots/GitRootProblemNotifier.java | 4 ++-- ...rrorsFinder.java => VcsRootErrorsFinder.java} | 16 +++++----------- .../roots/GitRootErrorsFinderTest.groovy | 2 +- 4 files changed, 10 insertions(+), 16 deletions(-) rename plugins/git4idea/src/git4idea/roots/{GitRootErrorsFinder.java => VcsRootErrorsFinder.java} (88%) diff --git a/plugins/git4idea/src/git4idea/roots/GitRootChecker.java b/plugins/git4idea/src/git4idea/roots/GitRootChecker.java index b43dbfeeb20d..037b6a0afd7c 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootChecker.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootChecker.java @@ -36,7 +36,7 @@ public class GitRootChecker implements VcsRootChecker { private final boolean myProjectMappingIsInvalid; public GitRootChecker(@NotNull Project project, @NotNull GitPlatformFacade platformFacade) { - myErrors = new GitRootErrorsFinder(project, platformFacade).find(); + myErrors = new VcsRootErrorsFinder(project).find(); myProjectMappingIsInvalid = isProjectMappingInvalid(); } @@ -66,7 +66,7 @@ public class GitRootChecker implements VcsRootChecker { // this information is available in myErrors, // but the method may be called in VcsDirectoryConfigurationPanel after adding a mapping (to highlight errors right away) // in which case ProjectLevelVcsManager#getAllVcsRoots() is not aware of new roots yet, - // while GitRootErrorsFinder relies on the set of roots returned from ProjectLevelVcsManager. + // while VcsRootErrorsFinder relies on the set of roots returned from ProjectLevelVcsManager. if (mapping.isDefaultMapping()) { return myProjectMappingIsInvalid; } diff --git a/plugins/git4idea/src/git4idea/roots/GitRootProblemNotifier.java b/plugins/git4idea/src/git4idea/roots/GitRootProblemNotifier.java index 45f798adad8d..48de52936915 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootProblemNotifier.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootProblemNotifier.java @@ -46,7 +46,7 @@ import static git4idea.GitVcs.MINOR_NOTIFICATION; import static git4idea.Notificator.createNotification; /** - * Searches for Git roots problems via {@link GitRootErrorsFinder} and notifies about them. + * Searches for Git roots problems via {@link VcsRootErrorsFinder} and notifies about them. * * @author Kirill Likhodedov */ @@ -116,7 +116,7 @@ public class GitRootProblemNotifier { @NotNull private Collection scan() { - return new GitRootErrorsFinder(myProject, myPlatformFacade).find(); + return new VcsRootErrorsFinder(myProject).find(); } @SuppressWarnings("StringConcatenationInsideStringBufferAppend") diff --git a/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java b/plugins/git4idea/src/git4idea/roots/VcsRootErrorsFinder.java similarity index 88% rename from plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java rename to plugins/git4idea/src/git4idea/roots/VcsRootErrorsFinder.java index 31b75f923216..d6e225ddeedf 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java +++ b/plugins/git4idea/src/git4idea/roots/VcsRootErrorsFinder.java @@ -23,8 +23,6 @@ import com.intellij.openapi.vcs.VcsDirectoryMapping; import com.intellij.openapi.vcs.VcsRootError; import com.intellij.openapi.vcs.roots.VcsRootDetector; import com.intellij.openapi.vfs.VirtualFile; -import git4idea.GitPlatformFacade; -import git4idea.GitUtil; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -37,23 +35,19 @@ import java.util.List; * * @author Kirill Likhodedov */ -public class GitRootErrorsFinder { +public class VcsRootErrorsFinder { private final @NotNull Project myProject; - private final @NotNull GitPlatformFacade myPlatformFacade; private final @NotNull ProjectLevelVcsManager myVcsManager; - private final AbstractVcs myVcs; - public GitRootErrorsFinder(@NotNull Project project, @NotNull GitPlatformFacade platformFacade) { + public VcsRootErrorsFinder(@NotNull Project project) { myProject = project; - myPlatformFacade = platformFacade; - myVcsManager = myPlatformFacade.getVcsManager(myProject); - myVcs = myPlatformFacade.getVcs(myProject); + myVcsManager = ProjectLevelVcsManager.getInstance(project); } @NotNull public Collection find() { - List mappings = myVcsManager.getDirectoryMappings(myVcs); + List mappings = myVcsManager.getDirectoryMappings(); Collection gitRoots = new VcsRootDetector(myProject).detect().getRoots(); Collection errors = new ArrayList(); @@ -93,7 +87,7 @@ public class GitRootErrorsFinder { } private static boolean hasGitDir(String path) { - File file = new File(path, GitUtil.DOT_GIT); + File file = new File(path, ".git"); return file.exists(); } diff --git a/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy b/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy index bcac61058de2..c9d5fb5c3e0d 100644 --- a/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy +++ b/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy @@ -182,7 +182,7 @@ class GitRootErrorsFinderTest extends AbstractGitRootTest { expected.addAll map.errors.unreg.collect { unreg(it) } expected.addAll map.errors.extra.collect { extra(it) } - Collection actual = new GitRootErrorsFinder(myProject, myPlatformFacade).find() + Collection actual = new VcsRootErrorsFinder(myProject).find() assertEquals expected.toSet(), actual.toSet() } From 7f0888e4e0df5a860ea7bec2d66c909dfc22b16b Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Thu, 10 Oct 2013 20:40:21 +0400 Subject: [PATCH 6/9] VcsRootErrorsFinder moved to vcs platform directory --- .../com/intellij/openapi/vcs}/roots/VcsRootErrorsFinder.java | 2 +- plugins/git4idea/src/git4idea/roots/GitRootChecker.java | 1 + .../git4idea/src/git4idea/roots/GitRootProblemNotifier.java | 3 ++- .../tests/git4idea/roots/GitRootErrorsFinderTest.groovy | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) rename {plugins/git4idea/src/git4idea => platform/vcs-impl/src/com/intellij/openapi/vcs}/roots/VcsRootErrorsFinder.java (99%) diff --git a/plugins/git4idea/src/git4idea/roots/VcsRootErrorsFinder.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java similarity index 99% rename from plugins/git4idea/src/git4idea/roots/VcsRootErrorsFinder.java rename to platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java index d6e225ddeedf..016d1adf8ff6 100644 --- a/plugins/git4idea/src/git4idea/roots/VcsRootErrorsFinder.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package git4idea.roots; +package com.intellij.openapi.vcs.roots; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; diff --git a/plugins/git4idea/src/git4idea/roots/GitRootChecker.java b/plugins/git4idea/src/git4idea/roots/GitRootChecker.java index 037b6a0afd7c..47a221bbe1d8 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootChecker.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootChecker.java @@ -19,6 +19,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsDirectoryMapping; import com.intellij.openapi.vcs.VcsRootChecker; import com.intellij.openapi.vcs.VcsRootError; +import com.intellij.openapi.vcs.roots.VcsRootErrorsFinder; import git4idea.GitPlatformFacade; import git4idea.GitUtil; import org.jetbrains.annotations.NotNull; diff --git a/plugins/git4idea/src/git4idea/roots/GitRootProblemNotifier.java b/plugins/git4idea/src/git4idea/roots/GitRootProblemNotifier.java index 48de52936915..93cf2fa8cbb0 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootProblemNotifier.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootProblemNotifier.java @@ -29,6 +29,7 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.VcsConfiguration; import com.intellij.openapi.vcs.VcsDirectoryMapping; import com.intellij.openapi.vcs.VcsRootError; +import com.intellij.openapi.vcs.roots.VcsRootErrorsFinder; import com.intellij.util.Function; import git4idea.GitPlatformFacade; import org.jetbrains.annotations.NotNull; @@ -46,7 +47,7 @@ import static git4idea.GitVcs.MINOR_NOTIFICATION; import static git4idea.Notificator.createNotification; /** - * Searches for Git roots problems via {@link VcsRootErrorsFinder} and notifies about them. + * Searches for Git roots problems via {@link com.intellij.openapi.vcs.roots.VcsRootErrorsFinder} and notifies about them. * * @author Kirill Likhodedov */ diff --git a/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy b/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy index c9d5fb5c3e0d..8fbd2a4a8691 100644 --- a/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy +++ b/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy @@ -17,6 +17,7 @@ package git4idea.roots import com.intellij.openapi.vcs.VcsDirectoryMapping import com.intellij.openapi.vcs.VcsRootError +import com.intellij.openapi.vcs.roots.VcsRootErrorsFinder import git4idea.test.GitMockVcsManager import org.junit.After import org.junit.Before From f519dd3ae737c9912debfeddf0e2998b48379b45 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Thu, 10 Oct 2013 20:40:52 +0400 Subject: [PATCH 7/9] optimize imports --- .../com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java index 016d1adf8ff6..73c1b43f583e 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java @@ -17,11 +17,9 @@ package com.intellij.openapi.vcs.roots; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vcs.AbstractVcs; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsDirectoryMapping; import com.intellij.openapi.vcs.VcsRootError; -import com.intellij.openapi.vcs.roots.VcsRootDetector; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; @@ -115,5 +113,4 @@ public class VcsRootErrorsFinder { } return paths; } - } From e4180e6ee6cc914447bd3d387de7c74bdc7de41f Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Thu, 10 Oct 2013 21:11:22 +0400 Subject: [PATCH 8/9] Root Checker and Root Problem Notifier *Extension Point for rootChecker created; *api changed and moved form git directory to common platform; *platform facade remove from root subdirectory exclude integration enabler; * root scanner started in ProjectLevelVcsManager; *vcs name stored in VcsRootError; *java tests created instead of groovy test; *UsefulTestCase class used as a base class for test instead of light test; *platform facade removed (except IntegrationEnablerTest); *IntegrationsEnabler test switched off; *check that chosen vcs in mapping root is supported for this kind of root; *filter git roots in integration enabler *do not start scanner in unit test mode or if there are no root checkers in --- .../src/META-INF/VcsExtensionPoints.xml | 2 + .../com/intellij/openapi/vcs/AbstractVcs.java | 5 - .../intellij/openapi/vcs/VcsRootChecker.java | 32 ++- .../intellij/openapi/vcs/VcsRootError.java | 13 +- .../VcsDirectoryConfigurationPanel.java | 56 ++-- .../vcs/impl/ProjectLevelVcsManagerImpl.java | 8 + .../openapi/vcs/roots/VcsRootDetectInfo.java | 55 ++-- .../openapi/vcs/roots/VcsRootDetector.java | 118 ++++---- .../vcs/roots/VcsRootErrorsFinder.java | 103 +++---- .../vcs/roots/VcsRootProblemNotifier.java | 96 +++---- .../openapi/vcs/roots/VcsRootScanner.java | 31 +- plugins/git4idea/src/META-INF/plugin.xml | 3 +- plugins/git4idea/src/git4idea/GitVcs.java | 10 +- .../git4idea/repo/GitRepositoryManager.java | 14 +- .../git4idea/roots/GitIntegrationEnabler.java | 23 +- .../src/git4idea/roots/GitRootChecker.java | 53 +--- .../src/git4idea/roots/GitRootFinder.java | 17 +- .../git4idea/roots/AbstractGitRootTest.groovy | 107 ------- .../roots/GitIntegrationEnablerTest.groovy | 9 +- .../tests/git4idea/roots/GitPlatformTest.java | 209 ++++++++++++++ .../git4idea/roots/GitRootDetectorTest.groovy | 222 -------------- .../git4idea/roots/GitRootDetectorTest.java | 222 ++++++++++++++ .../roots/GitRootErrorsFinderTest.groovy | 211 -------------- .../roots/GitRootErrorsFinderTest.java | 270 ++++++++++++++++++ plugins/hg4idea/src/META-INF/plugin.xml | 1 + .../org/zmlx/hg4idea/roots/HgRootChecker.java | 45 +++ 26 files changed, 1061 insertions(+), 874 deletions(-) rename plugins/git4idea/src/git4idea/roots/GitRootProblemNotifier.java => platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootProblemNotifier.java (61%) rename plugins/git4idea/src/git4idea/roots/GitRootScanner.java => platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootScanner.java (80%) delete mode 100644 plugins/git4idea/tests/git4idea/roots/AbstractGitRootTest.groovy create mode 100644 plugins/git4idea/tests/git4idea/roots/GitPlatformTest.java delete mode 100644 plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy create mode 100644 plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.java delete mode 100644 plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy create mode 100644 plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.java create mode 100644 plugins/hg4idea/src/org/zmlx/hg4idea/roots/HgRootChecker.java diff --git a/platform/platform-resources/src/META-INF/VcsExtensionPoints.xml b/platform/platform-resources/src/META-INF/VcsExtensionPoints.xml index 274036923c65..defeb7de5f76 100644 --- a/platform/platform-resources/src/META-INF/VcsExtensionPoints.xml +++ b/platform/platform-resources/src/META-INF/VcsExtensionPoints.xml @@ -2,6 +2,8 @@ + extends S return null; } - @Nullable - public VcsRootChecker getRootChecker() { - return null; - } - @Nullable public VcsRootSettings createEmptyVcsRootSettings() { return null; diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsRootChecker.java b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsRootChecker.java index b268b6dafaec..2f8231fb1f64 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsRootChecker.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsRootChecker.java @@ -15,9 +15,10 @@ */ package com.intellij.openapi.vcs; +import com.intellij.openapi.extensions.ExtensionPointName; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; - -import java.util.Collection; +import org.jetbrains.annotations.Nullable; /** * Checks VCS roots, revealing invalid roots (registered in the settings, but not related to real VCS roots on disk) @@ -25,18 +26,31 @@ import java.util.Collection; * * @author Kirill Likhodedov */ -public interface VcsRootChecker { +public abstract class VcsRootChecker { + + @NonNls public static final ExtensionPointName EXTENSION_POINT_NAME = + new ExtensionPointName("com.intellij.vcsRootChecker"); /** - * @return Paths to VCS roots which are not registered in the Settings | Version Control. + * @param path path to check if it is vcs root directory + * @return true if it is vcs root */ - @NotNull - Collection getUnregisteredRoots(); + public boolean isRoot(@NotNull String path) { + return false; + } /** + * @return - return vcs for current checker + */ + public abstract VcsKey getSupportedVcs(); + + /** + * Check if the "dot" directory changed during scan * - * @param directory root to be checked. - * @return true if the given directory is not a VCS root. + * @param path - path to check + * @return true if it is a DOT_DIR */ - boolean isInvalidMapping(@NotNull VcsDirectoryMapping mapping); + public boolean isVcsDir(@Nullable String path) { + return false; + } } diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsRootError.java b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsRootError.java index 5fde942a9b12..ada11256da9a 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsRootError.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsRootError.java @@ -20,24 +20,24 @@ import org.jetbrains.annotations.NotNull; /** * Incorrect VCS root definition: either an unregistered, or an incorrectly registered VCS root. * - * @see VcsRootChecker - * @see AbstractVcs#getRootChecker - * * @author Kirill Likhodedov + * @see VcsRootChecker */ public class VcsRootError { private final @NotNull Type myType; private final @NotNull String myMapping; + private final @NotNull VcsKey myVcsKey; public enum Type { EXTRA_MAPPING, UNREGISTERED_ROOT } - public VcsRootError(@NotNull Type type, @NotNull String mapping) { + public VcsRootError(@NotNull Type type, @NotNull String mapping, @NotNull String key) { myType = type; myMapping = mapping; + myVcsKey = new VcsKey(key); } @NotNull @@ -50,6 +50,11 @@ public class VcsRootError { return myMapping; } + @NotNull + public VcsKey getVcsKey() { + return myVcsKey; + } + @Override public String toString() { return String.format("VcsRootError{%s - %s}", myType, myMapping); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsDirectoryConfigurationPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsDirectoryConfigurationPanel.java index 2ed939836dcc..922768298355 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsDirectoryConfigurationPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsDirectoryConfigurationPanel.java @@ -17,6 +17,7 @@ package com.intellij.openapi.vcs.configurable; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.project.Project; @@ -25,6 +26,7 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.*; import com.intellij.openapi.vcs.impl.DefaultVcsRootPolicy; import com.intellij.openapi.vcs.impl.VcsDescriptor; +import com.intellij.openapi.vcs.roots.VcsRootErrorsFinder; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.*; import com.intellij.ui.components.JBLabel; @@ -125,7 +127,8 @@ public class VcsDirectoryConfigurationPanel extends JPanel implements Configurab private boolean mappingIsError(VcsDirectoryMapping mapping) { String vcs = mapping.getVcs(); VcsRootChecker checker = myCheckers.get(vcs); - return checker != null && checker.isInvalidMapping(mapping); + return checker != null && + (mapping.isDefaultMapping() ? !checker.isRoot(myProject.getBasePath()) : !checker.isRoot(mapping.getDirectory())); } } @@ -263,16 +266,14 @@ public class VcsDirectoryConfigurationPanel extends JPanel implements Configurab private void updateRootCheckers() { myCheckers.clear(); - for (VcsDescriptor descriptor : myVcsManager.getAllVcss()) { - String name = descriptor.getName(); - AbstractVcs vcs = myVcsManager.findVcsByName(name); + VcsRootChecker[] checkers = Extensions.getExtensions(VcsRootChecker.EXTENSION_POINT_NAME); + for (VcsRootChecker checker : checkers) { + VcsKey key = checker.getSupportedVcs(); + AbstractVcs vcs = myVcsManager.findVcsByName(key.getName()); if (vcs == null) { continue; } - VcsRootChecker checker = vcs.getRootChecker(); - if (checker != null) { - myCheckers.put(name, checker); - } + myCheckers.put(key.getName(), checker); } } @@ -416,27 +417,28 @@ public class VcsDirectoryConfigurationPanel extends JPanel implements Configurab final JComponent errorPanel = Box.createVerticalBox(); final JBScrollPane pane = new JBScrollPane(errorPanel); - for (Map.Entry entry : myCheckers.entrySet()) { - VcsRootChecker checker = entry.getValue(); - for (final String root : checker.getUnregisteredRoots()) { - final String vcs = entry.getKey(); - String title = "Unregistered " + vcs + " root: " + FileUtil.toSystemDependentName(root); - final VcsRootErrorLabel vcsRootErrorLabel = new VcsRootErrorLabel(title); - vcsRootErrorLabel.setAddRootLinkHandler(new Runnable() { - @Override - public void run() { - addMapping(new VcsDirectoryMapping(root, vcs)); - errorPanel.remove(vcsRootErrorLabel); - if (errorPanel.getComponentCount() == 0) { - pane.setVisible(false); - } - pane.setMinimumSize(new Dimension(-1, calcMinHeight(errorPanel, DEFAULT_HEIGHT))); - validate(); + Collection myErrors = VcsRootErrorsFinder.getInstance(myProject).find(); + for (final VcsRootError root : myErrors) { + final VcsKey vcsKey = root.getVcsKey(); + final VcsDescriptor vcsDescriptor = myAllVcss.get(vcsKey.getName()); + String displayVcsName = vcsDescriptor.getDisplayName(); + String title = "Unregistered " + displayVcsName + " root: " + FileUtil.toSystemDependentName(root.getMapping()); + final VcsRootErrorLabel vcsRootErrorLabel = new VcsRootErrorLabel(title); + vcsRootErrorLabel.setAddRootLinkHandler(new Runnable() { + @Override + public void run() { + addMapping(new VcsDirectoryMapping(root.getMapping(), vcsKey.getName())); + errorPanel.remove(vcsRootErrorLabel); + if (errorPanel.getComponentCount() == 0) { + pane.setVisible(false); } - }); - errorPanel.add(vcsRootErrorLabel); - } + pane.setMinimumSize(new Dimension(-1, calcMinHeight(errorPanel, DEFAULT_HEIGHT))); + validate(); + } + }); + errorPanel.add(vcsRootErrorLabel); } + if (errorPanel.getComponentCount() == 0) { pane.setVisible(false); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java index 08414150336f..87d7faab4523 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java @@ -26,6 +26,7 @@ import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.EditorSettings; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.editor.markup.TextAttributes; +import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.DumbAwareRunnable; import com.intellij.openapi.project.Project; @@ -44,6 +45,7 @@ import com.intellij.openapi.vcs.checkout.CompositeCheckoutListener; import com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx; import com.intellij.openapi.vcs.history.VcsHistoryCache; import com.intellij.openapi.vcs.impl.projectlevelman.*; +import com.intellij.openapi.vcs.roots.VcsRootScanner; import com.intellij.openapi.vcs.update.ActionInfo; import com.intellij.openapi.vcs.update.UpdateInfoTree; import com.intellij.openapi.vcs.update.UpdatedFiles; @@ -240,6 +242,12 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme else { myContentManager = ContentFactory.SERVICE.getInstance().createContentManager(true, myProject); } + if (!ApplicationManager.getApplication().isUnitTestMode()) { + VcsRootChecker[] checkers = Extensions.getExtensions(VcsRootChecker.EXTENSION_POINT_NAME); + if (checkers.length != 0) { + VcsRootScanner.start(myProject, checkers); + } + } } }); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetectInfo.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetectInfo.java index 43a2bb74f21f..64e327781cc8 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetectInfo.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetectInfo.java @@ -1,54 +1,37 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package com.intellij.openapi.vcs.roots; -import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vcs.VcsRoot; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collection; /** - * The result of root detection. - * - * @author Kirill Likhodedov + * @author Nadya Zabrodina */ public class VcsRootDetectInfo { - private final @NotNull Collection myRoots; + private final @NotNull Collection myRoots; private final boolean myFull; private final boolean myBelow; /** - * @param roots Git roots important for the project. - * @param full Pass true to indicate that the project is fully under Git. - * @param below Pass true to indicate that the project dir is below Git dir, - * i.e. .git is above the project dir, and there is no .git directly under the project dir. + * @param roots Vcs roots important for the project. + * @param full Pass true to indicate that the project is fully under Vcs. + * @param below Pass true to indicate that the project dir is below Vcs dir, + * i.e. .git is above the project dir, and there is no DOT dir directly under the project dir. */ - public VcsRootDetectInfo(@NotNull Collection roots, boolean full, boolean below) { - myRoots = new ArrayList(roots); + public VcsRootDetectInfo(@NotNull Collection roots, boolean full, boolean below) { + myRoots = new ArrayList(roots); myFull = full; myBelow = below; } /** - * @return True if the project is fully under Git. - * It is true if .git is directly inside or above the project dir. + * @return True if the project is fully under Vcs. + * It is true if f.e. .git is directly inside or above the project dir. */ - public boolean totallyUnderGit() { + public boolean totallyUnderVcs() { return myFull; } @@ -57,17 +40,17 @@ public class VcsRootDetectInfo { } @NotNull - public Collection getRoots() { - return new ArrayList(myRoots); + public Collection getRoots() { + return new ArrayList(myRoots); } /** - * Below implies totally under Git. - * @return true if the uppermost interesting Git root is above the project dir, - * false if all .git directories are immediately under the project dir or deeper. + * Below implies totally under Vcs. + * + * @return true if the uppermost interesting Vcs root is above the project dir, + * false if all vcs internal directories are immediately under the project dir or deeper. */ - public boolean projectIsBelowGit() { + public boolean projectIsBelowVcs() { return myBelow; } - } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetector.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetector.java index c5aae821fac0..1fb36896275f 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetector.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetector.java @@ -1,53 +1,32 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package com.intellij.openapi.vcs.roots; +import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectRootManager; -import com.intellij.openapi.vcs.roots.VcsRootDetectInfo; +import com.intellij.openapi.vcs.AbstractVcs; +import com.intellij.openapi.vcs.ProjectLevelVcsManager; +import com.intellij.openapi.vcs.VcsRoot; +import com.intellij.openapi.vcs.VcsRootChecker; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; +import java.util.*; /** - *

- * Scans the file system looking for Git roots, which contain the Project or its parts, - * and returns the information enclosed to the {@link com.intellij.openapi.vcs.roots.VcsRootDetectInfo}. - * The main part of the information are Git roots which will be proposed to the user to be added as VCS roots. - *

- *

- * Linked sources are not scanned. User should add Git roots for them explicitly. - *

- * - * @author Kirill Likhodedov + * @author Nadya Zabrodina */ public class VcsRootDetector { - private static final int MAXIMUM_SCAN_DEPTH = 2; @NotNull private final Project myProject; @NotNull private final ProjectRootManager myProjectManager; + @NotNull private final ProjectLevelVcsManager myVcsManager; public VcsRootDetector(@NotNull Project project) { myProject = project; myProjectManager = ProjectRootManager.getInstance(project); + myVcsManager = ProjectLevelVcsManager.getInstance(project); } @NotNull @@ -58,43 +37,49 @@ public class VcsRootDetector { @NotNull public VcsRootDetectInfo detect(@Nullable VirtualFile startDir) { if (startDir == null) { - return new VcsRootDetectInfo(Collections.emptyList(), false, false); + return new VcsRootDetectInfo(Collections.emptyList(), false, false); } - final Set roots = scanForRootsInsideDir(startDir); + final Set roots = scanForRootsInsideDir(startDir); roots.addAll(scanForRootsInContentRoots()); - - if (roots.contains(startDir)) { - return new VcsRootDetectInfo(roots, true, false); + for (VcsRoot root : roots) { + if (startDir.equals(root.getPath())) { + return new VcsRootDetectInfo(roots, true, false); + } } - - VirtualFile rootAbove = scanForSingleRootAboveDir(startDir); - if (rootAbove != null) { - roots.add(rootAbove); + List rootsAbove = scanForSingleRootAboveDir(startDir); + if (!rootsAbove.isEmpty()) { + roots.addAll(rootsAbove); return new VcsRootDetectInfo(roots, true, true); } return new VcsRootDetectInfo(roots, false, false); } - private Set scanForRootsInContentRoots() { - Set gitRoots = new HashSet(); + @NotNull + private Set scanForRootsInContentRoots() { + Set gitRoots = new HashSet(); VirtualFile[] roots = myProjectManager.getContentRoots(); for (VirtualFile contentRoot : roots) { - Set rootsInsideRoot = scanForRootsInsideDir(contentRoot); - if (!rootsInsideRoot.contains(contentRoot)) { - VirtualFile rootAbove = scanForSingleRootAboveDir(contentRoot); - if (rootAbove != null) { - rootsInsideRoot.add(rootAbove); + + Set rootsInsideRoot = scanForRootsInsideDir(contentRoot); + boolean shouldScanAbove = true; + for (VcsRoot root : rootsInsideRoot) { + if (contentRoot.equals(root.getPath())) { + shouldScanAbove = false; } } + if (shouldScanAbove) { + List rootsAbove = scanForSingleRootAboveDir(contentRoot); + rootsInsideRoot.addAll(rootsAbove); + } gitRoots.addAll(rootsInsideRoot); } return gitRoots; } @NotNull - private Set scanForRootsInsideDir(@NotNull final VirtualFile dir, final int depth) { - final Set roots = new HashSet(); + private Set scanForRootsInsideDir(@NotNull final VirtualFile dir, final int depth) { + final Set roots = new HashSet(); if (depth > MAXIMUM_SCAN_DEPTH) { // performance optimization via limitation: don't scan deep though the whole VFS, 2 levels under a content root is enough return roots; @@ -103,8 +88,9 @@ public class VcsRootDetector { if (myProject.isDisposed() || !dir.isDirectory()) { return roots; } - if (hasGitDir(dir)) { - roots.add(dir); + List vcsList = getVcsListFor(dir); + for (AbstractVcs vcs : vcsList) { + roots.add(new VcsRoot(vcs, dir)); } for (VirtualFile child : dir.getChildren()) { roots.addAll(scanForRootsInsideDir(child, depth + 1)); @@ -113,28 +99,40 @@ public class VcsRootDetector { } @NotNull - private Set scanForRootsInsideDir(@NotNull VirtualFile dir) { + private Set scanForRootsInsideDir(@NotNull VirtualFile dir) { return scanForRootsInsideDir(dir, 0); } - @Nullable - private VirtualFile scanForSingleRootAboveDir(@NotNull final VirtualFile dir) { + @NotNull + private List scanForSingleRootAboveDir(@NotNull final VirtualFile dir) { + List roots = new ArrayList(); if (myProject.isDisposed()) { - return null; + return roots; } VirtualFile par = dir.getParent(); while (par != null) { - if (hasGitDir(par)) { - return par; + List vcsList = getVcsListFor(par); + for (AbstractVcs vcs : vcsList) { + roots.add(new VcsRoot(vcs, par)); + } + if (!roots.isEmpty()) { + return roots; } par = par.getParent(); } - return null; + return roots; } - private static boolean hasGitDir(@NotNull VirtualFile dir) { - VirtualFile gitDir = dir.findChild(".git"); - return gitDir != null && gitDir.exists(); + @NotNull + private List getVcsListFor(@NotNull VirtualFile dir) { + VcsRootChecker[] checkers = Extensions.getExtensions(VcsRootChecker.EXTENSION_POINT_NAME); + List vcsList = new ArrayList(); + for (VcsRootChecker checker : checkers) { + if (checker.isRoot(dir.getPath())) { + vcsList.add(myVcsManager.findVcsByName(checker.getSupportedVcs().getName())); + } + } + return vcsList; } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java index 73c1b43f583e..9a5aa900bf40 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java @@ -1,40 +1,24 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package com.intellij.openapi.vcs.roots; +import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vcs.ProjectLevelVcsManager; -import com.intellij.openapi.vcs.VcsDirectoryMapping; -import com.intellij.openapi.vcs.VcsRootError; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vcs.*; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; -import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.List; /** - * Detects actual Git roots and compares them to the ones registered in Settings | Version Control. - * - * @author Kirill Likhodedov + * @author Nadya Zabrodina */ public class VcsRootErrorsFinder { - private final @NotNull Project myProject; private final @NotNull ProjectLevelVcsManager myVcsManager; @@ -46,61 +30,67 @@ public class VcsRootErrorsFinder { @NotNull public Collection find() { List mappings = myVcsManager.getDirectoryMappings(); - Collection gitRoots = new VcsRootDetector(myProject).detect().getRoots(); + Collection vcsRoots = new VcsRootDetector(myProject).detect().getRoots(); Collection errors = new ArrayList(); - Collection gitPaths = rootsToPaths(gitRoots); - errors.addAll(findExtraMappings(mappings, gitPaths)); - errors.addAll(findUnregisteredRoots(mappings, gitPaths)); + errors.addAll(findExtraMappings(mappings, vcsRoots.isEmpty())); + errors.addAll(findUnregisteredRoots(mappings, vcsRoots)); return errors; } - private Collection findUnregisteredRoots(List mappings, Collection gitPaths) { + @NotNull + private Collection findUnregisteredRoots(@NotNull List mappings, + @NotNull Collection vcsRoots) { Collection errors = new ArrayList(); - List mappedPaths = mappingsToPaths(mappings); - for (String gitPath : gitPaths) { - if (!mappedPaths.contains(gitPath)) { - errors.add(new VcsRootError(VcsRootError.Type.UNREGISTERED_ROOT, gitPath)); + List mappedPaths = mappingsToPathsWithSelectedVcs(mappings); + for (VcsRoot root : vcsRoots) { + VirtualFile virtualFileFromRoot = root.getPath(); + if (virtualFileFromRoot == null) { + continue; + } + String vcsPath = virtualFileFromRoot.getPath(); + if (!mappedPaths.contains(vcsPath) && root.getVcs() != null) { + errors.add(new VcsRootError(VcsRootError.Type.UNREGISTERED_ROOT, vcsPath, root.getVcs().getName())); } } return errors; } - private static Collection findExtraMappings(List mappings, Collection gitPaths) { + @NotNull + private Collection findExtraMappings(@NotNull List mappings, boolean isEmptyVcsRoots) { Collection errors = new ArrayList(); for (VcsDirectoryMapping mapping : mappings) { if (mapping.isDefaultMapping()) { - if (gitPaths.isEmpty()) { - errors.add(new VcsRootError(VcsRootError.Type.EXTRA_MAPPING, VcsDirectoryMapping.PROJECT_CONSTANT)); + if (isEmptyVcsRoots && !StringUtil.isEmptyOrSpaces(mapping.getVcs())) { + errors.add(new VcsRootError(VcsRootError.Type.EXTRA_MAPPING, VcsDirectoryMapping.PROJECT_CONSTANT, mapping.getVcs())); } } else { String mappedPath = mapping.systemIndependentPath(); - if (!gitPaths.contains(mappedPath) && !hasGitDir(mappedPath)) { - errors.add(new VcsRootError(VcsRootError.Type.EXTRA_MAPPING, mappedPath)); + if (!isRoot(mapping)) { + errors.add(new VcsRootError(VcsRootError.Type.EXTRA_MAPPING, mappedPath, mapping.getVcs())); } } } return errors; } - private static boolean hasGitDir(String path) { - File file = new File(path, ".git"); - return file.exists(); - } - @NotNull - private static Collection rootsToPaths(@NotNull Collection gitRoots) { - Collection gitPaths = new ArrayList(gitRoots.size()); - for (VirtualFile root : gitRoots) { - gitPaths.add(root.getPath()); - } - return gitPaths; + public static Collection vcsRootsToVirtualFiles(@NotNull Collection vcsRoots) { + return ContainerUtil.map(vcsRoots, new Function() { + @Override + public VirtualFile fun(VcsRoot root) { + return root.getPath(); + } + }); } - private List mappingsToPaths(List mappings) { + private List mappingsToPathsWithSelectedVcs(@NotNull List mappings) { List paths = new ArrayList(); for (VcsDirectoryMapping mapping : mappings) { + if (StringUtil.isEmptyOrSpaces(mapping.getVcs())) { + continue; + } if (!mapping.isDefaultMapping()) { paths.add(mapping.systemIndependentPath()); } @@ -113,4 +103,19 @@ public class VcsRootErrorsFinder { } return paths; } + + public static VcsRootErrorsFinder getInstance(Project project) { + return new VcsRootErrorsFinder(project); + } + + private boolean isRoot(@NotNull final VcsDirectoryMapping mapping) { + VcsRootChecker[] checkers = Extensions.getExtensions(VcsRootChecker.EXTENSION_POINT_NAME); + final String pathToCheck = mapping.isDefaultMapping() ? myProject.getBasePath() : mapping.getDirectory(); + return ContainerUtil.find(checkers, new Condition() { + @Override + public boolean value(VcsRootChecker checker) { + return checker.getSupportedVcs().getName().equals(mapping.getVcs()) && checker.isRoot(pathToCheck); + } + }) != null; + } } diff --git a/plugins/git4idea/src/git4idea/roots/GitRootProblemNotifier.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootProblemNotifier.java similarity index 61% rename from plugins/git4idea/src/git4idea/roots/GitRootProblemNotifier.java rename to platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootProblemNotifier.java index 93cf2fa8cbb0..fac08321a25a 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootProblemNotifier.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootProblemNotifier.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,15 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package git4idea.roots; +package com.intellij.openapi.vcs.roots; import com.intellij.idea.ActionsBundle; -import com.intellij.notification.Notification; -import com.intellij.notification.NotificationGroup; -import com.intellij.notification.NotificationListener; -import com.intellij.notification.NotificationType; +import com.intellij.notification.*; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; @@ -29,9 +25,7 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.VcsConfiguration; import com.intellij.openapi.vcs.VcsDirectoryMapping; import com.intellij.openapi.vcs.VcsRootError; -import com.intellij.openapi.vcs.roots.VcsRootErrorsFinder; import com.intellij.util.Function; -import git4idea.GitPlatformFacade; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -42,33 +36,31 @@ import java.util.Collection; import static com.intellij.notification.NotificationType.ERROR; import static com.intellij.notification.NotificationType.INFORMATION; import static com.intellij.openapi.util.text.StringUtil.pluralize; -import static git4idea.GitVcs.IMPORTANT_ERROR_NOTIFICATION; -import static git4idea.GitVcs.MINOR_NOTIFICATION; -import static git4idea.Notificator.createNotification; /** - * Searches for Git roots problems via {@link com.intellij.openapi.vcs.roots.VcsRootErrorsFinder} and notifies about them. + * Searches for Vcs roots problems via {@link VcsRootErrorsFinder} and notifies about them. * - * @author Kirill Likhodedov + * @author Nadya Zabrodina */ -public class GitRootProblemNotifier { +public class VcsRootProblemNotifier { private final @NotNull Project myProject; - private final @NotNull GitPlatformFacade myPlatformFacade; private final @NotNull VcsConfiguration mySettings; private @Nullable Notification myNotification; private final @NotNull Object NOTIFICATION_LOCK = new Object(); - public static GitRootProblemNotifier getInstance(@NotNull Project project) { - return ServiceManager.getService(project, GitRootProblemNotifier.class); + public static final NotificationGroup IMPORTANT_ERROR_NOTIFICATION = new NotificationGroup( + "Vcs Important Messages", NotificationDisplayType.STICKY_BALLOON, true); + public static final NotificationGroup MINOR_NOTIFICATION = new NotificationGroup( + "Vcs Minor Notifications", NotificationDisplayType.BALLOON, true); + + public static VcsRootProblemNotifier getInstance(@NotNull Project project) { + return new VcsRootProblemNotifier(project); } - // registered as a project service - @SuppressWarnings("UnusedDeclaration") - private GitRootProblemNotifier(@NotNull Project project, @NotNull GitPlatformFacade platformFacade) { + private VcsRootProblemNotifier(@NotNull Project project) { myProject = project; - myPlatformFacade = platformFacade; mySettings = VcsConfiguration.getInstance(myProject); } @@ -85,8 +77,8 @@ public class GitRootProblemNotifier { return; } - Collection unregisteredRoots = getUnregisteredRoots(errors); - Collection invalidRoots = getInvalidRoots(errors); + Collection unregisteredRoots = getUnregisteredRoots(errors); + Collection invalidRoots = getInvalidRoots(errors); String title = makeTitle(unregisteredRoots, invalidRoots); String description = makeDescription(unregisteredRoots, invalidRoots); @@ -95,9 +87,9 @@ public class GitRootProblemNotifier { expireNotification(); NotificationGroup notificationGroup = invalidRoots.isEmpty() ? MINOR_NOTIFICATION : IMPORTANT_ERROR_NOTIFICATION; NotificationType notificationType = invalidRoots.isEmpty() ? INFORMATION : ERROR; - myNotification = createNotification(notificationGroup, title, description, notificationType, - new MyNotificationListener(myProject, mySettings)); - myPlatformFacade.getNotificator(myProject).notify(myNotification); + myNotification = notificationGroup.createNotification(title, description, notificationType, + new MyNotificationListener(myProject, mySettings)); + myNotification.notify(myProject); } } @@ -121,25 +113,29 @@ public class GitRootProblemNotifier { } @SuppressWarnings("StringConcatenationInsideStringBufferAppend") - private static String makeDescription(@NotNull Collection unregisteredRoots, @NotNull Collection invalidRoots) { - Function rootToDisplayableString = new Function() { + @NotNull + private static String makeDescription(@NotNull Collection unregisteredRoots, + @NotNull Collection invalidRoots) { + Function rootToDisplayableString = new Function() { @Override - public String fun(String path) { - if (path.equals(VcsDirectoryMapping.PROJECT_CONSTANT)) { - return StringUtil.escapeXml(path); + public String fun(VcsRootError rootError) { + if (rootError.getMapping().equals(VcsDirectoryMapping.PROJECT_CONSTANT)) { + return StringUtil.escapeXml(rootError.getMapping()); } - return FileUtil.toSystemDependentName(path); + return FileUtil.toSystemDependentName(rootError.getMapping()); } }; StringBuilder description = new StringBuilder(); if (!invalidRoots.isEmpty()) { if (invalidRoots.size() == 1) { - description.append("The directory " + rootToDisplayableString.fun(invalidRoots.iterator().next()) + " is registered as a Git root, " + - "but no Git repositories were found there."); + VcsRootError rootError = invalidRoots.iterator().next(); + description + .append("The directory " + rootToDisplayableString.fun(rootError) + " is registered as a " + rootError.getVcsKey() + " root, " + + "but no " + rootError.getVcsKey() + " repositories were found there."); } else { - description.append("The following directories are registered as Git roots, but they are not:
" + + description.append("The following directories are registered as Vcs roots, but they are not:
" + StringUtil.join(invalidRoots, rootToDisplayableString, ", ")); } description.append("
"); @@ -147,11 +143,13 @@ public class GitRootProblemNotifier { if (!unregisteredRoots.isEmpty()) { if (unregisteredRoots.size() == 1) { - description.append("The directory " + rootToDisplayableString.fun(unregisteredRoots.iterator().next()) + " is under Git, " + - "but is not registered in the Settings."); + VcsRootError unregisteredRoot = unregisteredRoots.iterator().next(); + description + .append("The directory " + rootToDisplayableString.fun(unregisteredRoot) + " is under " + unregisteredRoot.getVcsKey() + ", " + + "but is not registered in the Settings."); } else { - description.append("The following directories are roots of Git repositories, but they are not registered in the Settings:
" + + description.append("The following directories are roots of Vcs repositories, but they are not registered in the Settings:
" + StringUtil.join(unregisteredRoots, rootToDisplayableString, ", ")); } description.append("
"); @@ -163,36 +161,36 @@ public class GitRootProblemNotifier { } @NotNull - private static String makeTitle(@NotNull Collection unregisteredRoots, @NotNull Collection invalidRoots) { + private static String makeTitle(@NotNull Collection unregisteredRoots, @NotNull Collection invalidRoots) { String title; if (unregisteredRoots.isEmpty()) { - title = "Invalid Git root " + pluralize("mapping", invalidRoots.size()); + title = "Invalid Vcs root " + pluralize("mapping", invalidRoots.size()); } else if (invalidRoots.isEmpty()) { - title = "Unregistered Git " + pluralize("root", unregisteredRoots.size()) + " detected"; + title = "Unregistered Vcs " + pluralize("root", unregisteredRoots.size()) + " detected"; } else { - title = "Git root configuration problems"; + title = "Vcs root configuration problems"; } return title; } @NotNull - private static Collection getUnregisteredRoots(@NotNull Collection errors) { + private static Collection getUnregisteredRoots(@NotNull Collection errors) { return filterErrorsByType(errors, VcsRootError.Type.UNREGISTERED_ROOT); } @NotNull - private static Collection getInvalidRoots(@NotNull Collection errors) { + private static Collection getInvalidRoots(@NotNull Collection errors) { return filterErrorsByType(errors, VcsRootError.Type.EXTRA_MAPPING); } @NotNull - private static Collection filterErrorsByType(@NotNull Collection errors, @NotNull VcsRootError.Type type) { - Collection roots = new ArrayList(); + private static Collection filterErrorsByType(@NotNull Collection errors, @NotNull VcsRootError.Type type) { + Collection roots = new ArrayList(); for (VcsRootError error : errors) { if (error.getType() == type) { - roots.add(error.getMapping()); + roots.add(error); } } return roots; @@ -213,7 +211,7 @@ public class GitRootProblemNotifier { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (event.getDescription().equals("configure") && !myProject.isDisposed()) { ShowSettingsUtil.getInstance().showSettingsDialog(myProject, ActionsBundle.message("group.VcsGroup.text")); - Collection errorsAfterPossibleFix = GitRootProblemNotifier.getInstance(myProject).scan(); + Collection errorsAfterPossibleFix = getInstance(myProject).scan(); if (errorsAfterPossibleFix.isEmpty() && !notification.isExpired()) { notification.expire(); } diff --git a/plugins/git4idea/src/git4idea/roots/GitRootScanner.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootScanner.java similarity index 80% rename from plugins/git4idea/src/git4idea/roots/GitRootScanner.java rename to platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootScanner.java index fb1612771653..8ee2f551fd80 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootScanner.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootScanner.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package git4idea.roots; +package com.intellij.openapi.vcs.roots; import com.intellij.ProjectTopics; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.DumbAwareRunnable; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ModuleRootEvent; @@ -24,23 +23,24 @@ import com.intellij.openapi.roots.ModuleRootListener; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsListener; +import com.intellij.openapi.vcs.VcsRootChecker; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.newvfs.BulkFileListener; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.util.Alarm; import com.intellij.util.messages.MessageBus; -import git4idea.GitUtil; import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.concurrent.TimeUnit; /** - * @author Kirill Likhodedov + * @author Nadya Zabrodina */ -public class GitRootScanner implements BulkFileListener, ModuleRootListener, VcsListener { +public class VcsRootScanner implements BulkFileListener, ModuleRootListener, VcsListener { - @NotNull private final GitRootProblemNotifier myRootProblemNotifier; + @NotNull private final VcsRootProblemNotifier myRootProblemNotifier; + @NotNull private final VcsRootChecker[] myCheckers; private volatile boolean myProjectIsInitialized; private volatile boolean myMappingsAreReady; @@ -48,12 +48,13 @@ public class GitRootScanner implements BulkFileListener, ModuleRootListener, Vcs @NotNull private final Alarm myAlarm; private static final long WAIT_BEFORE_SCAN = TimeUnit.SECONDS.toMillis(1); - public static void start(@NotNull Project project) { - new GitRootScanner(project); + public static void start(@NotNull Project project, @NotNull VcsRootChecker[] checkers) { + new VcsRootScanner(project, checkers); } - private GitRootScanner(@NotNull Project project) { - myRootProblemNotifier = GitRootProblemNotifier.getInstance(project); + private VcsRootScanner(@NotNull Project project, @NotNull VcsRootChecker[] checkers) { + myRootProblemNotifier = VcsRootProblemNotifier.getInstance(project); + myCheckers = checkers; StartupManager.getInstance(project).runWhenProjectIsInitialized(new DumbAwareRunnable() { @Override @@ -79,8 +80,11 @@ public class GitRootScanner implements BulkFileListener, ModuleRootListener, Vcs public void after(@NotNull List events) { for (VFileEvent event : events) { String filePath = event.getPath(); - if (filePath != null && filePath.toLowerCase().endsWith(GitUtil.DOT_GIT)) { - scanIfReady(); + for (VcsRootChecker checker : myCheckers) { + if (checker.isVcsDir(filePath)) { + scanIfReady(); + break; + } } } } @@ -123,5 +127,4 @@ public class GitRootScanner implements BulkFileListener, ModuleRootListener, Vcs } }, WAIT_BEFORE_SCAN); } - } diff --git a/plugins/git4idea/src/META-INF/plugin.xml b/plugins/git4idea/src/META-INF/plugin.xml index da7d14a9117a..91e306d96e0d 100644 --- a/plugins/git4idea/src/META-INF/plugin.xml +++ b/plugins/git4idea/src/META-INF/plugin.xml @@ -109,6 +109,7 @@ + @@ -160,8 +161,6 @@ serviceImplementation="git4idea.Notificator"/> - diff --git a/plugins/git4idea/src/git4idea/GitVcs.java b/plugins/git4idea/src/git4idea/GitVcs.java index 12996da38d89..6d62a07bf422 100644 --- a/plugins/git4idea/src/git4idea/GitVcs.java +++ b/plugins/git4idea/src/git4idea/GitVcs.java @@ -46,6 +46,8 @@ import com.intellij.openapi.vcs.history.VcsHistoryProvider; import com.intellij.openapi.vcs.history.VcsRevisionNumber; import com.intellij.openapi.vcs.merge.MergeProvider; import com.intellij.openapi.vcs.rollback.RollbackEnvironment; +import com.intellij.openapi.vcs.roots.VcsRootDetectInfo; +import com.intellij.openapi.vcs.roots.VcsRootDetector; import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier; import com.intellij.openapi.vcs.update.UpdateEnvironment; import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList; @@ -77,9 +79,6 @@ import git4idea.i18n.GitBundle; import git4idea.merge.GitMergeProvider; import git4idea.rollback.GitRollbackEnvironment; import git4idea.roots.GitIntegrationEnabler; -import git4idea.roots.GitRootChecker; -import com.intellij.openapi.vcs.roots.VcsRootDetectInfo; -import com.intellij.openapi.vcs.roots.VcsRootDetector; import git4idea.status.GitChangeProvider; import git4idea.ui.branch.GitBranchWidget; import git4idea.update.GitUpdateEnvironment; @@ -320,11 +319,6 @@ public class GitVcs extends AbstractVcs { return dir.isDirectory() && GitUtil.gitRootOrNull(dir) != null; } - @Override - public VcsRootChecker getRootChecker() { - return new GitRootChecker(myProject, myPlatformFacade); - } - @Override protected void start() throws VcsException { } diff --git a/plugins/git4idea/src/git4idea/repo/GitRepositoryManager.java b/plugins/git4idea/src/git4idea/repo/GitRepositoryManager.java index d779dab856f3..3439149c38b6 100644 --- a/plugins/git4idea/src/git4idea/repo/GitRepositoryManager.java +++ b/plugins/git4idea/src/git4idea/repo/GitRepositoryManager.java @@ -16,13 +16,11 @@ package git4idea.repo; import com.intellij.dvcs.repo.AbstractRepositoryManager; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vfs.VirtualFile; import git4idea.GitPlatformFacade; import git4idea.GitUtil; -import git4idea.roots.GitRootScanner; import org.jetbrains.annotations.NotNull; /** @@ -32,25 +30,15 @@ public class GitRepositoryManager extends AbstractRepositoryManager roots = detectInfo.getRoots(); + Collection gitRoots = ContainerUtil.filter(detectInfo.getRoots(), new Condition() { + @Override + public boolean value(VcsRoot root) { + AbstractVcs gitVcs = root.getVcs(); + return gitVcs != null && gitVcs.getKeyInstanceMethod().equals(GitVcs.getKey()); + } + }); + Collection roots = VcsRootErrorsFinder.vcsRootsToVirtualFiles(gitRoots); VirtualFile projectDir = myProject.getBaseDir(); assert projectDir != null : "Base dir is unexpectedly null for project: " + myProject; - if (detectInfo.empty()) { + if (gitRoots.isEmpty()) { boolean succeeded = gitInitOrNotifyError(notificator, projectDir); if (succeeded) { addVcsRoots(Collections.singleton(projectDir)); @@ -66,7 +77,7 @@ public class GitIntegrationEnabler { } else { assert !roots.isEmpty(); - if (roots.size() > 1 || detectInfo.projectIsBelowGit()) { + if (roots.size() > 1 || detectInfo.projectIsBelowVcs()) { notifyAddedRoots(notificator, roots); } addVcsRoots(roots); @@ -95,9 +106,11 @@ public class GitIntegrationEnabler { private void refreshGitDir(final VirtualFile projectDir) { UIUtil.invokeAndWaitIfNeeded(new Runnable() { - @Override public void run() { + @Override + public void run() { myPlatformFacade.runReadAction(new Runnable() { - @Override public void run() { + @Override + public void run() { myPlatformFacade.getLocalFileSystem().refreshAndFindFileByPath(projectDir.getPath() + "/.git"); } }); diff --git a/plugins/git4idea/src/git4idea/roots/GitRootChecker.java b/plugins/git4idea/src/git4idea/roots/GitRootChecker.java index 47a221bbe1d8..c0e12e458c6c 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootChecker.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootChecker.java @@ -15,62 +15,33 @@ */ package git4idea.roots; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vcs.VcsDirectoryMapping; +import com.intellij.openapi.vcs.VcsKey; import com.intellij.openapi.vcs.VcsRootChecker; -import com.intellij.openapi.vcs.VcsRootError; -import com.intellij.openapi.vcs.roots.VcsRootErrorsFinder; -import git4idea.GitPlatformFacade; import git4idea.GitUtil; +import git4idea.GitVcs; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; -import java.util.ArrayList; -import java.util.Collection; /** * @author Kirill Likhodedov */ -public class GitRootChecker implements VcsRootChecker { +public class GitRootChecker extends VcsRootChecker { - @NotNull private final Collection myErrors; - private final boolean myProjectMappingIsInvalid; - - public GitRootChecker(@NotNull Project project, @NotNull GitPlatformFacade platformFacade) { - myErrors = new VcsRootErrorsFinder(project).find(); - myProjectMappingIsInvalid = isProjectMappingInvalid(); - } - - private boolean isProjectMappingInvalid() { - for (VcsRootError error : myErrors) { - if (error.getType() == VcsRootError.Type.EXTRA_MAPPING && error.getMapping().equals(VcsDirectoryMapping.PROJECT_CONSTANT)) { - return true; - } - } - return false; + @Override + public boolean isRoot(@NotNull String path) { + return new File(path, GitUtil.DOT_GIT).exists(); } + @Override @NotNull - @Override - public Collection getUnregisteredRoots() { - Collection roots = new ArrayList(); - for (VcsRootError error : myErrors) { - if (error.getType() == VcsRootError.Type.UNREGISTERED_ROOT) { - roots.add(error.getMapping()); - } - } - return roots; + public VcsKey getSupportedVcs() { + return GitVcs.getKey(); } @Override - public boolean isInvalidMapping(@NotNull VcsDirectoryMapping mapping) { - // this information is available in myErrors, - // but the method may be called in VcsDirectoryConfigurationPanel after adding a mapping (to highlight errors right away) - // in which case ProjectLevelVcsManager#getAllVcsRoots() is not aware of new roots yet, - // while VcsRootErrorsFinder relies on the set of roots returned from ProjectLevelVcsManager. - if (mapping.isDefaultMapping()) { - return myProjectMappingIsInvalid; - } - return !new File(mapping.getDirectory(), GitUtil.DOT_GIT).exists(); + public boolean isVcsDir(@Nullable String path) { + return path != null && path.toLowerCase().endsWith(GitUtil.DOT_GIT); } } diff --git a/plugins/git4idea/src/git4idea/roots/GitRootFinder.java b/plugins/git4idea/src/git4idea/roots/GitRootFinder.java index 99f7ae277faf..01e20992d0f9 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootFinder.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootFinder.java @@ -2,12 +2,12 @@ package git4idea.roots; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsDirectoryMapping; +import com.intellij.openapi.vcs.VcsRoot; import com.intellij.openapi.vcs.VcsRootFinder; import com.intellij.openapi.vcs.roots.VcsRootDetectInfo; import com.intellij.openapi.vcs.roots.VcsRootDetector; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.ContainerUtilRt; -import git4idea.GitPlatformFacade; import git4idea.GitVcs; import org.jetbrains.annotations.NotNull; @@ -20,25 +20,26 @@ import java.util.Collections; */ public class GitRootFinder implements VcsRootFinder { - @NotNull private final Project myProject; - @NotNull private final GitPlatformFacade myPlatformFacade; + @NotNull private final Project myProject; - public GitRootFinder(@NotNull Project project, @NotNull GitPlatformFacade platformFacade) { + public GitRootFinder(@NotNull Project project) { myProject = project; - myPlatformFacade = platformFacade; } @NotNull @Override public Collection findRoots(@NotNull VirtualFile root) { VcsRootDetectInfo info = new VcsRootDetector(myProject).detect(root); - Collection roots = info.getRoots(); + Collection roots = info.getRoots(); if (roots.isEmpty()) { return Collections.emptyList(); } Collection result = ContainerUtilRt.newArrayList(); - for (VirtualFile file : roots) { - result.add(new VcsDirectoryMapping(file.getPath(), GitVcs.getKey().getName())); + for (VcsRoot vcsRoot : roots) { + VirtualFile vFile = vcsRoot.getPath(); + if (vFile != null) { + result.add(new VcsDirectoryMapping(vFile.getPath(), GitVcs.getKey().getName())); + } } return result; } diff --git a/plugins/git4idea/tests/git4idea/roots/AbstractGitRootTest.groovy b/plugins/git4idea/tests/git4idea/roots/AbstractGitRootTest.groovy deleted file mode 100644 index 0016e30207d3..000000000000 --- a/plugins/git4idea/tests/git4idea/roots/AbstractGitRootTest.groovy +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package git4idea.roots -import com.intellij.dvcs.test.MockProject -import com.intellij.dvcs.test.MockProjectRootManager -import com.intellij.dvcs.test.MockVirtualFile -import com.intellij.openapi.project.Project -import com.intellij.openapi.util.io.FileUtil -import git4idea.test.GitLightTest -import org.junit.After -import org.junit.Before -/** - * - * @author Kirill Likhodedov - */ -class AbstractGitRootTest extends GitLightTest { - - static File baseDir - - @Before - void setUp() { - super.setUp(); - } - - @After - void tearDown() { - super.tearDown(); - } - - /** - * Creates the necessary temporary directories in the filesystem with empty ".git" directories for given roots. - * And creates an instance of the project. - * @param gitRoots path to actual .git roots, relative to the project dir. - */ - Project initProject(Collection gitRoots, Collection projectStructure, Collection contentRoots = []) { - String projectDir = createDirs(gitRoots) - Project project = new MockProject(projectDir) - createProjectStructure(project, projectStructure); - createProjectStructure(project, contentRoots); - - contentRoots.each { - ((MockProjectRootManager)myPlatformFacade.getProjectRootManager(project)).myContentRoots << MockVirtualFile.fromPath(it, project) - } - - project - } - - static void createProjectStructure(Project project, Collection paths) { - paths.each { String path -> - File file = new File(project.baseDir.path + "/" + path) - file.mkdir() - } - } - - /** - * @return path to the project - */ - private static String createDirs(Collection gitRoots) { - if (gitRoots.empty) { - return baseDir = FileUtil.createTempDirectory("grdt", null); - } - - baseDir = createBaseTempDir() - int maxDepth = findMaxDepthAboveProject(gitRoots) - File projectDir = createChild(baseDir, maxDepth) - gitRoots.each { String path -> - File file = new File(projectDir.path + "/" + path) - file.mkdirs() - file.deleteOnExit() - - File gitDir = new File(file, ".git") - gitDir.mkdir() - gitDir.deleteOnExit() - } - return projectDir.path - } - - private static File createBaseTempDir() { - FileUtil.createTempDirectory("pref", null) - } - - private static File createChild(File base, int depth) { - File dir = base - depth.times { dir = FileUtil.createTempDirectory(dir, "grdt", null)} - dir - } - - // Assuming that there are no ".." inside the path - only in the beginning - static int findMaxDepthAboveProject(Collection paths) { - def len = { String path -> path.split("/").count("..") } - len(paths.max(len)) - } - -} diff --git a/plugins/git4idea/tests/git4idea/roots/GitIntegrationEnablerTest.groovy b/plugins/git4idea/tests/git4idea/roots/GitIntegrationEnablerTest.groovy index 54d063b291fe..41b5ecc5c612 100644 --- a/plugins/git4idea/tests/git4idea/roots/GitIntegrationEnablerTest.groovy +++ b/plugins/git4idea/tests/git4idea/roots/GitIntegrationEnablerTest.groovy @@ -20,7 +20,7 @@ import com.intellij.notification.Notification import com.intellij.notification.NotificationType import com.intellij.openapi.vcs.roots.VcsRootDetectInfo import com.intellij.openapi.vfs.VirtualFile -import git4idea.test.GitLightTest +import com.intellij.testFramework.UsefulTestCase import git4idea.test.TestNotificator import org.junit.After import org.junit.Before @@ -28,18 +28,20 @@ import org.junit.Test import static git4idea.test.GitGTestUtil.toAbsolute import static junit.framework.Assert.* +import static org.junit.Assume.assumeTrue /** - * + * * @author Kirill Likhodedov */ -class GitIntegrationEnablerTest extends GitLightTest { +class GitIntegrationEnablerTest extends UsefulTestCase { public static final String TEST_NOTIFICATION_GROUP = "Test" @Override @Before public void setUp() { + assumeTrue(false); super.setUp(); } @@ -157,5 +159,4 @@ class GitIntegrationEnablerTest extends GitLightTest { void assertNotificationShown(String title, String message, NotificationType type) { assertNotificationShown(new Notification(TEST_NOTIFICATION_GROUP, title, message, type)) } - } diff --git a/plugins/git4idea/tests/git4idea/roots/GitPlatformTest.java b/plugins/git4idea/tests/git4idea/roots/GitPlatformTest.java new file mode 100644 index 000000000000..c435e76a0b27 --- /dev/null +++ b/plugins/git4idea/tests/git4idea/roots/GitPlatformTest.java @@ -0,0 +1,209 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package git4idea.roots; + +import com.intellij.ide.highlighter.ModuleFileType; +import com.intellij.openapi.application.Result; +import com.intellij.openapi.application.WriteAction; +import com.intellij.openapi.module.EmptyModuleType; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ModuleRootManager; +import com.intellij.openapi.roots.impl.ModuleRootManagerImpl; +import com.intellij.openapi.roots.impl.RootModelImpl; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VfsUtilCore; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.testFramework.PlatformTestCase; +import com.intellij.testFramework.UsefulTestCase; +import com.intellij.testFramework.fixtures.IdeaProjectTestFixture; +import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.HashSet; + +import static com.intellij.dvcs.test.Executor.*; + +/** + * @author Nadya Zabrodina + */ +public abstract class GitPlatformTest extends UsefulTestCase { + + protected Project myProject; + protected VirtualFile myProjectRoot; + protected VirtualFile myRepository; + public static final String myRepositoryFolderName = "repository"; + private RootModelImpl myRootModel; + protected static final Collection myFilesToDelete = new HashSet(); + + protected IdeaProjectTestFixture myProjectFixture; + + @SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors") + protected GitPlatformTest() { + PlatformTestCase.initPlatformLangPrefix(); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + myProjectFixture = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getTestName(true)).getFixture(); + myProjectFixture.setUp(); + + myProject = myProjectFixture.getProject(); + myProjectRoot = myProject.getBaseDir(); + cd(myProjectRoot); + Module module = doCreateRealModuleIn("foo", myProject, EmptyModuleType + .getInstance()); + myRootModel = ((ModuleRootManagerImpl)ModuleRootManager.getInstance(module)).getRootModel(); + mkdir(myRepositoryFolderName); + myRepository = myProjectRoot.findChild(myRepositoryFolderName); + } + + @Override + protected void tearDown() throws Exception { + for (File file : myFilesToDelete) { + delete(file); + } + myProjectFixture.tearDown(); + super.tearDown(); + } + + private static void delete(File file) { + boolean b = FileUtil.delete(file); + if (!b && file.exists()) { + fail("Can't delete " + file.getAbsolutePath()); + } + } + + /** + * Creates the necessary temporary directories in the filesystem with empty ".git" directories for given roots. + * And creates an instance of the project. + * + * @param gitRoots path to actual .git roots, relative to the project dir. + */ + public void initProject(@NotNull Collection gitRoots, + @NotNull Collection projectStructure, + @NotNull Collection contentRoots) + throws IOException { + createDirs(gitRoots); + createProjectStructure(myProject, projectStructure); + createProjectStructure(myProject, contentRoots); + if (!contentRoots.isEmpty()) { + for (String root : contentRoots) { + VirtualFile f = myProjectRoot.findFileByRelativePath(root); + if (f != null) { + myRootModel.addContentEntry(f); + } + } + } + } + + static void createProjectStructure(@NotNull Project project, @NotNull Collection paths) { + for (String path : paths) { + cd(project.getBaseDir().getPath()); + File f = new File(project.getBaseDir().getPath(), path); + f.mkdirs(); + } + } + + @NotNull + public static Module doCreateRealModuleIn(@NotNull String moduleName, + @NotNull final Project project, + @NotNull final ModuleType moduleType) { + final VirtualFile baseDir = project.getBaseDir(); + assertNotNull(baseDir); + final File moduleFile = new File(baseDir.getPath().replace('/', File.separatorChar), + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION); + FileUtil.createIfDoesntExist(moduleFile); + myFilesToDelete.add(moduleFile); + return new WriteAction() { + @Override + protected void run(Result result) throws Throwable { + final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleFile); + assert virtualFile != null; + Module module = ModuleManager.getInstance(project).newModule(virtualFile.getPath(), moduleType.getId()); + module.getModuleFile(); + result.setResult(module); + } + }.execute().getResultObject(); + } + + /** + * @return path to the project + */ + private void createDirs(@NotNull Collection gitRoots) throws IOException { + File baseDir; + if (gitRoots.isEmpty()) { + return; + } + + baseDir = VfsUtilCore.virtualToIoFile(myProject.getBaseDir()); + int maxDepth = findMaxDepthAboveProject(gitRoots); + File projectDir = createChild(baseDir, maxDepth - 1); + cd(projectDir.getPath()); + for (String path : gitRoots) { + File file = new File(projectDir, path); + file.mkdirs(); + File gitDir = new File(file, ".git"); + gitDir.mkdirs(); + myFilesToDelete.add(gitDir); + gitDir.deleteOnExit(); + cd(gitDir.getPath()); + touch("HEAD", "ref: refs/heads/master"); + File head = new File(gitDir, "HEAD"); + myFilesToDelete.add(head); + touch("config", ""); + File config = new File(gitDir, "config"); + myFilesToDelete.add(config); + } + } + + @NotNull + private static File createChild(@NotNull File base, int depth) throws IOException { + File dir = base; + if (depth < 0) { + return dir; + } + for (int i = 0; i < depth; ++i) { + dir = FileUtil.createTempDirectory(dir, "grdt", null); + } + return dir; + } + + // Assuming that there are no ".." inside the path - only in the beginning + static int findMaxDepthAboveProject(@NotNull Collection paths) { + int max = 0; + for (String path : paths) { + String[] splits = path.split("/"); + int count = 0; + for (String split : splits) { + if (split.equals("..")) { + count++; + } + } + if (count > max) { + max = count; + } + } + return max; + } +} diff --git a/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy b/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy deleted file mode 100644 index 500c8fda7db7..000000000000 --- a/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package git4idea.roots - -import com.intellij.openapi.project.Project -import com.intellij.openapi.vcs.roots.VcsRootDetectInfo -import com.intellij.openapi.vcs.roots.VcsRootDetector -import com.intellij.openapi.vfs.VirtualFile -import git4idea.test.GitGTestUtil -import org.junit.After -import org.junit.Before -import org.junit.Test - -import static org.junit.Assert.assertEquals -import static org.junit.Assert.fail - -/** - * @author Kirill Likhodedov - */ -class GitRootDetectorTest extends AbstractGitRootTest { - - Project myProject - - @Before - void setUp() { - super.setUp(); - } - - @After - void tearDown() { - super.tearDown(); - } - - @Test - void "no roots in project"() { - doTest gits: [], - expected: [], - full: false, - below: false - } - - @Test - void "project under single Git"() { - doTest "." - } - - @Test - void "project with Git under it"() { - doTest project: [".idea", "bin", "src", "community"], - gits: ["community"], - expected: ["community"], - full: false, - below: false - } - - @Test - public void "project with all subdirs under Git should still be not fully controlled"() { - doTest gits: [".idea", "src", "community"], - expected: [".idea", "src", "community"], - full: false, - below: false - } - - @Test - void "project under Git above it"() { - doTest gits: [".."], - expected: [".."], - full: true, - below: true - } - - @Test - void "IDEA project"() { - doTest ".", "./community", "./contrib" - } - - @Test - void "one above and one under"() { - doTest gits: ["..", "./community"], - expected: ["..", "./community"], - full: true, - below: true - } - - @Test - void "one above and one for project should show only project root"() { - doTest gits: ["..", "."], - expected: ["."], - full: true, - below: false - } - - @Test - void "one above and several under project"() { - doTest gits: ["..", "./community", "./contrib"], - expected: ["..", "./community", "./contrib"], - full: true, - below: true - } - - @Test - void "multiple above should be detected as one above"() { - doTest gits: ["..", "../.."], - expected: [".."], - full: true, - below: true - } - - @Test - void "unrelated root should not be detected"() { - doTest gits: ["../neighbour"], - expected: [], - full: false, - below: false - } - - @Test - void "linked source root alone should be detected"() { - doTest content_roots: ["../linked_root"], - gits: ["../linked_root"], - expected: ["../linked_root"], - full: false, - below: false - } - - @Test - void "linked source root and project root should be detected"() { - doTest content_roots: ["../linked_root"], - gits: [".", "../linked_root"], - expected: [".", "../linked_root"], - full: true, - below: false - } - - @Test - void "linked source below Git"() { - doTest content_roots: ["../linked_root/src"], - gits: [".", "../linked_root"], - expected: [".", "../linked_root"], - full: true, - below: false - } - - @Test - // This is a test of performance optimization via limitation: don't scan deep though the whole VFS, i.e. don't detect deep roots - void "don't scan deeper than 2 levels below a content root"() { - doTest content_roots: ["content_root"], - gits: ["community", "content_root/lev1/lev2", "content_root2/lev1/lev2/lev3"], - expected: ["community", "content_root/lev1/lev2"], - full: false, - below: false - } - - /** - * Perform test. Map contains actual Git repositories to be created on disk, - * and Git repositories expected to be detected by the VcsRootDetector. - * @param map - */ - private void doTest(Map map) { - myProject = initProject(map.gits, map.project, map.content_roots) - testInfo empty: map.expected.empty, - full : map.full, - roots: map.expected, - below: map.below - } - - /** - * Shorthand, when all Git roots are expected to be detected, and project is fully under Git. - * @param roots paths relative to the project dir. "..", ".", "./community" are accepted. - */ - private void doTest(String... roots = []) { - doTest gits: roots.toList(), - expected: roots.toList(), - full: true, - below: false - } - - void testInfo(Map expected) { - assertInfo(expected, detect()) - } - - void assertInfo(Map expected, VcsRootDetectInfo actual) { - assertEquals(expected.empty, actual.empty()) - if (expected.full ^ actual.totallyUnderGit()) { - fail("The project is unexpectedly ${actual.totallyUnderGit() ? "" : "not "}under Git${roots(actual.roots)}") - } - if (expected.below ^ actual.projectIsBelowGit()) { - fail("The project is unexpectedly ${actual.projectIsBelowGit() ? "below" : "not below"} Git${roots(actual.roots)}") - } - assertRoots(expected.roots, actual.roots) - } - - static String roots(Collection roots) { - "\nRoots:${roots.collect {"\n * $it"}}\n" - } - - void assertRoots(Collection expectedRelativePaths, Collection actual) { - assertEquals(GitGTestUtil.toAbsolute(expectedRelativePaths, myProject).toSet(), getPaths(actual).toSet()) - } - - static Collection getPaths(Collection files) { - files.collect { it.path } - } - - private VcsRootDetectInfo detect() { - new VcsRootDetector(myProject).detect() - } - -} \ No newline at end of file diff --git a/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.java b/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.java new file mode 100644 index 000000000000..75e5a15edc5d --- /dev/null +++ b/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.java @@ -0,0 +1,222 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package git4idea.roots; + +import com.intellij.dvcs.test.Executor; +import com.intellij.dvcs.test.TestRepositoryUtil; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.vcs.VcsRoot; +import com.intellij.openapi.vcs.roots.VcsRootDetectInfo; +import com.intellij.openapi.vcs.roots.VcsRootDetector; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.File; +import java.io.IOException; +import java.util.*; + +import static com.intellij.dvcs.test.Executor.cd; + + +/** + * @author Nadya Zabrodina + */ +public class GitRootDetectorTest extends GitPlatformTest { + + public void testNoRootsInProject() throws IOException { + Map> map = new HashMap>(); + map.put("git", Collections.emptyList()); + map.put("content_roots", Collections.emptyList()); + doTest(map, null, Collections.emptyList(), false, false); + } + + public void testProjectUnderSingleGit() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList(".")); + map.put("content_roots", Collections.emptyList()); + doTest(map, myProjectRoot, Arrays.asList("."), true, false); + } + + public void testProjectWithGitUnderIt() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList("community")); + map.put("content_roots", Collections.emptyList()); + cd(myProjectRoot); + Executor.mkdir("src"); + Executor.mkdir(".idea"); + doTest(map, myProjectRoot, Arrays.asList("community"), false, false); + } + + public void testProjectWithAllSubdirsUnderGitShouldStillBeNotFullyControlled() throws IOException { + String[] dirNames = {".idea", "src", "community"}; + Map> map = new HashMap>(); + map.put("git", Arrays.asList(dirNames)); + map.put("content_roots", Collections.emptyList()); + doTest(map, myProjectRoot, Arrays.asList(dirNames), false, false); + } + + + public void testProjectUnderVcsAboveIt() throws IOException { + String subdir = "insideRepo"; + cd(myRepository); + Executor.mkdir(subdir); + Map> map = new HashMap>(); + map.put("git", Arrays.asList(myRepository.getName())); + map.put("content_roots", Collections.emptyList()); + VirtualFile vfile = myRepository.findChild(subdir); + doTest(map, vfile, Arrays.asList(myRepository.getName()), + true, true); + } + + + public void testIDEAProject() throws IOException { + String[] names = {"community", "contrib", "."}; + Map> map = new HashMap>(); + map.put("git", Arrays.asList(names)); + map.put("content_roots", Collections.emptyList()); + doTest(map, myProjectRoot, Arrays.asList(names), true, false); + } + + + public void testOneAboveAndOneUnder() throws IOException { + String[] names = {myRepository.getName() + "/community", "."}; + Map> map = new HashMap>(); + map.put("git", Arrays.asList(names)); + map.put("content_roots", Collections.emptyList()); + doTest(map, myRepository, Arrays.asList(names), true, true); + } + + public void testOneAboveAndOneForProjectShouldShowOnlyProjectRoot() throws IOException { + String[] names = {myRepository.getName(), "."}; + Map> map = new HashMap>(); + map.put("git", Arrays.asList(names)); + map.put("content_roots", Collections.emptyList()); + doTest(map, myRepository, Arrays.asList(myRepository.getName()), true, false); + } + + public void testOneAboveAndSeveralUnderProject() throws IOException { + String[] names = {".", myRepository.getName() + "/community", myRepository.getName() + "/contrib"}; + Map> map = new HashMap>(); + map.put("git", Arrays.asList(names)); + map.put("content_roots", Collections.emptyList()); + doTest(map, myRepository, Arrays.asList(names), true, true); + } + + + public void testMultipleAboveShouldBeDetectedAsOneAbove() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList(".", myRepository.getName())); + map.put("content_roots", Collections.emptyList()); + String subdir = "insideRepo"; + cd(myRepository); + Executor.mkdir(subdir); + VirtualFile vfile = myRepository.findChild(subdir); + doTest(map, vfile, Arrays.asList(myRepository.getName()), true, true); + } + + public void testUnrelatedRootShouldNotBeDetected() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList("another")); + map.put("content_roots", Collections.emptyList()); + doTest(map, myRepository, Collections.emptyList(), false, false); + } + + + public void testLinkedSourceRootAloneShouldBeDetected() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList("linked_root")); + map.put("content_roots", Arrays.asList("linked_root")); + doTest(map, myRepository, Arrays.asList("linked_root"), false, false); + } + + public void testLinkedSourceRootAndProjectRootShouldBeDetected() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList(".", "linked_root")); + map.put("content_roots", Arrays.asList("linked_root")); + doTest(map, myProjectRoot, Arrays.asList(".", "linked_root"), true, false); + } + + public void testLinkedSourceBelowGit() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList(".", "linked_root")); + map.put("content_roots", Arrays.asList("linked_root/src")); + doTest(map, myProjectRoot, Arrays.asList(".", "linked_root"), true, false); + } + + // This is a test of performance optimization via limitation: don't scan deep though the whole VFS, i.e. don't detect deep roots + public void testDontScanDeeperThan2LevelsBelowAContentRoot() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList("community", "content_root/lev1/lev2", "content_root2/lev1/lev2/lev3")); + map.put("content_roots", Arrays.asList("content_root")); + doTest(map, myProjectRoot, Arrays.asList("community", "content_root/lev1/lev2"), false, false); + } + + void assertRoots(Collection expectedRelativePaths, Collection actual) { + TestRepositoryUtil.assertEqualCollections(actual, toAbsolute(expectedRelativePaths, myProject)); + } + + @NotNull + public static Collection toAbsolute(Collection relPaths, final Project project) { + return ContainerUtil.map(relPaths, new Function() { + @Override + public String fun(String s) { + try { + return FileUtil.toSystemIndependentName(new File(project.getBaseDir().getPath(), s).getCanonicalPath()); + } + catch (IOException e) { + fail(); + e.printStackTrace(); + return null; + } + } + }); + } + + @NotNull + static Collection getPaths(@NotNull Collection files) { + return ContainerUtil.map(files, new Function() { + @Override + public String fun(VcsRoot root) { + VirtualFile file = root.getPath(); + assert file != null; + return FileUtil.toSystemIndependentName(file.getPath()); + } + }); + } + + @NotNull + private VcsRootDetectInfo detect(@Nullable VirtualFile startDir) { + return new VcsRootDetector(myProject).detect(startDir); + } + + public void doTest(@NotNull Map> map, + @Nullable VirtualFile startDir, + @NotNull Collection expectedPaths, + boolean expectedFull, + boolean expectedBelow) + throws IOException { + initProject(map.get("git"), Collections.emptyList(), map.get("content_roots")); + + VcsRootDetectInfo info = detect(startDir); + assertRoots(expectedPaths, getPaths(info.getRoots())); + assertEquals(expectedFull, info.totallyUnderVcs()); + assertEquals(expectedBelow, info.projectIsBelowVcs()); + } +} diff --git a/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy b/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy deleted file mode 100644 index 8fbd2a4a8691..000000000000 --- a/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package git4idea.roots - -import com.intellij.openapi.vcs.VcsDirectoryMapping -import com.intellij.openapi.vcs.VcsRootError -import com.intellij.openapi.vcs.roots.VcsRootErrorsFinder -import git4idea.test.GitMockVcsManager -import org.junit.After -import org.junit.Before -import org.junit.Test - -import static git4idea.test.GitGTestUtil.toAbsolute -import static junit.framework.Assert.assertEquals -/** - * - * @author Kirill Likhodedov - */ -class GitRootErrorsFinderTest extends AbstractGitRootTest { - - static final String PROJECT = VcsDirectoryMapping.PROJECT_CONSTANT - - GitMockVcsManager myVcsManager - - @Before - void setUp() { - super.setUp() - } - - @After - void tearDown() { - super.tearDown(); - } - - @Test - void "No roots, then no errors"() { - doTest git: [], - roots: [], - errors: [] - } - - @Test - void "Same 1 root in both, then no errors"() { - doTest git: ["."], - roots: ["."], - errors: [] - } - - @Test - void "Same 2 roots in both, then no errors"() { - doTest git: ["..", "community"], - roots: ["..", "community"], - errors: [] - } - - @Test - void "One git, no VCS roots, then error"() { - doTest git: ["."], - roots: [], - errors: [unreg : ["."]] - } - - @Test - void "One VCS root, no gits, then error"() { - doTest git: [], - roots: ["."], - errors: [extra: ["."]] - } - - @Test - void "One root, but different, then 2 errors"() { - doTest git: ["."], - roots: ["community"], - errors: [unreg: ["."], extra: ["community"]] - } - - @Test - void "Two roots, one matching, one different, then 2 errors"() { - doTest git: [".", "community"], - roots: [".", "contrib"], - errors: [unreg: ["community"], extra: ["contrib"]] - } - - @Test - void "Two roots in git, one matching in VCS, then error"() { - doTest git: [".", "community"], - roots: ["."], - errors: [unreg: ["community"]] - } - - @Test - void "Two roots, both not matching, then 4 errors"() { - doTest git: ["..", "community"], - roots: [".", "contrib"], - errors: [unreg: ["..", "community"], extra: [".", "contrib"]] - } - - @Test - void "Project root, no gits, then error about extra root"() { - doTest content_roots: ["."], - git: [], - roots: [PROJECT], - errors: [extra: [PROJECT]] - } - - @Test - void "Project root, full under git, then correct"() { - doTest content_roots: ["."], - git: ["."], - roots: [PROJECT], - errors: [] - } - - @Test - void "Project root, git for a content root below project, then error"() { - doTest content_roots: [".", "content_root"], - git: ["content_root"], - roots: [PROJECT], - errors: [unreg: ["content_root"]] - } - - @Test - void "Project root, git below project folder not in a content root, then unregistered root error"() { - // this is to be fixed: auto-detection of Git repositories in subfolders for the mapping - doTest content_roots: ["."], - git: ["community"], - roots: [PROJECT], - errors: [unreg: ["community"]] - } - - @Test - void "Project root, git for full project, content root, linked source, folder below project, then errors"() { - doTest content_roots: [".", "content_root", "../linked_source_root"], - git: [".", "content_root", "../linked_source_root", "folder"], - roots: [PROJECT], - errors: [unreg: ["content_root", "../linked_source_root", "folder"]] - } - - @Test - void "Project root, root for folder, git for full project, content root, linked source, folder below project, then errors"() { - doTest content_roots: [".", "content_root", "../linked_source_root"], - git: [".", "content_root", "../linked_source_root", "folder"], - roots: [PROJECT, "folder"], - errors: [unreg: ["content_root", "../linked_source_root"]] - } - - @Test - void "Project root, git like in IDEA project, then correct"() { - doTest content_roots: [".", "community", "contrib"], - git: [".", "community", "contrib"], - roots: [PROJECT], - errors: [unreg: ["community", "contrib"]] - } - - @Test - void "Real Git root deeper than 3 levels should be detected"() { - doTest content_roots: [".", "community", "contrib"], - git: [".", "community", "contrib", "community/level1/level2/level3"], - roots: [PROJECT, "community/level1/level2/level3"], - errors: [unreg: ["community", "contrib"]] - } - - private void doTest(Map map) { - myProject = initProject(map.git, [], map.content_roots) - myVcsManager = (GitMockVcsManager) myPlatformFacade.getVcsManager(myProject) - - addVcsRoots(map.roots) - - Collection expected = new ArrayList(); - expected.addAll map.errors.unreg.collect { unreg(it) } - expected.addAll map.errors.extra.collect { extra(it) } - - Collection actual = new VcsRootErrorsFinder(myProject).find() - assertEquals expected.toSet(), actual.toSet() - } - - void addVcsRoots(Collection relativeRoots) { - relativeRoots.each { - if (it.equals(PROJECT)) { - myVcsManager.setProjectRootMapping() - } - else { - String root = toAbsolute(it, myProject) - myVcsManager.addRoots(root) - } - } - } - - VcsRootError unreg(String path) { - return new VcsRootError(VcsRootError.Type.UNREGISTERED_ROOT, toAbsolute(path, myProject)) - } - - VcsRootError extra(String path) { - return new VcsRootError(VcsRootError.Type.EXTRA_MAPPING, path.equals(PROJECT) ? PROJECT : toAbsolute(path, myProject)) - } - - -} diff --git a/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.java b/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.java new file mode 100644 index 000000000000..b1bf00feabc1 --- /dev/null +++ b/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.java @@ -0,0 +1,270 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package git4idea.roots; + +import com.intellij.dvcs.test.TestRepositoryUtil; +import com.intellij.openapi.vcs.ProjectLevelVcsManager; +import com.intellij.openapi.vcs.VcsDirectoryMapping; +import com.intellij.openapi.vcs.VcsRootError; +import com.intellij.openapi.vcs.roots.VcsRootErrorsFinder; +import git4idea.GitVcs; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.util.*; + +import static git4idea.test.GitGTestUtil.toAbsolute; + +/** + * @author Nadya Zabrodina + */ +public class GitRootErrorsFinderTest extends GitPlatformTest { + + static final String PROJECT = VcsDirectoryMapping.PROJECT_CONSTANT; + @NotNull private ProjectLevelVcsManager myVcsManager; + + @Override + public void setUp() throws Exception { + super.setUp(); + myVcsManager = ProjectLevelVcsManager.getInstance(myProject); + } + + public void testNoRootsThenNoErrors() throws IOException { + Map> map = new HashMap>(); + map.put("git", Collections.emptyList()); + map.put("roots", Collections.emptyList()); + map.put("content_roots", Collections.emptyList()); + doTest(map, Collections.>emptyMap()); + } + + public void testSameOneRootInBothThenNoErrors() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList(".")); + map.put("roots", Arrays.asList(".")); + map.put("content_roots", Collections.emptyList()); + doTest(map, Collections.>emptyMap()); + } + + public void testSameTwoRootsInBothThenNoErrors() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList(".", "community")); + map.put("roots", Arrays.asList(".", "community")); + map.put("content_roots", Collections.emptyList()); + doTest(map, Collections.>emptyMap()); + } + + public void testOneGitNoVCSRootsThenError() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList(".")); + map.put("roots", Collections.emptyList()); + map.put("content_roots", Collections.emptyList()); + Map> errorsMap = new HashMap>(); + errorsMap.put("unreg", Arrays.asList(".")); + doTest(map, errorsMap); + } + + public void testOneVCSRootNoGitsThenError() throws IOException { + Map> map = new HashMap>(); + map.put("roots", Arrays.asList(".")); + map.put("git", Collections.emptyList()); + map.put("content_roots", Collections.emptyList()); + Map> errorsMap = new HashMap>(); + errorsMap.put("extra", Arrays.asList(".")); + doTest(map, errorsMap); + } + + public void testOneRootButDifferentThenTwoErrors() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList(".")); + map.put("roots", Arrays.asList("community")); + map.put("content_roots", Collections.emptyList()); + Map> errorsMap = new HashMap>(); + errorsMap.put("extra", Arrays.asList("community")); + errorsMap.put("unreg", Arrays.asList(".")); + doTest(map, errorsMap); + } + + public void testTwoRootsOneMatchingOneDifferentThenTwoErrors() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList(".", "community")); + map.put("roots", Arrays.asList(".", "contrib")); + map.put("content_roots", Collections.emptyList()); + Map> errorsMap = new HashMap>(); + errorsMap.put("extra", Arrays.asList("contrib")); + errorsMap.put("unreg", Arrays.asList("community")); + doTest(map, errorsMap); + } + + public void testTwoRootsInGitOneMatchingInVCSThenError() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList(".", "community")); + map.put("roots", Arrays.asList(".")); + map.put("content_roots", Collections.emptyList()); + Map> errorsMap = new HashMap>(); + errorsMap.put("unreg", Arrays.asList("community")); + doTest(map, errorsMap); + } + + public void testTwoRootsBothNotMatchingThenFourErrors() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList(".", "community")); + map.put("roots", Arrays.asList("another", "contrib")); + map.put("content_roots", Collections.emptyList()); + Map> errorsMap = new HashMap>(); + errorsMap.put("extra", Arrays.asList("contrib", "another")); + errorsMap.put("unreg", Arrays.asList("community", ".")); + doTest(map, errorsMap); + } + + public void testProjectRootNoGitsThenErrorAboutExtraRoot() throws IOException { + Map> map = new HashMap>(); + map.put("git", Collections.emptyList()); + map.put("roots", Arrays.asList(PROJECT)); + map.put("content_roots", Collections.emptyList()); + Map> errorsMap = new HashMap>(); + errorsMap.put("extra", Arrays.asList(PROJECT)); + doTest(map, errorsMap); + } + + public void testProjectRootFullUnderGitThenCorrect() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList(".")); + map.put("roots", Arrays.asList(".", PROJECT)); + map.put("content_roots", Collections.emptyList()); + doTest(map, Collections.>emptyMap()); + } + + public void testProjectRootGitForAContentRootBelowProjectThenError() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList("content_root")); + map.put("roots", Arrays.asList(PROJECT)); + map.put("content_roots", Arrays.asList("content_root")); + Map> errorsMap = new HashMap>(); + errorsMap.put("unreg", Arrays.asList("content_root")); + doTest(map, errorsMap); + } + + public void testProjectRootGitBelowProjectFolderNotInAContentRootThenUnregisteredRootError() throws IOException { + // this is to be fixed: auto-detection of Git repositories in subfolders for the mapping + Map> map = new HashMap>(); + map.put("git", Arrays.asList("community")); + map.put("roots", Arrays.asList(PROJECT)); + map.put("content_roots", Arrays.asList(".")); + Map> errorsMap = new HashMap>(); + errorsMap.put("unreg", Arrays.asList("community")); + doTest(map, errorsMap); + } + + public void testProjectRootGitForFullProjectContentRootLinkedSourceFolderBelowProjectThenErrors() throws IOException + + { + Map> map = new HashMap>(); + map.put("git", Arrays.asList(".", "content_root", "../linked_source_root", "folder")); + map.put("roots", Arrays.asList(PROJECT)); + map.put("content_roots", Arrays.asList(".", "content_root", "../linked_source_root")); + Map> errorsMap = new HashMap>(); + errorsMap.put("unreg", Arrays.asList("content_root", "../linked_source_root", "folder")); + doTest(map, errorsMap); + } + + public void testProjectRootRootForFolderGitForFullProjectContentRootLinkedSourceFolderBelowProjectThenErrors() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList(".", "content_root", "../linked_source_root", "folder")); + map.put("roots", Arrays.asList(PROJECT, "folder")); + map.put("content_roots", Arrays.asList(".", "content_root", "../linked_source_root")); + Map> errorsMap = new HashMap>(); + errorsMap.put("unreg", Arrays.asList("content_root", "../linked_source_root")); + doTest(map, errorsMap); + } + + public void testProjectRootGitLikeInIDEAProjectThenError() throws IOException { + Map> map = new HashMap>(); + map.put("git", Arrays.asList(".", "community", "contrib")); + map.put("roots", Arrays.asList(PROJECT)); + map.put("content_roots", Arrays.asList(".", "community", "contrib")); + Map> errorsMap = new HashMap>(); + errorsMap.put("unreg", Arrays.asList("community", "contrib")); + doTest(map, errorsMap); + } + + public void testRealGitRootDeeperThanThreeLevelsShouldBeDetected() throws IOException { + + Map> map = new HashMap>(); + map.put("git", Arrays.asList(".", "community", "contrib", "community/level1/level2/level3")); + map.put("roots", Arrays.asList(PROJECT, "community/level1/level2/level3")); + map.put("content_roots", Arrays.asList(".", "community", "contrib")); + Map> errorsMap = new HashMap>(); + errorsMap.put("unreg", Arrays.asList("community", "contrib")); + doTest(map, errorsMap); + } + + private void doTest(@NotNull Map> map, @NotNull Map> errors) throws IOException { + initProject(map.get("git"), Collections.emptyList(), map.get("content_roots")); + addVcsRoots(map.get("roots")); + + Collection expected = new ArrayList(); + Collection unregPaths = errors.get("unreg"); + Collection extraPaths = errors.get("extra"); + if (unregPaths != null) { + expected.addAll(unregAll(unregPaths)); + } + if (extraPaths != null) { + expected.addAll(extraAll(extraPaths)); + } + Collection actual = new VcsRootErrorsFinder(myProject).find(); + TestRepositoryUtil.assertEqualCollections(actual, expected); + } + + void addVcsRoots(@NotNull Collection relativeRoots) { + for (String root : relativeRoots) { + if (root.equals(PROJECT)) { + myVcsManager.setDirectoryMapping("", GitVcs.NAME); + } + else { + String absoluteRoot = toAbsolute(root, myProject); + myVcsManager.setDirectoryMapping(absoluteRoot, GitVcs.NAME); + } + } + } + + @NotNull + Collection unregAll(@NotNull Collection paths) { + Collection unregRoots = new ArrayList(); + for (String path : paths) { + unregRoots.add(unreg(path)); + } + return unregRoots; + } + + @NotNull + Collection extraAll(@NotNull Collection paths) { + Collection extraRoots = new ArrayList(); + for (String path : paths) { + extraRoots.add(extra(path)); + } + return extraRoots; + } + + @NotNull + VcsRootError unreg(@NotNull String path) { + return new VcsRootError(VcsRootError.Type.UNREGISTERED_ROOT, toAbsolute(path, myProject), GitVcs.NAME); + } + + @NotNull + VcsRootError extra(@NotNull String path) { + return new VcsRootError(VcsRootError.Type.EXTRA_MAPPING, PROJECT.equals(path) ? PROJECT : toAbsolute(path, myProject), GitVcs.NAME); + } +} diff --git a/plugins/hg4idea/src/META-INF/plugin.xml b/plugins/hg4idea/src/META-INF/plugin.xml index 890c9f8b3cd2..8eb193bd5fd6 100644 --- a/plugins/hg4idea/src/META-INF/plugin.xml +++ b/plugins/hg4idea/src/META-INF/plugin.xml @@ -10,6 +10,7 @@ + diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/roots/HgRootChecker.java b/plugins/hg4idea/src/org/zmlx/hg4idea/roots/HgRootChecker.java new file mode 100644 index 000000000000..93a108c32bc0 --- /dev/null +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/roots/HgRootChecker.java @@ -0,0 +1,45 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.zmlx.hg4idea.roots; + +import com.intellij.openapi.vcs.VcsKey; +import com.intellij.openapi.vcs.VcsRootChecker; +import org.jetbrains.annotations.NotNull; +import org.zmlx.hg4idea.HgVcs; +import org.zmlx.hg4idea.util.HgUtil; + +import java.io.File; + +/** + * @author Nadya Zabrodina + */ +public class HgRootChecker extends VcsRootChecker { + + @Override + public boolean isRoot(@NotNull String path) { + return new File(path, HgUtil.DOT_HG).exists(); + } + + @Override + public VcsKey getSupportedVcs() { + return HgVcs.getKey(); + } + + @Override + public boolean isVcsDir(String path) { + return path != null && path.toLowerCase().endsWith(HgUtil.DOT_HG); + } +} From ea6a8c8d0a7fbaa649edc8c08008063da2a230f0 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Sat, 2 Nov 2013 02:02:16 +0400 Subject: [PATCH 9/9] Test for root scanner and root errors detector moved to platform. --- .../vcs/roots/VcsRootErrorsFinder.java | 2 +- .../com/intellij/openapi/vcs}/Executor.java | 2 +- .../intellij/openapi/vcs/VcsTestUtil.java} | 31 +++++++++++++++++-- .../openapi/vcs/roots/VcsPlatformTest.java | 10 +++--- .../vcs/roots/VcsRootDetectorTest.java | 26 ++++++---------- .../vcs/roots/VcsRootErrorsFinderTest.java | 22 ++++++------- .../test-stepdefs/git4idea/CommitDetails.java | 4 +-- .../git4idea/GitCherryPickStepdefs.java | 2 +- .../git4idea/GitCucumberWorld.java | 4 +-- .../git4idea/test/GitExecutor.java | 2 +- .../git4idea/test/GitTestRunEnv.java | 2 +- .../git4idea/test/GitTestUtil.java | 8 ++--- .../branch/GitBranchWorkerTest.groovy | 2 +- .../crlf/GitCrlfProblemsDetectorTest.groovy | 2 +- .../tests/git4idea/repo/GitConfigTest.java | 12 +++---- .../repo/GitRepositoryReaderTest.groovy | 4 +-- .../GithubCreatePullRequestTestBase.java | 2 +- .../github/GithubShareProjectTest.java | 2 +- .../testSrc/hg4idea/test/HgEncodingTest.java | 4 +-- .../testSrc/hg4idea/test/HgExecutor.java | 2 +- .../testSrc/hg4idea/test/HgPlatformTest.java | 4 +-- .../test/annotation/HgAnnotationTest.java | 4 +-- .../hg4idea/test/config/HgConfigTest.java | 6 ++-- .../test/history/HgBrowseChangesTest.java | 4 +-- .../hg4idea/test/history/HgHistoryTest.java | 2 +- .../hg4idea/test/history/HgLogTest.java | 4 +-- .../test/merge/HgMergeProviderTest.java | 2 +- .../test/repo/HgRealRepositoryReaderTest.java | 12 +++---- .../test/repo/HgRepositoryReaderTest.java | 8 ++--- 29 files changed, 105 insertions(+), 86 deletions(-) rename platform/{dvcs/testFramework/com/intellij/dvcs/test => vcs-impl/testSrc/com/intellij/openapi/vcs}/Executor.java (99%) rename platform/{dvcs/testFramework/com/intellij/dvcs/test/TestRepositoryUtil.java => vcs-impl/testSrc/com/intellij/openapi/vcs/VcsTestUtil.java} (88%) rename plugins/git4idea/tests/git4idea/roots/GitPlatformTest.java => platform/vcs-impl/testSrc/com/intellij/openapi/vcs/roots/VcsPlatformTest.java (95%) rename plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.java => platform/vcs-impl/testSrc/com/intellij/openapi/vcs/roots/VcsRootDetectorTest.java (94%) rename plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.java => platform/vcs-impl/testSrc/com/intellij/openapi/vcs/roots/VcsRootErrorsFinderTest.java (94%) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java index 9a5aa900bf40..3c2c494c7f97 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java @@ -114,7 +114,7 @@ public class VcsRootErrorsFinder { return ContainerUtil.find(checkers, new Condition() { @Override public boolean value(VcsRootChecker checker) { - return checker.getSupportedVcs().getName().equals(mapping.getVcs()) && checker.isRoot(pathToCheck); + return checker.getSupportedVcs().getName().equalsIgnoreCase(mapping.getVcs()) && checker.isRoot(pathToCheck); } }) != null; } diff --git a/platform/dvcs/testFramework/com/intellij/dvcs/test/Executor.java b/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/Executor.java similarity index 99% rename from platform/dvcs/testFramework/com/intellij/dvcs/test/Executor.java rename to platform/vcs-impl/testSrc/com/intellij/openapi/vcs/Executor.java index a736f4bf2de3..5f40300f09c6 100644 --- a/platform/dvcs/testFramework/com/intellij/dvcs/test/Executor.java +++ b/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/Executor.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.dvcs.test; +package com.intellij.openapi.vcs; import com.intellij.execution.process.CapturingProcessHandler; import com.intellij.execution.process.ProcessOutput; diff --git a/platform/dvcs/testFramework/com/intellij/dvcs/test/TestRepositoryUtil.java b/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/VcsTestUtil.java similarity index 88% rename from platform/dvcs/testFramework/com/intellij/dvcs/test/TestRepositoryUtil.java rename to platform/vcs-impl/testSrc/com/intellij/openapi/vcs/VcsTestUtil.java index 9b33b6719e49..a76dde616cab 100644 --- a/platform/dvcs/testFramework/com/intellij/dvcs/test/TestRepositoryUtil.java +++ b/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/VcsTestUtil.java @@ -1,4 +1,4 @@ -package com.intellij.dvcs.test; +package com.intellij.openapi.vcs; import com.intellij.openapi.application.PluginPathManager; import com.intellij.openapi.command.WriteCommandAction; @@ -7,6 +7,8 @@ import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -15,6 +17,8 @@ import java.io.FilenameFilter; import java.io.IOException; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; +import java.util.List; import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.fail; @@ -22,8 +26,7 @@ import static junit.framework.Assert.fail; /** * @author Nadya Zabrodina */ -public class TestRepositoryUtil { - +public class VcsTestUtil { // TODO: option - create via IDEA or via java.io. In latter case no need in Project parameter. public static VirtualFile createFile(@NotNull Project project, @@ -193,4 +196,26 @@ public class TestRepositoryUtil { public static String stringifyActualExpected(@NotNull Object actual, @NotNull Object expected) { return "\nExpected:\n" + expected + "\nActual:\n" + actual; } + + @NotNull + public static String toAbsolute(@NotNull String relPath, @NotNull Project project) { + new File(toAbsolute(Collections.singletonList(relPath), project).get(0)).mkdir(); + return toAbsolute(Collections.singletonList(relPath), project).get(0); + } + + @NotNull + public static List toAbsolute(@NotNull Collection relPaths, @NotNull final Project project) { + return ContainerUtil.map2List(relPaths, new Function() { + @Override + public String fun(String s) { + try { + return FileUtil.toSystemIndependentName((new File(project.getBasePath() + "/" + s).getCanonicalPath())); + } + catch (IOException e) { + e.printStackTrace(); + return ""; + } + } + }); + } } diff --git a/plugins/git4idea/tests/git4idea/roots/GitPlatformTest.java b/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/roots/VcsPlatformTest.java similarity index 95% rename from plugins/git4idea/tests/git4idea/roots/GitPlatformTest.java rename to platform/vcs-impl/testSrc/com/intellij/openapi/vcs/roots/VcsPlatformTest.java index c435e76a0b27..a12bf406293e 100644 --- a/plugins/git4idea/tests/git4idea/roots/GitPlatformTest.java +++ b/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/roots/VcsPlatformTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package git4idea.roots; +package com.intellij.openapi.vcs.roots; import com.intellij.ide.highlighter.ModuleFileType; import com.intellij.openapi.application.Result; @@ -41,12 +41,13 @@ import java.io.IOException; import java.util.Collection; import java.util.HashSet; -import static com.intellij.dvcs.test.Executor.*; +import static com.intellij.openapi.vcs.Executor.*; + /** * @author Nadya Zabrodina */ -public abstract class GitPlatformTest extends UsefulTestCase { +public abstract class VcsPlatformTest extends UsefulTestCase { protected Project myProject; protected VirtualFile myProjectRoot; @@ -54,11 +55,12 @@ public abstract class GitPlatformTest extends UsefulTestCase { public static final String myRepositoryFolderName = "repository"; private RootModelImpl myRootModel; protected static final Collection myFilesToDelete = new HashSet(); + protected final static String myVcsName = "Git"; //now scanner test executed only for git todo: create for all protected IdeaProjectTestFixture myProjectFixture; @SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors") - protected GitPlatformTest() { + protected VcsPlatformTest() { PlatformTestCase.initPlatformLangPrefix(); } diff --git a/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.java b/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/roots/VcsRootDetectorTest.java similarity index 94% rename from plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.java rename to platform/vcs-impl/testSrc/com/intellij/openapi/vcs/roots/VcsRootDetectorTest.java index 75e5a15edc5d..c24c9b9725ac 100644 --- a/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.java +++ b/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/roots/VcsRootDetectorTest.java @@ -13,15 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package git4idea.roots; +package com.intellij.openapi.vcs.roots; -import com.intellij.dvcs.test.Executor; -import com.intellij.dvcs.test.TestRepositoryUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vcs.VcsRoot; -import com.intellij.openapi.vcs.roots.VcsRootDetectInfo; -import com.intellij.openapi.vcs.roots.VcsRootDetector; +import com.intellij.openapi.vcs.VcsTestUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; @@ -32,13 +29,14 @@ import java.io.File; import java.io.IOException; import java.util.*; -import static com.intellij.dvcs.test.Executor.cd; +import static com.intellij.openapi.vcs.Executor.cd; +import static com.intellij.openapi.vcs.Executor.mkdir; /** * @author Nadya Zabrodina */ -public class GitRootDetectorTest extends GitPlatformTest { +public class VcsRootDetectorTest extends VcsPlatformTest { public void testNoRootsInProject() throws IOException { Map> map = new HashMap>(); @@ -59,8 +57,8 @@ public class GitRootDetectorTest extends GitPlatformTest { map.put("git", Arrays.asList("community")); map.put("content_roots", Collections.emptyList()); cd(myProjectRoot); - Executor.mkdir("src"); - Executor.mkdir(".idea"); + mkdir("src"); + mkdir(".idea"); doTest(map, myProjectRoot, Arrays.asList("community"), false, false); } @@ -72,11 +70,10 @@ public class GitRootDetectorTest extends GitPlatformTest { doTest(map, myProjectRoot, Arrays.asList(dirNames), false, false); } - public void testProjectUnderVcsAboveIt() throws IOException { String subdir = "insideRepo"; cd(myRepository); - Executor.mkdir(subdir); + mkdir(subdir); Map> map = new HashMap>(); map.put("git", Arrays.asList(myRepository.getName())); map.put("content_roots", Collections.emptyList()); @@ -85,7 +82,6 @@ public class GitRootDetectorTest extends GitPlatformTest { true, true); } - public void testIDEAProject() throws IOException { String[] names = {"community", "contrib", "."}; Map> map = new HashMap>(); @@ -94,7 +90,6 @@ public class GitRootDetectorTest extends GitPlatformTest { doTest(map, myProjectRoot, Arrays.asList(names), true, false); } - public void testOneAboveAndOneUnder() throws IOException { String[] names = {myRepository.getName() + "/community", "."}; Map> map = new HashMap>(); @@ -119,14 +114,13 @@ public class GitRootDetectorTest extends GitPlatformTest { doTest(map, myRepository, Arrays.asList(names), true, true); } - public void testMultipleAboveShouldBeDetectedAsOneAbove() throws IOException { Map> map = new HashMap>(); map.put("git", Arrays.asList(".", myRepository.getName())); map.put("content_roots", Collections.emptyList()); String subdir = "insideRepo"; cd(myRepository); - Executor.mkdir(subdir); + mkdir(subdir); VirtualFile vfile = myRepository.findChild(subdir); doTest(map, vfile, Arrays.asList(myRepository.getName()), true, true); } @@ -169,7 +163,7 @@ public class GitRootDetectorTest extends GitPlatformTest { } void assertRoots(Collection expectedRelativePaths, Collection actual) { - TestRepositoryUtil.assertEqualCollections(actual, toAbsolute(expectedRelativePaths, myProject)); + VcsTestUtil.assertEqualCollections(actual, toAbsolute(expectedRelativePaths, myProject)); } @NotNull diff --git a/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.java b/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/roots/VcsRootErrorsFinderTest.java similarity index 94% rename from plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.java rename to platform/vcs-impl/testSrc/com/intellij/openapi/vcs/roots/VcsRootErrorsFinderTest.java index b1bf00feabc1..9efe81347b6b 100644 --- a/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.java +++ b/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/roots/VcsRootErrorsFinderTest.java @@ -13,25 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package git4idea.roots; +package com.intellij.openapi.vcs.roots; -import com.intellij.dvcs.test.TestRepositoryUtil; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsDirectoryMapping; import com.intellij.openapi.vcs.VcsRootError; -import com.intellij.openapi.vcs.roots.VcsRootErrorsFinder; -import git4idea.GitVcs; +import com.intellij.openapi.vcs.VcsTestUtil; import org.jetbrains.annotations.NotNull; import java.io.IOException; import java.util.*; -import static git4idea.test.GitGTestUtil.toAbsolute; /** * @author Nadya Zabrodina */ -public class GitRootErrorsFinderTest extends GitPlatformTest { +public class VcsRootErrorsFinderTest extends VcsPlatformTest { static final String PROJECT = VcsDirectoryMapping.PROJECT_CONSTANT; @NotNull private ProjectLevelVcsManager myVcsManager; @@ -225,17 +222,17 @@ public class GitRootErrorsFinderTest extends GitPlatformTest { expected.addAll(extraAll(extraPaths)); } Collection actual = new VcsRootErrorsFinder(myProject).find(); - TestRepositoryUtil.assertEqualCollections(actual, expected); + VcsTestUtil.assertEqualCollections(actual, expected); } void addVcsRoots(@NotNull Collection relativeRoots) { for (String root : relativeRoots) { if (root.equals(PROJECT)) { - myVcsManager.setDirectoryMapping("", GitVcs.NAME); + myVcsManager.setDirectoryMapping("", myVcsName); } else { - String absoluteRoot = toAbsolute(root, myProject); - myVcsManager.setDirectoryMapping(absoluteRoot, GitVcs.NAME); + String absoluteRoot = VcsTestUtil.toAbsolute(root, myProject); + myVcsManager.setDirectoryMapping(absoluteRoot, myVcsName); } } } @@ -260,11 +257,12 @@ public class GitRootErrorsFinderTest extends GitPlatformTest { @NotNull VcsRootError unreg(@NotNull String path) { - return new VcsRootError(VcsRootError.Type.UNREGISTERED_ROOT, toAbsolute(path, myProject), GitVcs.NAME); + return new VcsRootError(VcsRootError.Type.UNREGISTERED_ROOT, VcsTestUtil.toAbsolute(path, myProject), myVcsName); } @NotNull VcsRootError extra(@NotNull String path) { - return new VcsRootError(VcsRootError.Type.EXTRA_MAPPING, PROJECT.equals(path) ? PROJECT : toAbsolute(path, myProject), GitVcs.NAME); + return new VcsRootError(VcsRootError.Type.EXTRA_MAPPING, PROJECT.equals(path) ? PROJECT : VcsTestUtil.toAbsolute(path, myProject), + myVcsName); } } diff --git a/plugins/git4idea/test-stepdefs/git4idea/CommitDetails.java b/plugins/git4idea/test-stepdefs/git4idea/CommitDetails.java index 76b9bebfc5b6..bd2d22aad6ba 100644 --- a/plugins/git4idea/test-stepdefs/git4idea/CommitDetails.java +++ b/plugins/git4idea/test-stepdefs/git4idea/CommitDetails.java @@ -23,8 +23,8 @@ import java.util.Collection; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static com.intellij.dvcs.test.Executor.echo; -import static com.intellij.dvcs.test.Executor.touch; +import static com.intellij.openapi.vcs.Executor.echo; +import static com.intellij.openapi.vcs.Executor.touch; import static git4idea.GitCucumberWorld.virtualCommits; import static git4idea.test.GitExecutor.git; import static org.junit.Assert.assertTrue; diff --git a/plugins/git4idea/test-stepdefs/git4idea/GitCherryPickStepdefs.java b/plugins/git4idea/test-stepdefs/git4idea/GitCherryPickStepdefs.java index 5aa6c58a9aee..f7504275d9df 100644 --- a/plugins/git4idea/test-stepdefs/git4idea/GitCherryPickStepdefs.java +++ b/plugins/git4idea/test-stepdefs/git4idea/GitCherryPickStepdefs.java @@ -43,7 +43,7 @@ import git4idea.log.GitContentRevisionFactory; import java.util.*; -import static com.intellij.dvcs.test.Executor.echo; +import static com.intellij.openapi.vcs.Executor.echo; import static git4idea.GitCucumberWorld.*; import static git4idea.test.GitExecutor.git; import static junit.framework.Assert.assertEquals; diff --git a/plugins/git4idea/test-stepdefs/git4idea/GitCucumberWorld.java b/plugins/git4idea/test-stepdefs/git4idea/GitCucumberWorld.java index f100ba54b72f..89dfd4481245 100644 --- a/plugins/git4idea/test-stepdefs/git4idea/GitCucumberWorld.java +++ b/plugins/git4idea/test-stepdefs/git4idea/GitCucumberWorld.java @@ -45,8 +45,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; -import static com.intellij.dvcs.test.Executor.cd; -import static com.intellij.dvcs.test.Executor.mkdir; +import static com.intellij.openapi.vcs.Executor.cd; +import static com.intellij.openapi.vcs.Executor.mkdir; import static org.junit.Assume.assumeTrue; /** diff --git a/plugins/git4idea/testFramework/git4idea/test/GitExecutor.java b/plugins/git4idea/testFramework/git4idea/test/GitExecutor.java index a1d9704b4ee2..d77d20c6a11c 100644 --- a/plugins/git4idea/testFramework/git4idea/test/GitExecutor.java +++ b/plugins/git4idea/testFramework/git4idea/test/GitExecutor.java @@ -15,7 +15,7 @@ */ package git4idea.test; -import com.intellij.dvcs.test.Executor; +import com.intellij.openapi.vcs.Executor; import git4idea.repo.GitRepository; import java.util.Arrays; diff --git a/plugins/git4idea/testFramework/git4idea/test/GitTestRunEnv.java b/plugins/git4idea/testFramework/git4idea/test/GitTestRunEnv.java index 437f0bf5e3d3..2a5109205547 100644 --- a/plugins/git4idea/testFramework/git4idea/test/GitTestRunEnv.java +++ b/plugins/git4idea/testFramework/git4idea/test/GitTestRunEnv.java @@ -15,8 +15,8 @@ */ package git4idea.test; -import com.intellij.dvcs.test.Executor; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vcs.Executor; import org.jetbrains.annotations.NotNull; import java.io.File; diff --git a/plugins/git4idea/testFramework/git4idea/test/GitTestUtil.java b/plugins/git4idea/testFramework/git4idea/test/GitTestUtil.java index 74eec538d1cd..e5db2c9adfbd 100644 --- a/plugins/git4idea/testFramework/git4idea/test/GitTestUtil.java +++ b/plugins/git4idea/testFramework/git4idea/test/GitTestUtil.java @@ -35,10 +35,10 @@ import java.io.File; import java.util.HashMap; import java.util.Map; -import static com.intellij.dvcs.test.Executor.cd; -import static com.intellij.dvcs.test.Executor.touch; -import static com.intellij.dvcs.test.TestRepositoryUtil.createDir; -import static com.intellij.dvcs.test.TestRepositoryUtil.createFile; +import static com.intellij.openapi.vcs.Executor.cd; +import static com.intellij.openapi.vcs.Executor.touch; +import static com.intellij.openapi.vcs.VcsTestUtil.createDir; +import static com.intellij.openapi.vcs.VcsTestUtil.createFile; import static git4idea.test.GitExecutor.git; import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNull; diff --git a/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.groovy b/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.groovy index e109fe74ce9f..8fb477b4532e 100644 --- a/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.groovy +++ b/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.groovy @@ -42,7 +42,7 @@ import org.junit.Test import java.util.regex.Matcher -import static com.intellij.dvcs.test.Executor.* +import static com.intellij.openapi.vcs.Executor.* import static git4idea.test.GitExecutor.cd import static git4idea.test.GitExecutor.git import static git4idea.test.GitScenarios.* diff --git a/plugins/git4idea/tests/git4idea/crlf/GitCrlfProblemsDetectorTest.groovy b/plugins/git4idea/tests/git4idea/crlf/GitCrlfProblemsDetectorTest.groovy index da7de5b7fefa..a5285e2bd0c3 100644 --- a/plugins/git4idea/tests/git4idea/crlf/GitCrlfProblemsDetectorTest.groovy +++ b/plugins/git4idea/tests/git4idea/crlf/GitCrlfProblemsDetectorTest.groovy @@ -24,7 +24,7 @@ import org.junit.Before import org.junit.Ignore import org.junit.Test -import static com.intellij.dvcs.test.Executor.cd +import static com.intellij.openapi.vcs.Executor.cd import static git4idea.test.GitExecutor.git import static org.junit.Assert.assertFalse import static org.junit.Assert.assertTrue diff --git a/plugins/git4idea/tests/git4idea/repo/GitConfigTest.java b/plugins/git4idea/tests/git4idea/repo/GitConfigTest.java index fa68213da981..f0690e354d56 100644 --- a/plugins/git4idea/tests/git4idea/repo/GitConfigTest.java +++ b/plugins/git4idea/tests/git4idea/repo/GitConfigTest.java @@ -17,9 +17,9 @@ package git4idea.repo; import com.google.common.base.Function; import com.google.common.collect.Collections2; -import com.intellij.dvcs.test.TestRepositoryUtil; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vcs.VcsTestUtil; import git4idea.GitBranch; import git4idea.GitLocalBranch; import git4idea.GitRemoteBranch; @@ -40,23 +40,23 @@ public class GitConfigTest { @DataProvider(name = "remote") public Object[][] loadRemotes() throws IOException { - return TestRepositoryUtil.loadConfigData(getTestDataFolder("remote")); + return VcsTestUtil.loadConfigData(getTestDataFolder("remote")); } @DataProvider(name = "branch") public Object[][] loadBranches() throws IOException { - return TestRepositoryUtil.loadConfigData(getTestDataFolder("branch")); + return VcsTestUtil.loadConfigData(getTestDataFolder("branch")); } private static File getTestDataFolder(String subfolder) { - File testData = TestRepositoryUtil.getTestDataFolder(); + File testData = VcsTestUtil.getTestDataFolder(); return new File(new File(testData, "config"), subfolder); } @Test(dataProvider = "remote") public void testRemotes(String testName, File configFile, File resultFile) throws IOException { GitConfig config = GitConfig.read(new GitTestPlatformFacade(), configFile); - TestRepositoryUtil.assertEqualCollections(config.parseRemotes(), readRemoteResults(resultFile)); + VcsTestUtil.assertEqualCollections(config.parseRemotes(), readRemoteResults(resultFile)); } @Test(dataProvider = "branch") @@ -77,7 +77,7 @@ public class GitConfigTest { } }); - TestRepositoryUtil.assertEqualCollections( + VcsTestUtil.assertEqualCollections( GitConfig.read(new GitTestPlatformFacade(), configFile).parseTrackInfos(localBranches, remoteBranches), expectedInfos); } diff --git a/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderTest.groovy b/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderTest.groovy index 6fc661d2be65..e1fa21e3ecec 100644 --- a/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderTest.groovy +++ b/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderTest.groovy @@ -15,9 +15,9 @@ */ package git4idea.repo -import com.intellij.dvcs.test.TestRepositoryUtil import com.intellij.openapi.application.PluginPathManager import com.intellij.openapi.util.io.FileUtil +import com.intellij.openapi.vcs.VcsTestUtil import com.intellij.util.Processor import git4idea.GitBranch import git4idea.branch.GitBranchesCollection @@ -88,7 +88,7 @@ public class GitRepositoryReaderTest extends GitLightTest { } private static void assertBranches(Collection actualBranches, Collection expectedBranches) { - TestRepositoryUtil.assertEqualCollections(actualBranches, expectedBranches, new TestRepositoryUtil.EqualityChecker() { + VcsTestUtil.assertEqualCollections(actualBranches, expectedBranches, new VcsTestUtil.EqualityChecker() { @Override public boolean areEqual(@NotNull GitBranch actual, @NotNull GitTestBranch expected) { return branchesAreEqual(actual, expected); diff --git a/plugins/github/test/org/jetbrains/plugins/github/GithubCreatePullRequestTestBase.java b/plugins/github/test/org/jetbrains/plugins/github/GithubCreatePullRequestTestBase.java index 741ccd6e08f4..643c3d2db5f0 100644 --- a/plugins/github/test/org/jetbrains/plugins/github/GithubCreatePullRequestTestBase.java +++ b/plugins/github/test/org/jetbrains/plugins/github/GithubCreatePullRequestTestBase.java @@ -33,7 +33,7 @@ import org.jetbrains.plugins.github.util.GithubUtil; import java.util.Random; -import static com.intellij.dvcs.test.Executor.cd; +import static com.intellij.openapi.vcs.Executor.cd; import static git4idea.test.GitExecutor.git; /** diff --git a/plugins/github/test/org/jetbrains/plugins/github/GithubShareProjectTest.java b/plugins/github/test/org/jetbrains/plugins/github/GithubShareProjectTest.java index fe2f40a82593..c4063629cbbe 100644 --- a/plugins/github/test/org/jetbrains/plugins/github/GithubShareProjectTest.java +++ b/plugins/github/test/org/jetbrains/plugins/github/GithubShareProjectTest.java @@ -9,7 +9,7 @@ import org.jetbrains.plugins.github.util.GithubAuthData; import java.io.IOException; -import static com.intellij.dvcs.test.Executor.cd; +import static com.intellij.openapi.vcs.Executor.cd; import static git4idea.test.GitExecutor.git; /** diff --git a/plugins/hg4idea/testSrc/hg4idea/test/HgEncodingTest.java b/plugins/hg4idea/testSrc/hg4idea/test/HgEncodingTest.java index 9c2d0648ee63..1e5e3ee9f6a3 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/HgEncodingTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/HgEncodingTest.java @@ -25,8 +25,8 @@ import org.zmlx.hg4idea.execution.HgCommandException; import java.util.List; -import static com.intellij.dvcs.test.Executor.cd; -import static com.intellij.dvcs.test.Executor.echo; +import static com.intellij.openapi.vcs.Executor.cd; +import static com.intellij.openapi.vcs.Executor.echo; /** * @author Nadya Zabrodina diff --git a/plugins/hg4idea/testSrc/hg4idea/test/HgExecutor.java b/plugins/hg4idea/testSrc/hg4idea/test/HgExecutor.java index 02a74da03b2c..db23fda54740 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/HgExecutor.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/HgExecutor.java @@ -15,10 +15,10 @@ */ package hg4idea.test; -import com.intellij.dvcs.test.Executor; import com.intellij.openapi.application.PluginPathManager; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.vcs.Executor; import org.jetbrains.annotations.NotNull; import java.io.File; diff --git a/plugins/hg4idea/testSrc/hg4idea/test/HgPlatformTest.java b/plugins/hg4idea/testSrc/hg4idea/test/HgPlatformTest.java index 4e3af6c0d524..95c834c004b6 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/HgPlatformTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/HgPlatformTest.java @@ -32,8 +32,8 @@ import org.zmlx.hg4idea.util.HgUtil; import java.io.File; import java.io.IOException; -import static com.intellij.dvcs.test.Executor.cd; -import static com.intellij.dvcs.test.Executor.touch; +import static com.intellij.openapi.vcs.Executor.cd; +import static com.intellij.openapi.vcs.Executor.touch; import static hg4idea.test.HgExecutor.hg; /** diff --git a/plugins/hg4idea/testSrc/hg4idea/test/annotation/HgAnnotationTest.java b/plugins/hg4idea/testSrc/hg4idea/test/annotation/HgAnnotationTest.java index 8a0fa9d9f01b..86487916a687 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/annotation/HgAnnotationTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/annotation/HgAnnotationTest.java @@ -14,8 +14,8 @@ import java.util.Arrays; import java.util.Date; import java.util.List; -import static com.intellij.dvcs.test.Executor.cd; -import static com.intellij.dvcs.test.Executor.echo; +import static com.intellij.openapi.vcs.Executor.cd; +import static com.intellij.openapi.vcs.Executor.echo; import static hg4idea.test.HgExecutor.hg; /** diff --git a/plugins/hg4idea/testSrc/hg4idea/test/config/HgConfigTest.java b/plugins/hg4idea/testSrc/hg4idea/test/config/HgConfigTest.java index 62c0abaa21ad..8b69c2d74ed4 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/config/HgConfigTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/config/HgConfigTest.java @@ -1,7 +1,7 @@ package hg4idea.test.config; -import com.intellij.dvcs.test.TestRepositoryUtil; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.vcs.VcsTestUtil; import hg4idea.test.HgPlatformTest; import org.zmlx.hg4idea.util.HgUtil; @@ -10,7 +10,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collection; -import static com.intellij.dvcs.test.Executor.cd; +import static com.intellij.openapi.vcs.Executor.cd; /** * @author Nadya Zabrodina @@ -63,7 +63,7 @@ public class HgConfigTest extends HgPlatformTest { updateRepoConfig(myProject, myChildRepo); final Collection paths = HgUtil.getRepositoryPaths(myProject, myChildRepo); final Collection expectedPaths = Arrays.asList(FileUtil.toSystemDependentName(myRepository.getPath()), path1, path2, path3); - TestRepositoryUtil.assertEqualCollections(paths,expectedPaths); + VcsTestUtil.assertEqualCollections(paths, expectedPaths); } public void testLargeExtensionInClonedRepo() throws IOException { diff --git a/plugins/hg4idea/testSrc/hg4idea/test/history/HgBrowseChangesTest.java b/plugins/hg4idea/testSrc/hg4idea/test/history/HgBrowseChangesTest.java index 1f7bf027ad75..5b5782731144 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/history/HgBrowseChangesTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/history/HgBrowseChangesTest.java @@ -27,8 +27,8 @@ import org.zmlx.hg4idea.provider.HgRepositoryLocation; import java.text.ParseException; import java.util.List; -import static com.intellij.dvcs.test.Executor.cd; -import static com.intellij.dvcs.test.Executor.touch; +import static com.intellij.openapi.vcs.Executor.cd; +import static com.intellij.openapi.vcs.Executor.touch; import static hg4idea.test.HgExecutor.hg; /** diff --git a/plugins/hg4idea/testSrc/hg4idea/test/history/HgHistoryTest.java b/plugins/hg4idea/testSrc/hg4idea/test/history/HgHistoryTest.java index 81c0c219e779..0af39b095804 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/history/HgHistoryTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/history/HgHistoryTest.java @@ -28,7 +28,7 @@ import org.zmlx.hg4idea.util.HgUtil; import java.io.File; import java.util.List; -import static com.intellij.dvcs.test.Executor.*; +import static com.intellij.openapi.vcs.Executor.*; import static hg4idea.test.HgExecutor.hg; /** diff --git a/plugins/hg4idea/testSrc/hg4idea/test/history/HgLogTest.java b/plugins/hg4idea/testSrc/hg4idea/test/history/HgLogTest.java index d6f9d7b2e7bc..b57f0efeb73c 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/history/HgLogTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/history/HgLogTest.java @@ -11,8 +11,8 @@ import org.zmlx.hg4idea.execution.HgCommandException; import java.util.List; -import static com.intellij.dvcs.test.Executor.cd; -import static com.intellij.dvcs.test.Executor.touch; +import static com.intellij.openapi.vcs.Executor.cd; +import static com.intellij.openapi.vcs.Executor.touch; import static hg4idea.test.HgExecutor.hg; /** diff --git a/plugins/hg4idea/testSrc/hg4idea/test/merge/HgMergeProviderTest.java b/plugins/hg4idea/testSrc/hg4idea/test/merge/HgMergeProviderTest.java index 35e65e9a1822..1fc377d4f6b8 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/merge/HgMergeProviderTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/merge/HgMergeProviderTest.java @@ -27,7 +27,7 @@ import org.zmlx.hg4idea.HgVcs; import java.io.IOException; -import static com.intellij.dvcs.test.Executor.*; +import static com.intellij.openapi.vcs.Executor.*; import static hg4idea.test.HgExecutor.hg; import static hg4idea.test.HgExecutor.updateProject; diff --git a/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRealRepositoryReaderTest.java b/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRealRepositoryReaderTest.java index 642e125f1f11..73a1a58e28b8 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRealRepositoryReaderTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRealRepositoryReaderTest.java @@ -16,7 +16,7 @@ package hg4idea.test.repo; import com.intellij.dvcs.repo.Repository; -import com.intellij.dvcs.test.TestRepositoryUtil; +import com.intellij.openapi.vcs.VcsTestUtil; import hg4idea.test.HgPlatformTest; import org.jetbrains.annotations.NotNull; import org.zmlx.hg4idea.repo.HgRepositoryReader; @@ -25,7 +25,7 @@ import org.zmlx.hg4idea.util.HgUtil; import java.io.File; import java.util.Arrays; -import static com.intellij.dvcs.test.Executor.*; +import static com.intellij.openapi.vcs.Executor.*; import static hg4idea.test.HgExecutor.hg; /** @@ -58,17 +58,17 @@ public class HgRealRepositoryReaderTest extends HgPlatformTest { } public void testBranches() { - TestRepositoryUtil.assertEqualCollections(HgUtil.getNamesWithoutHashes(myRepositoryReader.readBranches()), + VcsTestUtil.assertEqualCollections(HgUtil.getNamesWithoutHashes(myRepositoryReader.readBranches()), Arrays.asList("default", "branchA", "branchB")); } public void testTags() { - TestRepositoryUtil.assertEqualCollections(HgUtil.getNamesWithoutHashes(myRepositoryReader.readTags()), + VcsTestUtil.assertEqualCollections(HgUtil.getNamesWithoutHashes(myRepositoryReader.readTags()), Arrays.asList("tag1", "tag2")); } public void testLocalTags() { - TestRepositoryUtil.assertEqualCollections(HgUtil.getNamesWithoutHashes(myRepositoryReader.readLocalTags()), + VcsTestUtil.assertEqualCollections(HgUtil.getNamesWithoutHashes(myRepositoryReader.readLocalTags()), Arrays.asList("localTag")); } @@ -78,7 +78,7 @@ public class HgRealRepositoryReaderTest extends HgPlatformTest { } public void testBookmarks() { - TestRepositoryUtil.assertEqualCollections(HgUtil.getNamesWithoutHashes(myRepositoryReader.readBookmarks()), + VcsTestUtil.assertEqualCollections(HgUtil.getNamesWithoutHashes(myRepositoryReader.readBookmarks()), Arrays.asList("A_BookMark", "B_BookMark", "C_BookMark")); } diff --git a/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRepositoryReaderTest.java b/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRepositoryReaderTest.java index 872951ca5be8..c770de22cd42 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRepositoryReaderTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRepositoryReaderTest.java @@ -15,9 +15,9 @@ */ package hg4idea.test.repo; -import com.intellij.dvcs.test.TestRepositoryUtil; import com.intellij.openapi.application.PluginPathManager; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.vcs.VcsTestUtil; import hg4idea.test.HgPlatformTest; import org.jetbrains.annotations.NotNull; import org.zmlx.hg4idea.repo.HgRepositoryReader; @@ -81,12 +81,12 @@ public class HgRepositoryReaderTest extends HgPlatformTest { public void testBranches() { Collection branches = HgUtil.getNamesWithoutHashes(myRepositoryReader.readBranches()); - TestRepositoryUtil.assertEqualCollections(branches, myBranches); + VcsTestUtil.assertEqualCollections(branches, myBranches); } public void testBookmarks() { - Collection bookmarks = HgUtil.getNamesWithoutHashes(myRepositoryReader.readBookmarks()); - TestRepositoryUtil.assertEqualCollections(bookmarks, myBookmarks); + Collection bookmarks = myRepositoryReader.readBookmarks(); + VcsTestUtil.assertEqualCollections(bookmarks, myBookmarks); } public void testTags() {