Search in sources :

Example 16 with ProjectLevelVcsManager

use of com.intellij.openapi.vcs.ProjectLevelVcsManager in project intellij-community by JetBrains.

the class ModuleDefaultVcsRootPolicy method getDefaultVcsRoots.

@Override
@NotNull
public Collection<VirtualFile> getDefaultVcsRoots(@NotNull NewMappings mappingList, @NotNull String vcsName) {
    Set<VirtualFile> result = newHashSet();
    final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
    if (myBaseDir != null && vcsName.equals(mappingList.getVcsFor(myBaseDir))) {
        final AbstractVcs vcsFor = vcsManager.getVcsFor(myBaseDir);
        if (vcsFor != null && vcsName.equals(vcsFor.getName())) {
            result.add(myBaseDir);
        }
    }
    if (ProjectKt.isDirectoryBased(myProject) && myBaseDir != null) {
        final VirtualFile ideaDir = ProjectKt.getStateStore(myProject).getDirectoryStoreFile();
        if (ideaDir != null) {
            final AbstractVcs vcsFor = vcsManager.getVcsFor(ideaDir);
            if (vcsFor != null && vcsName.equals(vcsFor.getName())) {
                result.add(ideaDir);
            }
        }
    }
    // assertion for read access inside
    Module[] modules = ReadAction.compute(myModuleManager::getModules);
    for (Module module : modules) {
        final VirtualFile[] files = ModuleRootManager.getInstance(module).getContentRoots();
        for (VirtualFile file : files) {
            // if we're currently processing moduleAdded notification, getModuleForFile() will return null, so we pass the module
            // explicitly (we know it anyway)
            VcsDirectoryMapping mapping = mappingList.getMappingFor(file, module);
            final String mappingVcs = mapping != null ? mapping.getVcs() : null;
            if (vcsName.equals(mappingVcs) && file.isDirectory()) {
                result.add(file);
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsDirectoryMapping(com.intellij.openapi.vcs.VcsDirectoryMapping) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager) Module(com.intellij.openapi.module.Module) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with ProjectLevelVcsManager

use of com.intellij.openapi.vcs.ProjectLevelVcsManager in project intellij-community by JetBrains.

the class ImportAction method createCheckoutAction.

private AbstractAction createCheckoutAction(final boolean makeNewFilesReadOnly) {
    return new AbstractAction(false) {

        protected String getTitle(VcsContext context) {
            return CvsBundle.message("operation.name.check.out.project");
        }

        protected CvsHandler getCvsHandler(CvsContext context) {
            final Project project = context.getProject();
            return CommandCvsHandler.createCheckoutHandler(myImportDetails.getCvsRoot(), new String[] { myImportDetails.getModuleName() }, myImportDetails.getBaseImportDirectory(), true, makeNewFilesReadOnly, project == null ? null : VcsConfiguration.getInstance(project).getCheckoutOption());
        }

        protected void onActionPerformed(CvsContext context, CvsTabbedWindow tabbedWindow, boolean successfully, CvsHandler handler) {
            super.onActionPerformed(context, tabbedWindow, successfully, handler);
            final Project project = context.getProject();
            if (successfully) {
                if (project != null) {
                    final VirtualFile importedRoot = CvsVfsUtil.findFileByIoFile(myImportDetails.getBaseImportDirectory());
                    updateDirectoryMappings(project, importedRoot);
                }
            }
        }

        /**
       * Basically copied from GitInit/HgInit
       */
        private void updateDirectoryMappings(Project project, VirtualFile mapRoot) {
            if (project == null || project.isDefault()) {
                return;
            }
            final VirtualFile projectBaseDir = project.getBaseDir();
            if (projectBaseDir == null || !VfsUtil.isAncestor(projectBaseDir, mapRoot, false)) {
                return;
            }
            mapRoot.refresh(false, false);
            final String path = mapRoot.equals(projectBaseDir) ? "" : mapRoot.getPath();
            ProjectLevelVcsManager manager = ProjectLevelVcsManager.getInstance(project);
            manager.setDirectoryMappings(VcsUtil.addMapping(manager.getDirectoryMappings(), path, CvsVcs2.getInstance(project).getName()));
            manager.updateActiveVcss();
        }
    };
}
Also used : VcsContext(com.intellij.openapi.vcs.actions.VcsContext) CvsTabbedWindow(com.intellij.cvsSupport2.ui.CvsTabbedWindow) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) CvsHandler(com.intellij.cvsSupport2.cvshandlers.CvsHandler) CommandCvsHandler(com.intellij.cvsSupport2.cvshandlers.CommandCvsHandler) CvsContext(com.intellij.cvsSupport2.actions.cvsContext.CvsContext) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager)

Example 18 with ProjectLevelVcsManager

use of com.intellij.openapi.vcs.ProjectLevelVcsManager in project intellij-community by JetBrains.

the class BasicAction method collectAffectedFiles.

/**
   * given a list of action-target files, returns ALL the files that should be
   * subject to the action Does not keep directories, but recursively adds
   * directory contents
   *
   * @param project the project subject of the action
   * @param files   the root selection
   * @return the complete set of files this action should apply to
   */
@NotNull
protected VirtualFile[] collectAffectedFiles(@NotNull Project project, @NotNull VirtualFile[] files) {
    List<VirtualFile> affectedFiles = new ArrayList<>(files.length);
    ProjectLevelVcsManager projectLevelVcsManager = ProjectLevelVcsManager.getInstance(project);
    for (VirtualFile file : files) {
        if (!file.isDirectory() && projectLevelVcsManager.getVcsFor(file) instanceof GitVcs) {
            affectedFiles.add(file);
        } else if (file.isDirectory() && isRecursive()) {
            addChildren(project, affectedFiles, file);
        }
    }
    return VfsUtilCore.toVirtualFileArray(affectedFiles);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitVcs(git4idea.GitVcs) ArrayList(java.util.ArrayList) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with ProjectLevelVcsManager

use of com.intellij.openapi.vcs.ProjectLevelVcsManager in project intellij-community by JetBrains.

the class HgTestUtil method updateDirectoryMappings.

public static void updateDirectoryMappings(Project project, VirtualFile mapRoot) {
    if (project != null && (!project.isDefault()) && project.getBaseDir() != null && VfsUtilCore.isAncestor(project.getBaseDir(), mapRoot, false)) {
        mapRoot.refresh(false, false);
        final String path = mapRoot.equals(project.getBaseDir()) ? "" : mapRoot.getPath();
        ProjectLevelVcsManager manager = ProjectLevelVcsManager.getInstance(project);
        manager.setDirectoryMappings(VcsUtil.addMapping(manager.getDirectoryMappings(), path, HgVcs.VCS_NAME));
    }
}
Also used : ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager)

Aggregations

ProjectLevelVcsManager (com.intellij.openapi.vcs.ProjectLevelVcsManager)19 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)6 NotNull (org.jetbrains.annotations.NotNull)6 Project (com.intellij.openapi.project.Project)3 VcsDirectoryMapping (com.intellij.openapi.vcs.VcsDirectoryMapping)3 Nullable (org.jetbrains.annotations.Nullable)3 FilePath (com.intellij.openapi.vcs.FilePath)2 VcsException (com.intellij.openapi.vcs.VcsException)2 Date (java.util.Date)2 CvsContext (com.intellij.cvsSupport2.actions.cvsContext.CvsContext)1 AdditionalOptionsPanel (com.intellij.cvsSupport2.checkinProject.AdditionalOptionsPanel)1 CommandCvsHandler (com.intellij.cvsSupport2.cvshandlers.CommandCvsHandler)1 CvsHandler (com.intellij.cvsSupport2.cvshandlers.CvsHandler)1 CvsTabbedWindow (com.intellij.cvsSupport2.ui.CvsTabbedWindow)1 Disposable (com.intellij.openapi.Disposable)1 Application (com.intellij.openapi.application.Application)1 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)1 ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)1 ExternalSystemSettingsListenerAdapter (com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter)1