@NotNull
 public static GitRepository registerRepo(Project project, String root) {
   ProjectLevelVcsManagerImpl vcsManager =
       (ProjectLevelVcsManagerImpl) ProjectLevelVcsManager.getInstance(project);
   vcsManager.setDirectoryMapping(root, GitVcs.NAME);
   VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(new File(root));
   assertFalse(vcsManager.getAllVcsRoots().length == 0);
   GitRepository repository = GitUtil.getRepositoryManager(project).getRepositoryForRoot(file);
   assertNotNull("Couldn't find repository for root " + root, repository);
   return repository;
 }
  @Before
  public void setUp() throws Throwable {
    IdeaTestApplication.getInstance();

    myTestName = createTestName();
    myProjectFixture =
        IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(myTestName).getFixture();

    edt(
        new ThrowableRunnable<Exception>() {
          @Override
          public void run() throws Exception {
            myProjectFixture.setUp();
          }
        });

    myProject = myProjectFixture.getProject();

    myProjectRoot = myProject.getBasePath();
    myProjectDir = myProject.getBaseDir();
    myTestRoot = myProjectRoot;

    myGit = ServiceManager.getService(myProject, Git.class);
    mySettings = GitVcsSettings.getInstance(myProject);
    mySettings.getAppSettings().setPathToGit(GitExecutor.PathHolder.GIT_EXECUTABLE);

    // dynamic overriding is used instead of making it in plugin.xml,
    // because MockVcsHelper is not ready to be a full featured implementation for all tests.
    myVcsHelper =
        GitTestUtil.overrideService(myProject, AbstractVcsHelper.class, MockVcsHelper.class);
    myChangeListManager = ChangeListManagerImpl.getInstanceImpl(myProject);
    myNotificator = (TestVcsNotifier) ServiceManager.getService(myProject, VcsNotifier.class);
    myVcs = GitVcs.getInstance(myProject);
    myRepositoryManager = GitUtil.getRepositoryManager(myProject);

    virtualCommits = new GitTestVirtualCommitsHolder();
    myAsyncTasks = new ArrayList<>();

    cd(myProjectRoot);
    myRepository = GitTestUtil.createRepository(myProject, myProjectRoot);

    ProjectLevelVcsManagerImpl vcsManager =
        (ProjectLevelVcsManagerImpl) ProjectLevelVcsManager.getInstance(myProject);
    AbstractVcs vcs = vcsManager.findVcsByName("Git");
    Assert.assertEquals(1, vcsManager.getRootsUnderVcs(vcs).length);

    GitTestUtil.assumeSupportedGitVersion(myVcs);
    LOG.info(getStartTestMarker());
  }
  private RemoteRevisionsCache(final Project project) {
    myProject = project;
    myLock = new Object();

    myRemoteRevisionsNumbersCache = new RemoteRevisionsNumbersCache(myProject);
    myRemoteRevisionsStateCache = new RemoteRevisionsStateCache(myProject);

    myChangeDecorator = new RemoteStatusChangeNodeDecorator(this);

    myVcsManager = ProjectLevelVcsManager.getInstance(project);
    myVcsManager.addVcsListener(this);
    myKinds = new HashMap<String, RemoteDifferenceStrategy>();
    Disposer.register(
        project,
        new Disposable() {
          public void dispose() {
            myVcsManager.removeVcsListener(RemoteRevisionsCache.this);
          }
        });
    final VcsConfiguration vcsConfiguration = VcsConfiguration.getInstance(myProject);
    myControlledCycle =
        new ControlledCycle(
            project,
            new Getter<Boolean>() {
              @Override
              public Boolean get() {
                final boolean shouldBeDone =
                    vcsConfiguration.isChangedOnServerEnabled() && myVcsManager.hasActiveVcss();

                if (shouldBeDone) {
                  boolean somethingChanged = myRemoteRevisionsNumbersCache.updateStep();
                  somethingChanged |= myRemoteRevisionsStateCache.updateStep();
                  if (somethingChanged) {
                    myProject.getMessageBus().syncPublisher(REMOTE_VERSION_CHANGED).run();
                  }
                }
                return shouldBeDone;
              }
            },
            "Finishing \"changed on server\" update",
            DEFAULT_REFRESH_INTERVAL);

    updateRoots();

    if ((!myProject.isDefault()) && vcsConfiguration.isChangedOnServerEnabled()) {
      ((ProjectLevelVcsManagerImpl) myVcsManager)
          .addInitializationRequest(
              VcsInitObject.REMOTE_REVISIONS_CACHE,
              new Runnable() {
                public void run() {
                  // do not start if there're no vcses
                  if (!myVcsManager.hasActiveVcss() || !vcsConfiguration.isChangedOnServerEnabled())
                    return;
                  myControlledCycle.startIfNotStarted(-1);
                }
              });
    }
  }
  /** call in setUp */
  public DuringChangeListManagerUpdateTestScheme(final Project project, final String tmpDirPath) {
    final MockAbstractVcs vcs = new MockAbstractVcs(project);
    myChangeProvider = new MockDelayingChangeProvider();
    vcs.setChangeProvider(myChangeProvider);

    final File mockVcsRoot = new File(tmpDirPath, "mock");
    mockVcsRoot.mkdir();
    final VirtualFile vRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(mockVcsRoot);

    final ProjectLevelVcsManagerImpl projectLevelVcsManager =
        (ProjectLevelVcsManagerImpl) ProjectLevelVcsManager.getInstance(project);
    projectLevelVcsManager.registerVcs(vcs);
    // projectLevelVcsManager.setDirectoryMapping(mockVcsRoot.getAbsolutePath(), vcs.getName());
    final ArrayList<VcsDirectoryMapping> list =
        new ArrayList<VcsDirectoryMapping>(projectLevelVcsManager.getDirectoryMappings());
    list.add(new VcsDirectoryMapping(vRoot.getPath(), vcs.getName()));
    projectLevelVcsManager.setDirectoryMappings(list);

    AbstractVcs vcsFound = projectLevelVcsManager.findVcsByName(vcs.getName());
    final VirtualFile[] roots = projectLevelVcsManager.getRootsUnderVcs(vcsFound);
    assert roots.length == 1
        : Arrays.asList(roots)
            + "; "
            + vcs.getName()
            + "; "
            + Arrays.toString(AllVcses.getInstance(project).getAll());

    myDirtyScopeManager = VcsDirtyScopeManager.getInstance(project);
    myClManager = ChangeListManager.getInstance(project);
  }
 @Override
 protected void tearDown() throws Exception {
   try {
     getExtensionPoint().unregisterExtension(myExtension);
     myVcsManager.unregisterVcs(myVcs);
     for (File file : myFilesToDelete) {
       delete(file);
     }
     myProjectFixture.tearDown();
   } finally {
     super.tearDown();
   }
 }
