Search in sources :

Example 6 with VcsDirectoryMapping

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);
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExternalSystemSettingsListenerAdapter(com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter) VcsDirectoryMapping(com.intellij.openapi.vcs.VcsDirectoryMapping) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Collection(java.util.Collection) List(java.util.List)

Example 7 with VcsDirectoryMapping

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;
}
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 8 with VcsDirectoryMapping

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsDirectoryMapping(com.intellij.openapi.vcs.VcsDirectoryMapping) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade)

Example 9 with VcsDirectoryMapping

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;
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) ChangeListManagerImpl(com.intellij.openapi.vcs.changes.ChangeListManagerImpl) VcsDirectoryMapping(com.intellij.openapi.vcs.VcsDirectoryMapping) Change(com.intellij.openapi.vcs.changes.Change) SvnTreeConflictResolver(org.jetbrains.idea.svn.treeConflict.SvnTreeConflictResolver) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File) Test(org.junit.Test)

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