Search in sources :

Example 1 with VcsDirectoryMapping

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

the class ShareWholeProject method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final MyChecker checker = new MyChecker();
    checker.execute(e);
    if (!checker.isEnabled())
        return;
    final Project project = checker.getProject();
    final VirtualFile baseDir = project.getBaseDir();
    if (baseDir == null)
        return;
    boolean success = false;
    boolean excThrown = false;
    try {
        success = ShareProjectAction.share(project, baseDir);
    } catch (VcsException exc) {
        AbstractVcsHelper.getInstance(project).showError(exc, "Failed to Share Project");
        excThrown = true;
    } finally {
        // if success = false -> either action was cancelled or exception was thrown, so also check for exception
        if (success || excThrown) {
            baseDir.refresh(true, true, () -> ApplicationManager.getApplication().invokeLater(() -> {
                VcsDirtyScopeManager.getInstance(project).dirDirtyRecursively(project.getBaseDir());
                if (checker.isHadNoMappings() && SvnUtil.seemsLikeVersionedDir(baseDir)) {
                    final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
                    vcsManager.setDirectoryMappings(Arrays.asList(new VcsDirectoryMapping("", SvnVcs.VCS_NAME)));
                }
            }, ModalityState.NON_MODAL, project.getDisposed()));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) VcsDirectoryMapping(com.intellij.openapi.vcs.VcsDirectoryMapping) VcsException(com.intellij.openapi.vcs.VcsException) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager)

Example 2 with VcsDirectoryMapping

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

the class VcsDirtyScopeManagerImpl method getEverythingDirtyRoots.

