use of com.intellij.openapi.progress.Task in project intellij-community by JetBrains.
the class SkeletonTestTask method runTestOn.
@Override
public void runTestOn(@NotNull final String sdkHome) throws IOException, InvalidSdkException {
final Sdk sdk = createTempSdk(sdkHome, SdkCreationType.SDK_PACKAGES_ONLY);
final File skeletonsPath = new File(PythonSdkType.getSkeletonsPath(PathManager.getSystemPath(), sdk.getHomePath()));
// File with module skeleton
File skeletonFileOrDirectory = new File(skeletonsPath, myModuleNameToBeGenerated);
// Module may be stored in "moduleName.py" or "moduleName/__init__.py"
if (skeletonFileOrDirectory.isDirectory()) {
skeletonFileOrDirectory = new File(skeletonFileOrDirectory, PyNames.INIT_DOT_PY);
} else {
skeletonFileOrDirectory = new File(skeletonFileOrDirectory.getAbsolutePath() + PyNames.DOT_PY);
}
final File skeletonFile = skeletonFileOrDirectory;
if (skeletonFile.exists()) {
// To make sure we do not reuse it
assert skeletonFile.delete() : "Failed to delete file " + skeletonFile;
}
ApplicationManager.getApplication().invokeAndWait(() -> {
// File that uses CLR library
myFixture.copyFileToProject("dotNet/" + mySourceFileToRunGenerationOn, mySourceFileToRunGenerationOn);
// Library itself
myFixture.copyFileToProject("dotNet/PythonLibs.dll", "PythonLibs.dll");
// Another library
myFixture.copyFileToProject("dotNet/SingleNameSpace.dll", "SingleNameSpace.dll");
myFixture.configureByFile(mySourceFileToRunGenerationOn);
}, ModalityState.NON_MODAL);
// This inspection should suggest us to generate stubs
myFixture.enableInspections(PyUnresolvedReferencesInspection.class);
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
PsiDocumentManager.getInstance(myFixture.getProject()).commitAllDocuments();
final String intentionName = PyBundle.message("sdk.gen.stubs.for.binary.modules", myUseQuickFixWithThisModuleOnly);
final IntentionAction intention = myFixture.findSingleIntention(intentionName);
Assert.assertNotNull("No intention found to generate skeletons!", intention);
Assert.assertThat("Intention should be quick fix to run", intention, Matchers.instanceOf(QuickFixWrapper.class));
final LocalQuickFix quickFix = ((QuickFixWrapper) intention).getFix();
Assert.assertThat("Quick fix should be 'generate binary skeletons' fix to run", quickFix, Matchers.instanceOf(GenerateBinaryStubsFix.class));
final Task fixTask = ((GenerateBinaryStubsFix) quickFix).getFixTask(myFixture.getFile());
fixTask.run(new AbstractProgressIndicatorBase());
}
});
FileUtil.copy(skeletonFile, new File(myFixture.getTempDirPath(), skeletonFile.getName()));
if (myExpectedSkeletonFile != null) {
final String actual = StreamUtil.readText(new FileInputStream(skeletonFile), Charset.defaultCharset());
final String skeletonText = StreamUtil.readText(new FileInputStream(new File(getTestDataPath(), myExpectedSkeletonFile)), Charset.defaultCharset());
// TODO: Move to separate method ?
if (!Matchers.equalToIgnoringWhiteSpace(removeGeneratorVersion(skeletonText)).matches(removeGeneratorVersion(actual))) {
throw new FileComparisonFailure("asd", skeletonText, actual, skeletonFile.getAbsolutePath());
}
}
myFixture.configureByFile(skeletonFile.getName());
}
use of com.intellij.openapi.progress.Task in project intellij-community by JetBrains.
the class MavenBeforeRunTasksProvider method executeTask.
public boolean executeTask(final DataContext context, RunConfiguration configuration, ExecutionEnvironment env, final MavenBeforeRunTask task) {
final Semaphore targetDone = new Semaphore();
final boolean[] result = new boolean[] { true };
try {
ApplicationManager.getApplication().invokeAndWait(() -> {
final Project project = CommonDataKeys.PROJECT.getData(context);
final MavenProject mavenProject = getMavenProject(task);
if (project == null || project.isDisposed() || mavenProject == null)
return;
FileDocumentManager.getInstance().saveAllDocuments();
final MavenExplicitProfiles explicitProfiles = MavenProjectsManager.getInstance(project).getExplicitProfiles();
final MavenRunner mavenRunner = MavenRunner.getInstance(project);
targetDone.down();
new Task.Backgroundable(project, TasksBundle.message("maven.tasks.executing"), true) {
public void run(@NotNull ProgressIndicator indicator) {
try {
MavenRunnerParameters params = new MavenRunnerParameters(true, mavenProject.getDirectory(), ParametersListUtil.parse(task.getGoal()), explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles());
result[0] = mavenRunner.runBatch(Collections.singletonList(params), null, null, TasksBundle.message("maven.tasks.executing"), indicator);
} finally {
targetDone.up();
}
}
@Override
public boolean shouldStartInBackground() {
return MavenRunner.getInstance(project).getSettings().isRunMavenInBackground();
}
@Override
public void processSentToBackground() {
MavenRunner.getInstance(project).getSettings().setRunMavenInBackground(true);
}
}.queue();
}, ModalityState.NON_MODAL);
} catch (Exception e) {
MavenLog.LOG.error(e);
return false;
}
targetDone.waitFor();
return result[0];
}
use of com.intellij.openapi.progress.Task in project intellij-community by JetBrains.
the class MavenUtil method runInBackground.
public static MavenTaskHandler runInBackground(final Project project, final String title, final boolean cancellable, final MavenTask task) {
final MavenProgressIndicator indicator = new MavenProgressIndicator();
Runnable runnable = () -> {
if (project.isDisposed())
return;
try {
task.run(indicator);
} catch (MavenProcessCanceledException | ProcessCanceledException ignore) {
indicator.cancel();
}
};
if (isNoBackgroundMode()) {
runnable.run();
return new MavenTaskHandler() {
public void waitFor() {
}
};
} else {
final Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(runnable);
final MavenTaskHandler handler = new MavenTaskHandler() {
public void waitFor() {
try {
future.get();
} catch (InterruptedException | ExecutionException e) {
MavenLog.LOG.error(e);
}
}
};
invokeLater(project, () -> {
if (future.isDone())
return;
new Task.Backgroundable(project, title, cancellable) {
public void run(@NotNull ProgressIndicator i) {
indicator.setIndicator(i);
handler.waitFor();
}
}.queue();
});
return handler;
}
}
use of com.intellij.openapi.progress.Task in project intellij-community by JetBrains.
the class ExternalSystemUtil method runTask.
public static void runTask(@NotNull final ExternalSystemTaskExecutionSettings taskSettings, @NotNull final String executorId, @NotNull final Project project, @NotNull final ProjectSystemId externalSystemId, @Nullable final TaskCallback callback, @NotNull final ProgressExecutionMode progressExecutionMode, boolean activateToolWindowBeforeRun) {
ExecutionEnvironment environment = createExecutionEnvironment(project, externalSystemId, taskSettings, executorId);
if (environment == null)
return;
RunnerAndConfigurationSettings runnerAndConfigurationSettings = environment.getRunnerAndConfigurationSettings();
assert runnerAndConfigurationSettings != null;
runnerAndConfigurationSettings.setActivateToolWindowBeforeRun(activateToolWindowBeforeRun);
final TaskUnderProgress task = new TaskUnderProgress() {
@Override
public void execute(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
final Semaphore targetDone = new Semaphore();
final Ref<Boolean> result = new Ref<>(false);
final Disposable disposable = Disposer.newDisposable();
project.getMessageBus().connect(disposable).subscribe(ExecutionManager.EXECUTION_TOPIC, new ExecutionListener() {
public void processStartScheduled(@NotNull final String executorIdLocal, @NotNull final ExecutionEnvironment environmentLocal) {
if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
targetDone.down();
}
}
public void processNotStarted(@NotNull final String executorIdLocal, @NotNull final ExecutionEnvironment environmentLocal) {
if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
targetDone.up();
}
}
public void processStarted(@NotNull final String executorIdLocal, @NotNull final ExecutionEnvironment environmentLocal, @NotNull final ProcessHandler handler) {
if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
handler.addProcessListener(new ProcessAdapter() {
public void processTerminated(ProcessEvent event) {
result.set(event.getExitCode() == 0);
targetDone.up();
}
});
}
}
});
try {
ApplicationManager.getApplication().invokeAndWait(() -> {
try {
environment.getRunner().execute(environment);
} catch (ExecutionException e) {
targetDone.up();
LOG.error(e);
}
}, ModalityState.defaultModalityState());
} catch (Exception e) {
LOG.error(e);
Disposer.dispose(disposable);
return;
}
targetDone.waitFor();
Disposer.dispose(disposable);
if (callback != null) {
if (result.get()) {
callback.onSuccess();
} else {
callback.onFailure();
}
}
}
};
final String title = AbstractExternalSystemTaskConfigurationType.generateName(project, taskSettings);
switch(progressExecutionMode) {
case NO_PROGRESS_SYNC:
task.execute(new EmptyProgressIndicator());
break;
case MODAL_SYNC:
new Task.Modal(project, title, true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
task.execute(indicator);
}
}.queue();
break;
case NO_PROGRESS_ASYNC:
ApplicationManager.getApplication().executeOnPooledThread(() -> task.execute(new EmptyProgressIndicator()));
break;
case IN_BACKGROUND_ASYNC:
new Task.Backgroundable(project, title) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
task.execute(indicator);
}
}.queue();
break;
case START_IN_FOREGROUND_ASYNC:
new Task.Backgroundable(project, title, true, PerformInBackgroundOption.DEAF) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
task.execute(indicator);
}
}.queue();
}
}
use of com.intellij.openapi.progress.Task in project intellij-community by JetBrains.
the class LogConsoleBase method getSearchComponent.
@Override
public JComponent getSearchComponent() {
myLogFilterCombo.setModel(new DefaultComboBoxModel(myFilters.toArray(new LogFilter[myFilters.size()])));
resetLogFilter();
myLogFilterCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final LogFilter filter = (LogFilter) myLogFilterCombo.getSelectedItem();
final Task.Backgroundable task = new Task.Backgroundable(myProject, APPLYING_FILTER_TITLE) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
myModel.selectFilter(filter);
}
};
ProgressManager.getInstance().run(task);
}
});
myTextFilterWrapper.removeAll();
myTextFilterWrapper.add(getTextFilterComponent());
return mySearchComponent;
}
Aggregations