Search in sources :

Example 1 with ProgressEvent

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

the class CmdUpdateClient method createCommandListener.

private BaseUpdateCommandListener createCommandListener(final File[] paths, final AtomicReference<long[]> updatedToRevision, final File base) {
    return new BaseUpdateCommandListener(base, myDispatcher) {

        final long[] myRevisions = new long[paths.length];

        @Override
        protected void beforeHandler(@NotNull ProgressEvent event) {
            if (EventAction.UPDATE_COMPLETED.equals(event.getAction())) {
                final long eventRevision = event.getRevision();
                for (int i = 0; i < paths.length; i++) {
                    final File path = paths[i];
                    if (FileUtil.filesEqual(path, event.getFile())) {
                        myRevisions[i] = eventRevision;
                        break;
                    }
                }
            }
        }

        @Override
        public void processTerminated(int exitCode) {
            super.processTerminated(exitCode);
            updatedToRevision.set(myRevisions);
        }
    };
}
Also used : BaseUpdateCommandListener(org.jetbrains.idea.svn.commandLine.BaseUpdateCommandListener) ProgressEvent(org.jetbrains.idea.svn.api.ProgressEvent) NotNull(org.jetbrains.annotations.NotNull) File(java.io.File)

Example 2 with ProgressEvent

use of org.jetbrains.idea.svn.api.ProgressEvent 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 ProgressEvent

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

the class UpdateOutputLineConverter method parseNormalString.

@Nullable
private ProgressEvent parseNormalString(final String line) {
    if (line.length() < 5)
        return null;
    final char first = line.charAt(0);
    if (' ' != first && !ourActions.contains(first))
        return null;
    final StatusType contentsStatus = CommandUtil.getStatusType(first);
    final char second = line.charAt(1);
    final StatusType propertiesStatus = CommandUtil.getStatusType(second);
    // dont know what to do with stolen lock info
    final char lock = line.charAt(2);
    if (' ' != lock && 'B' != lock)
        return null;
    final char treeConflict = line.charAt(3);
    if (' ' != treeConflict && 'C' != treeConflict)
        return null;
    final boolean haveTreeConflict = 'C' == treeConflict;
    final String path = line.substring(4).trim();
    if (StringUtil.isEmptyOrSpaces(path))
        return null;
    final File file = SvnUtil.resolvePath(myBase, path);
    if (StatusType.STATUS_OBSTRUCTED.equals(contentsStatus)) {
        // obstructed
        return new ProgressEvent(file, -1, contentsStatus, propertiesStatus, EventAction.UPDATE_SKIP_OBSTRUCTION, null, null);
    }
    EventAction action;
    EventAction expectedAction;
    if (StatusType.STATUS_ADDED.equals(contentsStatus)) {
        expectedAction = EventAction.UPDATE_ADD;
    } else if (StatusType.STATUS_DELETED.equals(contentsStatus)) {
        expectedAction = EventAction.UPDATE_DELETE;
    } else {
        expectedAction = EventAction.UPDATE_UPDATE;
    }
    action = expectedAction;
    if (haveTreeConflict) {
        action = EventAction.TREE_CONFLICT;
    }
    return new ProgressEvent(file, -1, contentsStatus, propertiesStatus, action, null, null);
}
Also used : StatusType(org.jetbrains.idea.svn.status.StatusType) EventAction(org.jetbrains.idea.svn.api.EventAction) ProgressEvent(org.jetbrains.idea.svn.api.ProgressEvent) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ProgressEvent

use of org.jetbrains.idea.svn.api.ProgressEvent 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)

Example 5 with ProgressEvent

use of org.jetbrains.idea.svn.api.ProgressEvent 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)

Aggregations

File (java.io.File)5 ProgressEvent (org.jetbrains.idea.svn.api.ProgressEvent)5 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 VcsException (com.intellij.openapi.vcs.VcsException)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 ProgressTracker (org.jetbrains.idea.svn.api.ProgressTracker)3 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 Depth (org.jetbrains.idea.svn.api.Depth)1 EventAction (org.jetbrains.idea.svn.api.EventAction)1 BaseUpdateCommandListener (org.jetbrains.idea.svn.commandLine.BaseUpdateCommandListener)1 LockDialog (org.jetbrains.idea.svn.dialogs.LockDialog)1 StatusType (org.jetbrains.idea.svn.status.StatusType)1