use of com.intellij.openapi.vcs.VcsDirectoryMapping in project intellij-community by JetBrains.
the class ExternalSystemVcsRegistrar method handle.
@SuppressWarnings("unchecked")
public static void handle(@NotNull final Project project) {
for (final ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
final AbstractExternalSystemSettings settings = manager.getSettingsProvider().fun(project);
settings.subscribe(new ExternalSystemSettingsListenerAdapter() {
@Override
public void onProjectsLinked(@NotNull final Collection linked) {
List<VcsDirectoryMapping> newMappings = ContainerUtilRt.newArrayList();
final LocalFileSystem fileSystem = LocalFileSystem.getInstance();
ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
for (Object o : linked) {
final ExternalProjectSettings settings = (ExternalProjectSettings) o;
VirtualFile dir = fileSystem.refreshAndFindFileByPath(settings.getExternalProjectPath());
if (dir == null) {
continue;
}
if (!dir.isDirectory()) {
dir = dir.getParent();
}
newMappings.addAll(VcsUtil.findRoots(dir, project));
}
// There is a possible case that no VCS mappings are configured for the current project. There is a single
// mapping like <Project> - <No VCS> then. We want to replace it if only one mapping to the project root dir
// has been detected then.
List<VcsDirectoryMapping> oldMappings = vcsManager.getDirectoryMappings();
if (oldMappings.size() == 1 && newMappings.size() == 1 && StringUtil.isEmpty(oldMappings.get(0).getVcs())) {
VcsDirectoryMapping newMapping = newMappings.iterator().next();
String detectedDirPath = newMapping.getDirectory();
VirtualFile detectedDir = fileSystem.findFileByPath(detectedDirPath);
if (detectedDir != null && detectedDir.equals(project.getBaseDir())) {
newMappings.clear();
newMappings.add(new VcsDirectoryMapping("", newMapping.getVcs()));
vcsManager.setDirectoryMappings(newMappings);
return;
}
}
newMappings.addAll(oldMappings);
vcsManager.setDirectoryMappings(newMappings);
}
});
}
}
use of com.intellij.openapi.vcs.VcsDirectoryMapping 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;
}
use of com.intellij.openapi.vcs.VcsDirectoryMapping in project intellij-community by JetBrains.
the class MappingsToRoots method getDetailedVcsMappings.
// not only set mappings, but include all modules inside: modules might have different settings
public List<VirtualFile> getDetailedVcsMappings(final AbstractVcs vcs) {
// same as above, but no compression
final List<VirtualFile> result = myMappings.getMappingsAsFilesUnderVcs(vcs);
boolean addInnerModules = true;
final String vcsName = vcs.getName();
final List<VcsDirectoryMapping> directoryMappings = myMappings.getDirectoryMappings(vcsName);
for (VcsDirectoryMapping directoryMapping : directoryMappings) {
if (directoryMapping.isDefaultMapping()) {
addInnerModules = false;
break;
}
}
Collections.sort(result, FilePathComparator.getInstance());
if (addInnerModules) {
final FileIndexFacade facade = PeriodicalTasksCloser.getInstance().safeGetService(myProject, FileIndexFacade.class);
final Collection<VirtualFile> modules = DefaultVcsRootPolicy.getInstance(myProject).getDefaultVcsRoots(myMappings, vcsName);
ApplicationManager.getApplication().runReadAction(() -> {
Iterator<VirtualFile> iterator = modules.iterator();
while (iterator.hasNext()) {
final VirtualFile module = iterator.next();
boolean included = false;
for (VirtualFile root : result) {
if (facade.isValidAncestor(root, module)) {
included = true;
break;
}
}
if (!included) {
iterator.remove();
}
}
});
result.addAll(modules);
}
result.removeIf(file -> !file.isDirectory());
return result;
}
use of com.intellij.openapi.vcs.VcsDirectoryMapping in project intellij-community by JetBrains.
the class SvnResolveTreeAcceptVariantsTest method testMineFull.
@Test
public void testMineFull() throws Exception {
int cnt = 0;
myWorkingCopyDir = createDirInCommand(myWorkingCopyDir, "test--");
myTheirs = createDirInCommand(myTheirs, "theirs--");
//final TreeConflictData.Data data = TreeConflictData.FileToFile.MINE_EDIT_THEIRS_MOVE;
for (final TreeConflictData.Data data : TreeConflictData.ourAll) {
if (myTraceClient) {
System.out.println("========= TEST " + getTestName(data) + " =========");
}
((ChangeListManagerImpl) myChangeListManager).stopEveryThingIfInTestMode();
myWorkingCopyDir = createDirInCommand(myWorkingCopyDir.getParent(), "test" + cnt);
myTheirs = createDirInCommand(myTheirs.getParent(), "theirs" + cnt);
mySvnClientRunner.checkout(myRepoUrl, myTheirs);
mySvnClientRunner.checkout(myRepoUrl, myWorkingCopyDir);
sleep(200);
ProjectLevelVcsManager.getInstance(myProject).setDirectoryMappings(Collections.singletonList(new VcsDirectoryMapping(myWorkingCopyDir.getPath(), myVcs.getName())));
createSubTree(data);
myTheirs.refresh(false, true);
final ConflictCreator creator = new ConflictCreator(myProject, myTheirs, myWorkingCopyDir, data, mySvnClientRunner);
creator.create();
sleep(200);
((ChangeListManagerImpl) myChangeListManager).forceGoInTestMode();
myDirtyScopeManager.markEverythingDirty();
myChangeListManager.ensureUpToDate(false);
myDirtyScopeManager.markEverythingDirty();
myChangeListManager.ensureUpToDate(false);
final String conflictFile = data.getConflictFile();
final File conflictIoFile = new File(myWorkingCopyDir.getPath(), conflictFile);
final FilePath filePath = VcsUtil.getFilePath(conflictIoFile);
final Change change = myChangeListManager.getChange(filePath);
Assert.assertNotNull(change);
Assert.assertTrue(change instanceof ConflictedSvnChange);
final SvnRevisionNumber committedRevision = change.getBeforeRevision() != null ? (SvnRevisionNumber) change.getBeforeRevision().getRevisionNumber() : null;
//SvnRevisionNumber committedRevision = new SvnRevisionNumber(SVNRevision.create(cnt * 2 + 1));
final SvnTreeConflictResolver resolver = new SvnTreeConflictResolver(myVcs, filePath, null);
resolver.resolveSelectMineFull();
myTheirs.refresh(false, true);
myWorkingCopyDir.refresh(false, true);
checkStatusesAfterMineFullResolve(data, conflictIoFile);
checkFileContents(data, conflictIoFile);
++cnt;
}
}
Aggregations