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()));
}
}
}
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;
}
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();
}
}
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;
}
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()));
}
}
}
Aggregations