Beispiel #6
0
  @Override
  public void setUp() throws Exception {
    super.setUp();

    myBranchVcsRoot = new File(myTempDirFixture.getTempDirPath(), "branch");
    myBranchVcsRoot.mkdir();

    myProjectLevelVcsManager =
        (ProjectLevelVcsManagerImpl) ProjectLevelVcsManager.getInstance(myProject);
    myProjectLevelVcsManager.setDirectoryMapping(
        myBranchVcsRoot.getAbsolutePath(), SvnVcs.VCS_NAME);

    //    AbstractVcs vcsFound = myProjectLevelVcsManager.findVcsByName(SvnVcs.VCS_NAME);
    //    Assert.assertEquals(1, myProjectLevelVcsManager.getRootsUnderVcs(vcsFound).length);
  }
  @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);
    myProjectRoot.refresh(false, true);
    myRepository = myProjectRoot.findChild(myRepositoryFolderName);
    myVcs = new MockAbstractVcs(myProject);
    myVcsManager = (ProjectLevelVcsManagerImpl) ProjectLevelVcsManager.getInstance(myProject);
    ExtensionPoint<VcsRootChecker> point = getExtensionPoint();
    myExtension =
        new VcsRootChecker() {
          @Override
          public VcsKey getSupportedVcs() {
            return myVcs.getKeyInstanceMethod();
          }

          @Override
          public boolean isRoot(@NotNull String path) {
            return new File(path, DOT_MOCK).exists();
          }

          @Override
          public boolean isVcsDir(@Nullable String path) {
            return path != null && path.toLowerCase().endsWith(DOT_MOCK);
          }
        };
    point.registerExtension(myExtension);
    myVcsManager.registerVcs(myVcs);
    myVcsName = myVcs.getName();
    myRepository.refresh(false, true);
  }