Search in sources :

Example 71 with Semaphore

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();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Semaphore(com.intellij.util.concurrency.Semaphore) ExecutionException(com.intellij.execution.ExecutionException)

Example 72 with Semaphore

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();
    }
}
Also used : Project(com.intellij.openapi.project.Project) AccessToken(com.intellij.openapi.application.AccessToken) Semaphore(com.intellij.util.concurrency.Semaphore) DumbService(com.intellij.openapi.project.DumbService) Application(com.intellij.openapi.application.Application)

Example 73 with Semaphore

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;
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) IOException(java.io.IOException) Semaphore(com.intellij.util.concurrency.Semaphore)

Example 74 with Semaphore

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();
}
Also used : PhoneGapCommandLine(com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine) Task(com.intellij.openapi.progress.Task) BeforeRunTask(com.intellij.execution.BeforeRunTask) ArrayList(java.util.ArrayList) Semaphore(com.intellij.util.concurrency.Semaphore) Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProcessOutput(com.intellij.execution.process.ProcessOutput)

Aggregations

Semaphore (com.intellij.util.concurrency.Semaphore)74 Ref (com.intellij.openapi.util.Ref)10 Project (com.intellij.openapi.project.Project)8 IOException (java.io.IOException)8 Nullable (org.jetbrains.annotations.Nullable)8 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)7 NotNull (org.jetbrains.annotations.NotNull)7 Test (org.junit.Test)7 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 ProcessEvent (com.intellij.execution.process.ProcessEvent)5 File (java.io.File)5 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)4 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)4 Disposable (com.intellij.openapi.Disposable)4 Application (com.intellij.openapi.application.Application)4 Task (com.intellij.openapi.progress.Task)4 VcsAbstractHistorySession (com.intellij.openapi.vcs.history.VcsAbstractHistorySession)4 VcsAppendableHistorySessionPartner (com.intellij.openapi.vcs.history.VcsAppendableHistorySessionPartner)4 VcsHistoryProvider (com.intellij.openapi.vcs.history.VcsHistoryProvider)4