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);
}
};
}
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]);
}
}
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);
}
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;
}
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];
}
}
Aggregations