@NotNull
private MultiMap<AbstractVcs, FilePath> getEverythingDirtyRoots() {
    MultiMap<AbstractVcs, FilePath> dirtyRoots = MultiMap.createSet();
    dirtyRoots.putAllValues(groupByVcs(toFilePaths(DefaultVcsRootPolicy.getInstance(myProject).getDirtyRoots())));
    List<VcsDirectoryMapping> mappings = myVcsManager.getDirectoryMappings();
    for (VcsDirectoryMapping mapping : mappings) {
        if (!mapping.isDefaultMapping() && mapping.getVcs() != null) {
            AbstractVcs vcs = myVcsManager.findVcsByName(mapping.getVcs());
            if (vcs != null) {
                dirtyRoots.putValue(vcs, VcsUtil.getFilePath(mapping.getDirectory(), true));
            }
        }
    }
    return dirtyRoots;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VcsDirectoryMapping(com.intellij.openapi.vcs.VcsDirectoryMapping) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with VcsDirectoryMapping

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

the class ModuleVcsDetector method autoDetectVcsMappings.

private void autoDetectVcsMappings(final boolean tryMapPieces) {
    Set<AbstractVcs> usedVcses = new HashSet<>();
    Map<VirtualFile, AbstractVcs> vcsMap = new HashMap<>();
    final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    for (Module module : moduleManager.getModules()) {
        final VirtualFile[] files = ModuleRootManager.getInstance(module).getContentRoots();
        for (VirtualFile file : files) {
            AbstractVcs contentRootVcs = myVcsManager.findVersioningVcs(file);
            if (contentRootVcs != null) {
                vcsMap.put(file, contentRootVcs);
            }
            usedVcses.add(contentRootVcs);
        }
    }
    if (usedVcses.size() == 1) {
        // todo I doubt this is correct, see IDEA-50527
        final AbstractVcs[] abstractVcses = usedVcses.toArray(new AbstractVcs[1]);
        final Module[] modules = moduleManager.getModules();
        final Set<String> contentRoots = new HashSet<>();
        for (Module module : modules) {
            final VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
            for (VirtualFile root : roots) {
                contentRoots.add(root.getPath());
            }
        }
        if (abstractVcses[0] != null) {
            final List<VcsDirectoryMapping> vcsDirectoryMappings = new ArrayList<>(myVcsManager.getDirectoryMappings());
            for (Iterator<VcsDirectoryMapping> iterator = vcsDirectoryMappings.iterator(); iterator.hasNext(); ) {
                final VcsDirectoryMapping mapping = iterator.next();
                if (!contentRoots.contains(mapping.getDirectory())) {
                    iterator.remove();
                }
            }
            myVcsManager.setAutoDirectoryMapping("", abstractVcses[0].getName());
            for (VcsDirectoryMapping mapping : vcsDirectoryMappings) {
                myVcsManager.removeDirectoryMapping(mapping);
            }
            myVcsManager.cleanupMappings();
        }
    } else if (tryMapPieces) {
        for (Map.Entry<VirtualFile, AbstractVcs> entry : vcsMap.entrySet()) {
            myVcsManager.setAutoDirectoryMapping(entry.getKey().getPath(), entry.getValue() == null ? "" : entry.getValue().getName());
        }
        myVcsManager.cleanupMappings();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsDirectoryMapping(com.intellij.openapi.vcs.VcsDirectoryMapping) ModuleManager(com.intellij.openapi.module.ModuleManager) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs) Module(com.intellij.openapi.module.Module)

Example 4 with VcsDirectoryMapping

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

the class ModuleVcsDetector method getMappings.

private List<Pair<String, VcsDirectoryMapping>> getMappings(final Module module) {
    List<Pair<String, VcsDirectoryMapping>> result = new ArrayList<>();
    final VirtualFile[] files = ModuleRootManager.getInstance(module).getContentRoots();
    final String moduleName = module.getName();
    for (final VirtualFile file : files) {
        for (final VcsDirectoryMapping mapping : myVcsManager.getDirectoryMappings()) {
            if (FileUtil.toSystemIndependentName(mapping.getDirectory()).equals(file.getPath())) {
                result.add(Pair.create(moduleName, mapping));
                break;
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsDirectoryMapping(com.intellij.openapi.vcs.VcsDirectoryMapping) Pair(com.intellij.openapi.util.Pair)

Example 5 with VcsDirectoryMapping

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

the class FileWatchRequestModifier method run.

@Override
public void run() {
    if (!myProject.isInitialized() || myProject.isDisposed())
        return;
    final List<VcsDirectoryMapping> copy = myNewMappings.getDirectoryMappings();
    final List<VcsDirectoryMapping> added = newLinkedList(copy);
    added.removeAll(myDirectoryMappingWatches.keySet());
    final List<VcsDirectoryMapping> deleted = newLinkedList(myDirectoryMappingWatches.keySet());
    deleted.removeAll(copy);
    final Map<String, VcsDirectoryMapping> toAdd = ContainerUtil.newTroveMap(FileUtil.PATH_HASHING_STRATEGY);
    for (VcsDirectoryMapping mapping : added) {
        if (!mapping.isDefaultMapping()) {
            toAdd.put(FileUtil.toCanonicalPath(mapping.getDirectory()), mapping);
        }
    }
    final Collection<LocalFileSystem.WatchRequest> toRemove = newLinkedList();
    for (VcsDirectoryMapping mapping : deleted) {
        if (mapping.isDefaultMapping())
            continue;
        final LocalFileSystem.WatchRequest removed = myDirectoryMappingWatches.remove(mapping);
        if (removed != null) {
            toRemove.add(removed);
        }
    }
    final Set<LocalFileSystem.WatchRequest> requests = myLfs.replaceWatchedRoots(toRemove, toAdd.keySet(), null);
    for (LocalFileSystem.WatchRequest request : requests) {
        final VcsDirectoryMapping mapping = toAdd.get(request.getRootPath());
        if (mapping != null) {
            myDirectoryMappingWatches.put(mapping, request);
        } else {
            LOG.error("root=" + request.getRootPath() + " toAdd=" + ContainerUtil.newHashSet(toAdd.keySet()));
        }
    }
}
Also used : VcsDirectoryMapping(com.intellij.openapi.vcs.VcsDirectoryMapping) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem)

Aggregations

VcsDirectoryMapping (com.intellij.openapi.vcs.VcsDirectoryMapping)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)3 ProjectLevelVcsManager (com.intellij.openapi.vcs.ProjectLevelVcsManager)3 Module (com.intellij.openapi.module.Module)2 FilePath (com.intellij.openapi.vcs.FilePath)2 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)2 NotNull (org.jetbrains.annotations.NotNull)2 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)1 ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)1 ExternalSystemSettingsListenerAdapter (com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 Project (com.intellij.openapi.project.Project)1 FileIndexFacade (com.intellij.openapi.roots.FileIndexFacade)1 Pair (com.intellij.openapi.util.Pair)1 VcsException (com.intellij.openapi.vcs.VcsException)1 Change (com.intellij.openapi.vcs.changes.Change)1 ChangeListManagerImpl (com.intellij.openapi.vcs.changes.ChangeListManagerImpl)1 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)1 File (java.io.File)1