mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix GitConfigTest: use PlatformFacade to get plugin.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package git4idea;
|
||||
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptor;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
@@ -27,6 +28,7 @@ import com.intellij.openapi.vcs.changes.ChangeListManager;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import git4idea.repo.GitRepositoryManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* IntelliJ code provides a lot of statical bindings to the interested pieces of data. For example we need to execute code
|
||||
@@ -80,4 +82,8 @@ public interface PlatformFacade {
|
||||
|
||||
@NotNull
|
||||
GitRepositoryManager getRepositoryManager(@NotNull Project project);
|
||||
|
||||
@Nullable
|
||||
IdeaPluginDescriptor getPluginByClassName(@NotNull String name);
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package git4idea;
|
||||
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptor;
|
||||
import com.intellij.ide.plugins.PluginManager;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
@@ -29,6 +31,7 @@ import com.intellij.openapi.vcs.changes.ChangeListManager;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import git4idea.repo.GitRepositoryManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Kirill Likhodedov
|
||||
@@ -100,6 +103,12 @@ public class PlatformFacadeImpl implements PlatformFacade {
|
||||
return ServiceManager.getService(project, GitRepositoryManager.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IdeaPluginDescriptor getPluginByClassName(@NotNull String name) {
|
||||
return PluginManager.getPlugin(PluginManager.getPluginByClassName(name));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AbstractVcs getVcs(@NotNull Project project) {
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
package git4idea.repo;
|
||||
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptor;
|
||||
import com.intellij.ide.plugins.PluginManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import git4idea.PlatformFacade;
|
||||
import org.ini4j.Ini;
|
||||
import org.ini4j.Profile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -102,7 +102,7 @@ public class GitConfig {
|
||||
* If it has valid format in general, but some sections are invalid, it skips invalid sections, but reports an error.
|
||||
*/
|
||||
@NotNull
|
||||
static GitConfig read(@NotNull File configFile) {
|
||||
static GitConfig read(@NotNull PlatformFacade platformFacade, @NotNull File configFile) {
|
||||
Ini ini = new Ini();
|
||||
ini.getConfig().setMultiOption(true); // duplicate keys (e.g. url in [remote])
|
||||
ini.getConfig().setTree(false); // don't need tree structure: it corrupts url in section name (e.g. [url "http://github.com/"]
|
||||
@@ -114,7 +114,7 @@ public class GitConfig {
|
||||
return new GitConfig(Collections.<GitRemote>emptyList(), Collections.<GitBranchTrackInfo>emptyList());
|
||||
}
|
||||
|
||||
IdeaPluginDescriptor plugin = PluginManager.getPlugin(PluginManager.getPluginByClassName(GitConfig.class.getName()));
|
||||
IdeaPluginDescriptor plugin = platformFacade.getPluginByClassName(GitConfig.class.getName());
|
||||
ClassLoader classLoader = plugin == null ? null : plugin.getPluginClassLoader(); // null if IDEA is started from IDEA
|
||||
|
||||
Collection<GitRemote> gitRemotes = parseRemotes(ini, classLoader);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package git4idea.repo;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
@@ -26,6 +27,7 @@ import com.intellij.util.messages.MessageBus;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import git4idea.GitBranch;
|
||||
import git4idea.GitUtil;
|
||||
import git4idea.PlatformFacade;
|
||||
import git4idea.branch.GitBranchesCollection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -231,7 +233,7 @@ public class GitRepositoryImpl implements GitRepository, Disposable {
|
||||
|
||||
private void updateConfig() {
|
||||
File configFile = new File(VfsUtil.virtualToIoFile(myGitDir), "config");
|
||||
myConfig = GitConfig.read(configFile);
|
||||
myConfig = GitConfig.read(ServiceManager.getService(PlatformFacade.class), configFile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,7 @@ package git4idea.repo;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import git4idea.test.GitTestPlatformFacade;
|
||||
import git4idea.test.GitTestUtil;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
@@ -47,13 +48,13 @@ public class GitConfigTest {
|
||||
|
||||
@Test(dataProvider = "remote")
|
||||
public void testRemotes(String testName, File configFile, File resultFile) throws IOException {
|
||||
GitConfig config = GitConfig.read(configFile);
|
||||
GitConfig config = GitConfig.read(new GitTestPlatformFacade(), configFile);
|
||||
GitTestUtil.assertEqualCollections(config.getRemotes(), readRemoteResults(resultFile));
|
||||
}
|
||||
|
||||
@Test(dataProvider = "branch")
|
||||
public void testBranches(String testName, File configFile, File resultFile) throws IOException {
|
||||
GitConfig config = GitConfig.read(configFile);
|
||||
GitConfig config = GitConfig.read(new GitTestPlatformFacade(), configFile);
|
||||
GitTestUtil.assertEqualCollections(config.getBranchTrackInfos(), readBranchResults(resultFile));
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package git4idea.test;
|
||||
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptor;
|
||||
import com.intellij.mock.MockLocalFileSystem;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -32,6 +33,7 @@ import git4idea.PlatformFacade;
|
||||
import git4idea.repo.GitRepositoryManager;
|
||||
import git4idea.tests.TestDialogManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -137,6 +139,12 @@ public class GitTestPlatformFacade implements PlatformFacade {
|
||||
return myRepositoryManager;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IdeaPluginDescriptor getPluginByClassName(@NotNull String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AbstractVcs getVcs(@NotNull Project project) {
|
||||
|
||||
Reference in New Issue
Block a user