use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.
the class PrepareToDeployAction method doPrepare.
public static boolean doPrepare(final Module module, final List<String> errorMessages, final List<String> successMessages) {
final String pluginName = module.getName();
final String defaultPath = new File(module.getModuleFilePath()).getParent() + File.separator + pluginName;
final HashSet<Module> modules = new HashSet<>();
PluginBuildUtil.getDependencies(module, modules);
modules.add(module);
final Set<Library> libs = new HashSet<>();
for (Module dep : modules) {
PluginBuildUtil.getLibraries(dep, libs);
}
final Map<Module, String> jpsModules = collectJpsPluginModules(module);
modules.removeAll(jpsModules.keySet());
final boolean isZip = !libs.isEmpty() || !jpsModules.isEmpty();
final String oldPath = defaultPath + (isZip ? JAR_EXTENSION : ZIP_EXTENSION);
final File oldFile = new File(oldPath);
if (oldFile.exists()) {
if (Messages.showYesNoDialog(module.getProject(), DevKitBundle.message("suggest.to.delete", oldPath), DevKitBundle.message("info.message"), Messages.getInformationIcon()) == Messages.YES) {
FileUtil.delete(oldFile);
}
}
final String dstPath = defaultPath + (isZip ? ZIP_EXTENSION : JAR_EXTENSION);
final File dstFile = new File(dstPath);
return clearReadOnly(module.getProject(), dstFile) && ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
if (progressIndicator != null) {
progressIndicator.setText(DevKitBundle.message("prepare.for.deployment.common"));
progressIndicator.setIndeterminate(true);
}
try {
File jarFile = preparePluginsJar(module, modules);
if (isZip) {
processLibrariesAndJpsPlugins(jarFile, dstFile, pluginName, libs, jpsModules, progressIndicator);
} else {
FileUtil.copy(jarFile, dstFile);
}
LocalFileSystem.getInstance().refreshIoFiles(Collections.singleton(dstFile), true, false, null);
successMessages.add(DevKitBundle.message("saved.message", isZip ? 1 : 2, pluginName, dstPath));
} catch (final IOException e) {
errorMessages.add(e.getMessage() + "\n(" + dstPath + ")");
}
}, DevKitBundle.message("prepare.for.deployment", pluginName), true, module.getProject());
}
use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.
the class AbstractVcsHelperImpl method loadAndShowCommittedChangesDetails.
@Override
public void loadAndShowCommittedChangesDetails(@NotNull final Project project, @NotNull final VcsRevisionNumber revision, @NotNull final VirtualFile virtualFile, @NotNull VcsKey vcsKey, @Nullable final RepositoryLocation location, final boolean isNonLocal) {
final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).findVcsByName(vcsKey.getName());
if (vcs == null)
return;
final CommittedChangesProvider provider = vcs.getCommittedChangesProvider();
if (provider == null)
return;
if (isNonLocal && provider.getForNonLocal(virtualFile) == null)
return;
final String title = VcsBundle.message("paths.affected.in.revision", revision instanceof ShortVcsRevisionNumber ? ((ShortVcsRevisionNumber) revision).toShortString() : revision.asString());
final CommittedChangeList[] list = new CommittedChangeList[1];
final FilePath[] targetPath = new FilePath[1];
final VcsException[] exc = new VcsException[1];
final BackgroundableActionLock lock = BackgroundableActionLock.getLock(project, VcsBackgroundableActions.COMMITTED_CHANGES_DETAILS, revision, virtualFile.getPath());
if (lock.isLocked())
return;
lock.lock();
Task.Backgroundable task = new Task.Backgroundable(project, title, true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
if (!isNonLocal) {
final Pair<CommittedChangeList, FilePath> pair = provider.getOneList(virtualFile, revision);
if (pair != null) {
list[0] = pair.getFirst();
targetPath[0] = pair.getSecond();
}
} else {
if (location != null) {
final ChangeBrowserSettings settings = provider.createDefaultSettings();
settings.USE_CHANGE_BEFORE_FILTER = true;
settings.CHANGE_BEFORE = revision.asString();
final List<CommittedChangeList> changes = provider.getCommittedChanges(settings, location, 1);
if (changes != null && changes.size() == 1) {
list[0] = changes.get(0);
}
} else {
list[0] = getRemoteList(vcs, revision, virtualFile);
}
}
} catch (VcsException e) {
exc[0] = e;
}
}
@Override
public void onCancel() {
lock.unlock();
}
@Override
public void onSuccess() {
lock.unlock();
if (exc[0] != null) {
showError(exc[0], failedText(virtualFile, revision));
} else if (list[0] == null) {
Messages.showErrorDialog(project, failedText(virtualFile, revision), getTitle());
} else {
VirtualFile navigateToFile = targetPath[0] != null ? new VcsVirtualFile(targetPath[0].getPath(), null, VcsFileSystem.getInstance()) : virtualFile;
showChangesListBrowser(list[0], navigateToFile, title);
}
}
};
// we can's use runProcessWithProgressAsynchronously(task) because then ModalityState.NON_MODAL would be used
CoreProgressManager progressManager = (CoreProgressManager) ProgressManager.getInstance();
progressManager.runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task), null, ModalityState.current());
}
use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.
the class AbstractFileProcessor method prepareFiles.
private Runnable prepareFiles(List<PsiFile> files) {
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
String msg = null;
double fraction = 0.0D;
if (indicator != null) {
msg = indicator.getText();
fraction = indicator.getFraction();
indicator.setText(message);
}
final Runnable[] runnables = new Runnable[files.size()];
for (int i = 0; i < files.size(); i++) {
PsiFile pfile = files.get(i);
if (pfile == null) {
logger.debug("Unexpected null file at " + i);
continue;
}
if (indicator != null) {
if (indicator.isCanceled()) {
return null;
}
indicator.setFraction((double) i / (double) files.size());
}
if (pfile.isWritable()) {
try {
runnables[i] = preprocessFile(pfile, true);
} catch (IncorrectOperationException incorrectoperationexception) {
logger.error(incorrectoperationexception);
}
}
files.set(i, null);
}
if (indicator != null) {
indicator.setText(msg);
indicator.setFraction(fraction);
}
return () -> {
ProgressIndicator indicator1 = ProgressManager.getInstance().getProgressIndicator();
String msg1 = null;
double fraction1 = 0.0D;
if (indicator1 != null) {
msg1 = indicator1.getText();
fraction1 = indicator1.getFraction();
indicator1.setText(message);
}
for (int j = 0; j < runnables.length; j++) {
if (indicator1 != null) {
if (indicator1.isCanceled()) {
return;
}
indicator1.setFraction((double) j / (double) runnables.length);
}
Runnable runnable = runnables[j];
if (runnable != null) {
runnable.run();
}
runnables[j] = null;
}
if (indicator1 != null) {
indicator1.setText(msg1);
indicator1.setFraction(fraction1);
}
};
}
use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.
the class UnmarkAddedAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
VcsContext context = CvsContextWrapper.createCachedInstance(e);
final VirtualFile[] selectedFiles = context.getSelectedFiles();
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
for (int i = 0; i < selectedFiles.length; i++) {
File file = CvsVfsUtil.getFileFor(selectedFiles[i]);
if (progressIndicator != null) {
progressIndicator.setFraction((double) i / (double) selectedFiles.length);
progressIndicator.setText(file.getAbsolutePath());
}
CvsUtil.removeEntryFor(file);
}
}, CvsBundle.message("operation.name.undo.add"), true, context.getProject());
VirtualFileManager.getInstance().asyncRefresh(null);
}
use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.
the class CvsListenerWithProgress method isAborted.
public boolean isAborted() {
myPing = true;
if (myLastError != null)
throw new CvsProcessException(myLastError);
if (myIndirectCancel)
return true;
final ProgressIndicator progressIndicator = getProgressIndicator();
if (progressIndicator == null)
return false;
return progressIndicator.isCanceled();
}
Aggregations