use of com.intellij.util.concurrency.Semaphore in project intellij-plugins by JetBrains.
the class DesignerApplicationLauncher method runAndWaitDebugger.
private boolean runAndWaitDebugger() {
final AtomicBoolean result = new AtomicBoolean();
final Semaphore debuggerRunSemaphore = new Semaphore();
debuggerRunSemaphore.down();
ApplicationManager.getApplication().invokeLater(() -> {
try {
runDebugger(module, () -> {
result.set(true);
debuggerRunSemaphore.up();
});
} catch (ExecutionException e) {
LOG.error(e);
debuggerRunSemaphore.up();
}
});
debuggerRunSemaphore.waitFor();
return result.get();
}
use of com.intellij.util.concurrency.Semaphore in project intellij-plugins by JetBrains.
the class ModuleInfoUtil method collectLocalStyle.
public static List<LocalStyleHolder> collectLocalStyle(final ModuleInfo moduleInfo, final String flexSdkVersion, final StringWriter stringWriter, final ProblemsHolder problemsHolder, ProjectComponentReferenceCounter projectComponentReferenceCounter, AssetCounter assetCounter) {
Project project = moduleInfo.getModule().getProject();
DumbService dumbService = DumbService.getInstance(project);
if (dumbService.isDumb()) {
dumbService.waitForSmartMode();
}
final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
if (psiDocumentManager.hasUncommitedDocuments()) {
final Semaphore semaphore = new Semaphore();
semaphore.down();
Application application = ApplicationManager.getApplication();
LogMessageUtil.LOG.assertTrue(!application.isReadAccessAllowed());
application.invokeLater(() -> psiDocumentManager.performWhenAllCommitted(() -> semaphore.up()));
semaphore.waitFor();
}
final AccessToken token = ReadAction.start();
try {
if (moduleInfo.isApp()) {
return collectApplicationLocalStyle(moduleInfo.getModule(), flexSdkVersion, problemsHolder, stringWriter, projectComponentReferenceCounter, assetCounter);
} else {
return collectLibraryLocalStyle(moduleInfo.getModule(), stringWriter, problemsHolder, projectComponentReferenceCounter, assetCounter);
}
} finally {
token.finish();
}
}
use of com.intellij.util.concurrency.Semaphore in project intellij-plugins by JetBrains.
the class FlexBuilder method doCompileWithBuiltInCompiler.
private static Status doCompileWithBuiltInCompiler(final CompileContext context, final JpsFlexBuildConfiguration bc, final List<File> configFiles, final String compilerName, final JpsBuiltInFlexCompilerHandler builtInCompilerHandler) {
try {
builtInCompilerHandler.startCompilerIfNeeded(bc.getSdk(), context, compilerName);
} catch (IOException e) {
context.processMessage(new CompilerMessage(compilerName, BuildMessage.Kind.ERROR, e.toString()));
return Status.Failed;
}
final List<String> mxmlcOrCompc = Collections.singletonList(bc.getOutputType() == OutputType.Library ? "compc" : "mxmlc");
final List<String> command = buildCommand(mxmlcOrCompc, configFiles, bc);
final String plainCommand = StringUtil.join(command, s -> s.indexOf(' ') >= 0 && !(s.startsWith("\"") && s.endsWith("\"")) ? '\"' + s + '\"' : s, " ");
final Semaphore semaphore = new Semaphore();
semaphore.down();
context.processMessage(new CompilerMessage(compilerName, BuildMessage.Kind.INFO, plainCommand));
final BuiltInCompilerListener listener = new BuiltInCompilerListener(context, compilerName, () -> semaphore.up());
builtInCompilerHandler.sendCompilationCommand(plainCommand, listener);
semaphore.waitFor();
builtInCompilerHandler.removeListener(listener);
return listener.isCompilationCancelled() ? Status.Cancelled : listener.isCompilationFailed() ? Status.Failed : Status.Ok;
}
use of com.intellij.util.concurrency.Semaphore in project intellij-plugins by JetBrains.
the class PhoneGapAddPlatformBeforeRun method executeTask.
@Override
public boolean executeTask(DataContext context, final RunConfiguration configuration, ExecutionEnvironment env, PhoneGapAddPlatformTask task) {
final PhoneGapRunConfiguration phoneGapRunConfiguration = (PhoneGapRunConfiguration) configuration;
final PhoneGapCommandLine line = phoneGapRunConfiguration.getCommandLine();
if (!line.needAddPlatform()) {
return true;
}
final Project project = configuration.getProject();
final Semaphore targetDone = new Semaphore();
final Ref<Boolean> result = new Ref<>(true);
final List<Exception> exceptions = new ArrayList<>();
ApplicationManager.getApplication().invokeAndWait(() -> {
//Save all opened documents
FileDocumentManager.getInstance().saveAllDocuments();
targetDone.down();
new Task.Backgroundable(project, PhoneGapBundle.message("phonegap.before.task.init.title"), true) {
public boolean shouldStartInBackground() {
return true;
}
public void run(@NotNull final ProgressIndicator indicator) {
try {
String platform = phoneGapRunConfiguration.getPlatform();
assert platform != null;
ProcessOutput output = line.platformAdd(platform);
if (output.getExitCode() != 0) {
ExecutionHelper.showOutput(project, output, PhoneGapBundle.message("phonegap.before.task.init.title"), null, true);
result.set(false);
}
} catch (final Exception e) {
exceptions.add(e);
result.set(false);
} finally {
targetDone.up();
}
}
}.queue();
}, ModalityState.NON_MODAL);
if (!targetDone.waitFor(TimeUnit.MINUTES.toMillis(2))) {
ExecutionHelper.showErrors(project, ContainerUtil.createMaybeSingletonList(new RuntimeException("Timeout")), PhoneGapBundle.message("phonegap.before.task.init.error"), null);
} else if (!exceptions.isEmpty()) {
ExecutionHelper.showErrors(project, exceptions, PhoneGapBundle.message("phonegap.before.task.init.error"), null);
}
return result.get();
}
Aggregations