Search in sources :

Example 81 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class IdeaCommitHandler method trackDeletedFile.

private void trackDeletedFile(@NotNull ProgressEvent event) {
    @NonNls final String filePath = "file://" + event.getFile().getAbsolutePath().replace(File.separatorChar, '/');
    VirtualFile virtualFile = ApplicationManager.getApplication().runReadAction((Computable<VirtualFile>) () -> VirtualFileManager.getInstance().findFileByUrl(filePath));
    if (virtualFile != null) {
        myDeletedFiles.add(virtualFile);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonNls(org.jetbrains.annotations.NonNls)

Example 82 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class SvnCheckinHandlerFactory method createVcsHandler.

@NotNull
@Override
protected CheckinHandler createVcsHandler(final CheckinProjectPanel panel) {
    final Project project = panel.getProject();
    final Collection<VirtualFile> commitRoots = panel.getRoots();
    return new CheckinHandler() {

        private Collection<Change> myChanges = panel.getSelectedChanges();

        @Override
        public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
            return null;
        }

        @Override
        public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) {
            if (executor instanceof LocalCommitExecutor)
                return ReturnResult.COMMIT;
            final SvnVcs vcs = SvnVcs.getInstance(project);
            final MultiMap<String, WorkingCopyFormat> copiesInfo = splitIntoCopies(vcs, myChanges);
            final List<String> repoUrls = new ArrayList<>();
            for (Map.Entry<String, Collection<WorkingCopyFormat>> entry : copiesInfo.entrySet()) {
                if (entry.getValue().size() > 1) {
                    repoUrls.add(entry.getKey());
                }
            }
            if (!repoUrls.isEmpty()) {
                final String join = StringUtil.join(repoUrls, ",\n");
                final int isOk = Messages.showOkCancelDialog(project, SvnBundle.message("checkin.different.formats.involved", repoUrls.size() > 1 ? 1 : 0, join), "Subversion: Commit Will Split", Messages.getWarningIcon());
                return Messages.OK == isOk ? ReturnResult.COMMIT : ReturnResult.CANCEL;
            }
            return ReturnResult.COMMIT;
        }

        @Override
        public void includedChangesChanged() {
            myChanges = panel.getSelectedChanges();
        }

        @Override
        public void checkinSuccessful() {
            if (SvnConfiguration.getInstance(project).isAutoUpdateAfterCommit()) {
                final VirtualFile[] roots = ProjectLevelVcsManager.getInstance(project).getRootsUnderVcs(SvnVcs.getInstance(project));
                final List<FilePath> paths = new ArrayList<>();
                for (VirtualFile root : roots) {
                    boolean take = false;
                    for (VirtualFile commitRoot : commitRoots) {
                        if (VfsUtilCore.isAncestor(root, commitRoot, false)) {
                            take = true;
                            break;
                        }
                    }
                    if (take) {
                        paths.add(VcsUtil.getFilePath(root));
                    }
                }
                if (paths.isEmpty())
                    return;
                ApplicationManager.getApplication().invokeLater(() -> AutoSvnUpdater.run(new AutoSvnUpdater(project, paths.toArray(new FilePath[paths.size()])), ActionInfo.UPDATE.getActionName()), ModalityState.NON_MODAL);
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilePath(com.intellij.openapi.vcs.FilePath) LocalCommitExecutor(com.intellij.openapi.vcs.changes.LocalCommitExecutor) ArrayList(java.util.ArrayList) CheckinHandler(com.intellij.openapi.vcs.checkin.CheckinHandler) LocalCommitExecutor(com.intellij.openapi.vcs.changes.LocalCommitExecutor) CommitExecutor(com.intellij.openapi.vcs.changes.CommitExecutor) Project(com.intellij.openapi.project.Project) PairConsumer(com.intellij.util.PairConsumer) Collection(java.util.Collection) AutoSvnUpdater(org.jetbrains.idea.svn.update.AutoSvnUpdater) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 83 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class SvnAnnotationProvider method annotateNonExisting.

private SvnRemoteFileAnnotation annotateNonExisting(Pair<SvnChangeList, FilePath> pair, VcsFileRevision revision, Info info, Charset charset, final VirtualFile current) throws VcsException, SVNException, IOException {
    final File wasFile = pair.getSecond().getIOFile();
    final File root = getCommonAncestor(wasFile, info.getFile());
    if (root == null) {
        throw new VcsException("Can not find relative path for " + wasFile.getPath() + "@" + revision.getRevisionNumber().asString());
    }
    final String relativePath = FileUtil.getRelativePath(root.getPath(), wasFile.getPath(), File.separatorChar);
    if (relativePath == null) {
        throw new VcsException("Can not find relative path for " + wasFile.getPath() + "@" + revision.getRevisionNumber().asString());
    }
    Info wcRootInfo = myVcs.getInfo(root);
    if (wcRootInfo == null || wcRootInfo.getURL() == null) {
        throw new VcsException("Can not find relative path for " + wasFile.getPath() + "@" + revision.getRevisionNumber().asString());
    }
    SVNURL wasUrl = wcRootInfo.getURL();
    final String[] strings = relativePath.replace('\\', '/').split("/");
    for (String string : strings) {
        wasUrl = wasUrl.appendPath(string, true);
    }
    final SVNRevision svnRevision = ((SvnRevisionNumber) revision.getRevisionNumber()).getRevision();
    byte[] data = SvnUtil.getFileContents(myVcs, SvnTarget.fromURL(wasUrl), svnRevision, svnRevision);
    final String contents = LoadTextUtil.getTextByBinaryPresentation(data, charset == null ? CharsetToolkit.UTF8_CHARSET : charset).toString();
    final SvnRemoteFileAnnotation result = new SvnRemoteFileAnnotation(myVcs, contents, revision.getRevisionNumber(), current);
    final AnnotationConsumer annotateHandler = createAnnotationHandler(ProgressManager.getInstance().getProgressIndicator(), result);
    boolean calculateMergeinfo = myVcs.getSvnConfiguration().isShowMergeSourcesInAnnotate() && SvnUtil.checkRepositoryVersion15(myVcs, wasUrl.toString());
    AnnotateClient client = myVcs.getFactory().createAnnotateClient();
    client.annotate(SvnTarget.fromURL(wasUrl, svnRevision), SVNRevision.create(1), svnRevision, calculateMergeinfo, getLogClientOptions(myVcs), annotateHandler);
    return result;
}
Also used : SVNURL(org.tmatesoft.svn.core.SVNURL) Info(org.jetbrains.idea.svn.info.Info) VcsException(com.intellij.openapi.vcs.VcsException) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

Example 84 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class SvnCheckoutProvider method doImport.

public static void doImport(final Project project, final File target, final SVNURL url, final Depth depth, final boolean includeIgnored, final String message) {
    final Ref<String> errorMessage = new Ref<>();
    final SvnVcs vcs = SvnVcs.getInstance(project);
    final String targetPath = FileUtil.toSystemIndependentName(target.getAbsolutePath());
    ExclusiveBackgroundVcsAction.run(project, () -> ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        final FileIndexFacade facade = PeriodicalTasksCloser.getInstance().safeGetService(project, FileIndexFacade.class);
        ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
        try {
            progressIndicator.setText(message("progress.text.import", target.getAbsolutePath()));
            final VirtualFile targetVf = SvnUtil.getVirtualFile(targetPath);
            if (targetVf == null) {
                errorMessage.set("Can not find file: " + targetPath);
            } else {
                final boolean isInContent = getApplication().runReadAction((Computable<Boolean>) () -> facade.isInContent(targetVf));
                CommitEventHandler handler = new IdeaCommitHandler(progressIndicator);
                boolean useFileFilter = !project.isDefault() && isInContent;
                ISVNCommitHandler commitHandler = useFileFilter ? new MyFilter(LocalFileSystem.getInstance(), new SvnExcludingIgnoredOperation.Filter(project)) : null;
                long revision = vcs.getFactoryFromSettings().createImportClient().doImport(target, url, depth, message, includeIgnored, handler, commitHandler);
                if (revision > 0) {
                    StatusBar.Info.set(message("status.text.comitted.revision", revision), project);
                }
            }
        } catch (VcsException e) {
            errorMessage.set(e.getMessage());
        }
    }, message("message.title.import"), true, project));
    if (!errorMessage.isNull()) {
        showErrorDialog(message("message.text.cannot.import", errorMessage.get()), message("message.title.import"));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdeaCommitHandler(org.jetbrains.idea.svn.checkin.IdeaCommitHandler) ISVNCommitHandler(org.tmatesoft.svn.core.wc.ISVNCommitHandler) CommitEventHandler(org.jetbrains.idea.svn.checkin.CommitEventHandler) SvnVcs(org.jetbrains.idea.svn.SvnVcs) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SvnExcludingIgnoredOperation(org.jetbrains.idea.svn.actions.SvnExcludingIgnoredOperation) VcsException(com.intellij.openapi.vcs.VcsException) Computable(com.intellij.openapi.util.Computable) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade)

Example 85 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile 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)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)5465 File (java.io.File)762 Project (com.intellij.openapi.project.Project)720 Nullable (org.jetbrains.annotations.Nullable)720 NotNull (org.jetbrains.annotations.NotNull)703 PsiFile (com.intellij.psi.PsiFile)571 Module (com.intellij.openapi.module.Module)501 IOException (java.io.IOException)327 ArrayList (java.util.ArrayList)260 Document (com.intellij.openapi.editor.Document)244 PsiElement (com.intellij.psi.PsiElement)209 Test (org.junit.Test)196 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)124 PsiDirectory (com.intellij.psi.PsiDirectory)124 XmlFile (com.intellij.psi.xml.XmlFile)124 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)116 Editor (com.intellij.openapi.editor.Editor)115 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)101 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)91 List (java.util.List)90