Search in sources :

Example 1 with MockChangeListManagerGate

use of com.intellij.testFramework.vcs.MockChangeListManagerGate in project intellij-community by JetBrains.

the class GitChangeProviderTest method getChanges.

/**
   * Marks the given files dirty in myDirtyScope, gets changes from myChangeProvider and groups the changes in the map.
   * Assumes that only one change for a file has happened.
   */
protected Map<FilePath, Change> getChanges(VirtualFile... changedFiles) throws VcsException {
    final List<FilePath> changedPaths = ObjectsConvertor.vf2fp(Arrays.asList(changedFiles));
    // get changes
    MockChangelistBuilder builder = new MockChangelistBuilder();
    myChangeProvider.getChanges(myDirtyScope, builder, new EmptyProgressIndicator(), new MockChangeListManagerGate(ChangeListManager.getInstance(myProject)));
    List<Change> changes = builder.getChanges();
    // get changes for files
    final Map<FilePath, Change> result = new HashMap<>();
    for (Change change : changes) {
        VirtualFile file = change.getVirtualFile();
        FilePath filePath = null;
        if (file == null) {
            // if a file was deleted, just find the reference in the original list of files and use it. 
            String path = change.getBeforeRevision().getFile().getPath();
            for (FilePath fp : changedPaths) {
                if (FileUtil.pathsEqual(fp.getPath(), path)) {
                    filePath = fp;
                    break;
                }
            }
        } else {
            filePath = VcsUtil.getFilePath(file);
        }
        result.put(filePath, change);
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MockChangeListManagerGate(com.intellij.testFramework.vcs.MockChangeListManagerGate) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) HashMap(java.util.HashMap) Change(com.intellij.openapi.vcs.changes.Change) MockChangelistBuilder(com.intellij.testFramework.vcs.MockChangelistBuilder)

Example 2 with MockChangeListManagerGate

use of com.intellij.testFramework.vcs.MockChangeListManagerGate in project intellij-community by JetBrains.

the class SvnTestCase method setUp.

@Before
public void setUp() throws Exception {
    System.out.println("Native client for status: " + isUseNativeAcceleration());
    String property = System.getProperty("svn.test.data.directory");
    if (!StringUtil.isEmpty(property)) {
        myTestDataDir = property;
    }
    UIUtil.invokeAndWaitIfNeeded((Runnable) () -> {
        try {
            final IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory();
            myTempDirFixture = fixtureFactory.createTempDirTestFixture();
            myTempDirFixture.setUp();
            myRepoRoot = new File(myTempDirFixture.getTempDirPath(), "svnroot");
            assert myRepoRoot.mkdir() || myRepoRoot.isDirectory() : myRepoRoot;
            myPluginRoot = new File(PluginPathManager.getPluginHomePath("svn4idea"));
            if (!myPluginRoot.isDirectory()) {
                Class aClass = SvnTestCase.class;
                String rootPath = PathManager.getResourceRoot(aClass, "/" + aClass.getName().replace('.', '/') + ".class");
                myPluginRoot = new File(rootPath).getParentFile().getParentFile().getParentFile();
            }
            File svnBinDir = new File(myPluginRoot, getTestDataDir() + "/svn/bin");
            File svnExecutable = null;
            if (SystemInfo.isWindows) {
                svnExecutable = new File(svnBinDir, "windows/svn.exe");
            } else if (SystemInfo.isLinux) {
                svnExecutable = new File(svnBinDir, "linux/svn");
            } else if (SystemInfo.isMac) {
                svnExecutable = new File(svnBinDir, "mac/svn");
            }
            assertTrue("No Subversion executable was found: " + svnExecutable + ", " + SystemInfo.OS_NAME, svnExecutable != null && svnExecutable.canExecute());
            myClientBinaryPath = svnExecutable.getParentFile();
            myRunner = SystemInfo.isMac ? createClientRunner(Collections.singletonMap("DYLD_LIBRARY_PATH", myClientBinaryPath.getPath())) : createClientRunner();
            ZipUtil.extract(new File(myPluginRoot, getTestDataDir() + "/svn/newrepo.zip"), myRepoRoot, null);
            myWcRoot = new File(myTempDirFixture.getTempDirPath(), myWcRootName);
            assert myWcRoot.mkdir() || myWcRoot.isDirectory() : myWcRoot;
            myRepoUrl = (SystemInfo.isWindows ? "file:///" : "file://") + FileUtil.toSystemIndependentName(myRepoRoot.getPath());
            verify(runSvn("co", myRepoUrl, myWcRoot.getPath()));
            initProject(myWcRoot, SvnTestCase.this.getTestName());
            activateVCS(SvnVcs.VCS_NAME);
            myGate = new MockChangeListManagerGate(ChangeListManager.getInstance(myProject));
            ((StartupManagerImpl) StartupManager.getInstance(myProject)).runPostStartupActivities();
            refreshSvnMappingsSynchronously();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    // there should be kind-a waiting for after change list manager finds all changes and runs inner refresh of copies in the above method
    if (myInitChangeListManager) {
        ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
        VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
        changeListManager.ensureUpToDate(false);
    }
}
Also used : MockChangeListManagerGate(com.intellij.testFramework.vcs.MockChangeListManagerGate) IdeaTestFixtureFactory(com.intellij.testFramework.fixtures.IdeaTestFixtureFactory) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File) VcsException(com.intellij.openapi.vcs.VcsException) IOException(java.io.IOException) Before(org.junit.Before)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 MockChangeListManagerGate (com.intellij.testFramework.vcs.MockChangeListManagerGate)2 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)1 VcsException (com.intellij.openapi.vcs.VcsException)1 Change (com.intellij.openapi.vcs.changes.Change)1 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)1 IdeaTestFixtureFactory (com.intellij.testFramework.fixtures.IdeaTestFixtureFactory)1 MockChangelistBuilder (com.intellij.testFramework.vcs.MockChangelistBuilder)1 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1