Search in sources :

Example 1 with ProgressTracker

use of org.jetbrains.idea.svn.api.ProgressTracker in project intellij-community by JetBrains.

the class SvnCheckoutProvider method doExport.

public static void doExport(final Project project, final File target, final SVNURL url, final Depth depth, final boolean ignoreExternals, final boolean force, final String eolStyle) {
    try {
        final VcsException[] exception = new VcsException[1];
        final SvnVcs vcs = SvnVcs.getInstance(project);
        ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
            ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
            ProgressTracker handler = new CheckoutEventHandler(vcs, true, progressIndicator);
            try {
                progressIndicator.setText(message("progress.text.export", target.getAbsolutePath()));
                SvnTarget from = SvnTarget.fromURL(url);
                ExportClient client = vcs.getFactoryFromSettings().createExportClient();
                client.export(from, target, SVNRevision.HEAD, depth, eolStyle, force, ignoreExternals, handler);
            } catch (VcsException e) {
                exception[0] = e;
            }
        }, message("message.title.export"), true, project);
        if (exception[0] != null) {
            throw exception[0];
        }
    } catch (VcsException e1) {
        showErrorDialog(message("message.text.cannot.export", e1.getMessage()), message("message.title.export"));
    }
}
Also used : ProgressTracker(org.jetbrains.idea.svn.api.ProgressTracker) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) SvnTarget(org.tmatesoft.svn.core.wc2.SvnTarget) SvnVcs(org.jetbrains.idea.svn.SvnVcs)

Example 2 with ProgressTracker

use of org.jetbrains.idea.svn.api.ProgressTracker in project intellij-community by JetBrains.

the class SvnUtil method doUnlockFiles.

public static void doUnlockFiles(Project project, final SvnVcs activeVcs, final File[] ioFiles) throws VcsException {
    final boolean force = true;
    final VcsException[] exception = new VcsException[1];
    final Collection<String> failedUnlocks = new ArrayList<>();
    final int[] count = new int[] { ioFiles.length };
    final ProgressTracker eventHandler = new ProgressTracker() {

        public void consume(ProgressEvent event) {
            if (event.getAction() == EventAction.UNLOCK_FAILED) {
                failedUnlocks.add(event.getErrorMessage() != null ? event.getErrorMessage().getFullMessage() : event.getFile().getAbsolutePath());
                count[0]--;
            }
        }

        public void checkCancelled() {
        }
    };
    Runnable command = () -> {
        ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
        try {
            if (progress != null) {
                progress.setText(SvnBundle.message("progress.text.unlocking.files"));
            }
            for (File ioFile : ioFiles) {
                if (progress != null) {
                    progress.checkCanceled();
                }
                if (progress != null) {
                    progress.setText2(SvnBundle.message("progress.text2.processing.file", ioFile.getName()));
                }
                activeVcs.getFactory(ioFile).createLockClient().unlock(ioFile, force, eventHandler);
            }
        } catch (VcsException e) {
            exception[0] = e;
        }
    };
    ProgressManager.getInstance().runProcessWithProgressSynchronously(command, SvnBundle.message("progress.title.unlock.files"), false, project);
    if (!failedUnlocks.isEmpty()) {
        String[] failedFiles = ArrayUtil.toStringArray(failedUnlocks);
        List<VcsException> exceptions = new ArrayList<>();
        for (String file : failedFiles) {
            exceptions.add(new VcsException(SvnBundle.message("exception.text.failed.to.unlock.file", file)));
        }
        AbstractVcsHelper.getInstance(project).showErrors(exceptions, SvnBundle.message("message.title.unlock.failures"));
    }
    StatusBarUtil.setStatusBarInfo(project, SvnBundle.message("message.text.files.unlocked", count[0]));
    if (exception[0] != null) {
        throw new VcsException(exception[0]);
    }
}
Also used : ProgressTracker(org.jetbrains.idea.svn.api.ProgressTracker) ArrayList(java.util.ArrayList) ProgressEvent(org.jetbrains.idea.svn.api.ProgressEvent) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

Example 3 with ProgressTracker

use of org.jetbrains.idea.svn.api.ProgressTracker in project intellij-community by JetBrains.

the class SvnFormatWorker method run.

public void run(@NotNull final ProgressIndicator indicator) {
    ProjectLevelVcsManager.getInstanceChecked(myProject).startBackgroundVcsOperation();
    indicator.setIndeterminate(true);
    final boolean supportsChangelists = myNewFormat.supportsChangelists();
    if (supportsChangelists) {
        myBeforeChangeLists = ChangeListManager.getInstance(myProject).getChangeListsCopy();
    }
    try {
        for (WCInfo wcInfo : myWcInfos) {
            File path = new File(wcInfo.getPath());
            if (!wcInfo.isIsWcRoot()) {
                path = SvnUtil.getWorkingCopyRoot(path);
            }
            try {
                String cleanupMessage = SvnBundle.message("action.Subversion.cleanup.progress.text", path.getAbsolutePath());
                String upgradeMessage = SvnBundle.message("action.change.wcopy.format.task.progress.text", path.getAbsolutePath(), wcInfo.getFormat(), myNewFormat);
                ProgressTracker handler = createUpgradeHandler(indicator, cleanupMessage, upgradeMessage);
                getFactory(path, myNewFormat).createUpgradeClient().upgrade(path, myNewFormat, handler);
            } catch (Throwable e) {
                myExceptions.add(e);
            }
        }
    } finally {
        ProjectLevelVcsManager.getInstance(myProject).stopBackgroundVcsOperation();
        // to map to native
        if (supportsChangelists) {
            SvnVcs.getInstance(myProject).processChangeLists(myBeforeChangeLists);
        }
        ApplicationManager.getApplication().getMessageBus().syncPublisher(SvnVcs.WC_CONVERTED).run();
    }
}
Also used : ProgressTracker(org.jetbrains.idea.svn.api.ProgressTracker) File(java.io.File)

Example 4 with ProgressTracker

use of org.jetbrains.idea.svn.api.ProgressTracker in project intellij-community by JetBrains.

the class SvnUtil method doLockFiles.

public static void doLockFiles(Project project, final SvnVcs activeVcs, @NotNull final File[] ioFiles) throws VcsException {
    final String lockMessage;
    final boolean force;
    // TODO[yole]: check for shift pressed
    if (activeVcs.getCheckoutOptions().getValue()) {
        LockDialog dialog = new LockDialog(project, true, ioFiles.length > 1);
        if (!dialog.showAndGet()) {
            return;
        }
        lockMessage = dialog.getComment();
        force = dialog.isForce();
    } else {
        lockMessage = "";
        force = false;
    }
    final VcsException[] exception = new VcsException[1];
    final Collection<String> failedLocks = new ArrayList<>();
    final int[] count = new int[] { ioFiles.length };
    final ProgressTracker eventHandler = new ProgressTracker() {

        public void consume(ProgressEvent event) {
            if (event.getAction() == EventAction.LOCK_FAILED) {
                failedLocks.add(event.getErrorMessage() != null ? event.getErrorMessage().getFullMessage() : event.getFile().getAbsolutePath());
                count[0]--;
            }
        }

        public void checkCancelled() {
        }
    };
    Runnable command = () -> {
        ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
        try {
            if (progress != null) {
                progress.setText(SvnBundle.message("progress.text.locking.files"));
            }
            for (File ioFile : ioFiles) {
                if (progress != null) {
                    progress.checkCanceled();
                }
                if (progress != null) {
                    progress.setText2(SvnBundle.message("progress.text2.processing.file", ioFile.getName()));
                }
                activeVcs.getFactory(ioFile).createLockClient().lock(ioFile, force, lockMessage, eventHandler);
            }
        } catch (VcsException e) {
            exception[0] = e;
        }
    };
    ProgressManager.getInstance().runProcessWithProgressSynchronously(command, SvnBundle.message("progress.title.lock.files"), false, project);
    if (!failedLocks.isEmpty()) {
        String[] failedFiles = ArrayUtil.toStringArray(failedLocks);
        List<VcsException> exceptions = new ArrayList<>();
        for (String file : failedFiles) {
            exceptions.add(new VcsException(SvnBundle.message("exception.text.locking.file.failed", file)));
        }
        final StringBuilder sb = new StringBuilder(SvnBundle.message("message.text.files.lock.failed", failedFiles.length == 1 ? 0 : 1));
        for (VcsException vcsException : exceptions) {
            if (sb.length() > 0)
                sb.append('\n');
            sb.append(vcsException.getMessage());
        }
        //AbstractVcsHelper.getInstance(project).showErrors(exceptions, SvnBundle.message("message.title.lock.failures"));
        throw new VcsException(sb.toString());
    }
    StatusBarUtil.setStatusBarInfo(project, SvnBundle.message("message.text.files.locked", count[0]));
    if (exception[0] != null) {
        throw exception[0];
    }
}
Also used : ProgressTracker(org.jetbrains.idea.svn.api.ProgressTracker) ArrayList(java.util.ArrayList) ProgressEvent(org.jetbrains.idea.svn.api.ProgressEvent) LockDialog(org.jetbrains.idea.svn.dialogs.LockDialog) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

Example 5 with ProgressTracker

use of org.jetbrains.idea.svn.api.ProgressTracker in project intellij-community by JetBrains.

the class SvnCheckinEnvironment method scheduleUnversionedFilesForAddition.

public static List<VcsException> scheduleUnversionedFilesForAddition(@NotNull SvnVcs vcs, List<VirtualFile> files, final boolean recursive) {
    Collections.sort(files, FilePathComparator.getInstance());
    ProgressTracker eventHandler = new SvnProgressCanceller() {

        @Override
        public void consume(ProgressEvent event) throws SVNException {
            // TODO: indicator is null here when invoking "Add" action
            ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
            File file = event.getFile();
            if (indicator != null && file != null) {
                indicator.setText(SvnBundle.message("progress.text2.adding", file.getName() + " (" + file.getParent() + ")"));
            }
        }
    };
    List<VcsException> exceptions = new ArrayList<>();
    Depth depth = Depth.allOrEmpty(recursive);
    for (VirtualFile file : files) {
        try {
            File convertedFile = VfsUtilCore.virtualToIoFile(file);
            vcs.getFactory(convertedFile).createAddClient().add(convertedFile, depth, true, false, true, eventHandler);
        } catch (VcsException e) {
            exceptions.add(e);
        }
    }
    return exceptions;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProgressTracker(org.jetbrains.idea.svn.api.ProgressTracker) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) ProgressEvent(org.jetbrains.idea.svn.api.ProgressEvent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Depth(org.jetbrains.idea.svn.api.Depth)

Aggregations

ProgressTracker (org.jetbrains.idea.svn.api.ProgressTracker)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 VcsException (com.intellij.openapi.vcs.VcsException)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 File (java.io.File)4 ProgressEvent (org.jetbrains.idea.svn.api.ProgressEvent)3 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)2 ArrayList (java.util.ArrayList)2 SvnVcs (org.jetbrains.idea.svn.SvnVcs)2 Task (com.intellij.openapi.progress.Task)1 Ref (com.intellij.openapi.util.Ref)1 NotNull (org.jetbrains.annotations.NotNull)1 WorkingCopyFormat (org.jetbrains.idea.svn.WorkingCopyFormat)1 Depth (org.jetbrains.idea.svn.api.Depth)1 LockDialog (org.jetbrains.idea.svn.dialogs.LockDialog)1 SVNCancelException (org.tmatesoft.svn.core.SVNCancelException)1 SVNException (org.tmatesoft.svn.core.SVNException)1 SvnTarget (org.tmatesoft.svn.core.wc2.SvnTarget)1