use of com.intellij.util.concurrency.Semaphore in project android by JetBrains.
the class DistributionService method refreshSynchronously.
/**
* Loads the latest distributions, and returns when complete.
*/
public void refreshSynchronously() {
final Semaphore completed = new Semaphore();
completed.down();
Runnable complete = new Runnable() {
@Override
public void run() {
completed.up();
}
};
refresh(complete, complete);
completed.waitFor();
}
use of com.intellij.util.concurrency.Semaphore in project android by JetBrains.
the class GradleTaskRunner method newRunner.
static GradleTaskRunner newRunner(@NotNull Project project) {
return new GradleTaskRunner() {
@Override
public boolean run(@NotNull List<String> tasks, @Nullable BuildMode buildMode, @NotNull List<String> commandLineArguments) throws InvocationTargetException, InterruptedException {
assert !ApplicationManager.getApplication().isDispatchThread();
final GradleBuildInvoker gradleBuildInvoker = GradleBuildInvoker.getInstance(project);
final AtomicBoolean success = new AtomicBoolean();
final Semaphore done = new Semaphore();
done.down();
final GradleBuildInvoker.AfterGradleInvocationTask afterTask = new GradleBuildInvoker.AfterGradleInvocationTask() {
@Override
public void execute(@NotNull GradleInvocationResult result) {
success.set(result.isBuildSuccessful());
gradleBuildInvoker.remove(this);
done.up();
}
};
// To ensure that the "Run Configuration" waits for the Gradle tasks to be executed, we use SwingUtilities.invokeAndWait. I tried
// using Application.invokeAndWait but it never worked. IDEA also uses SwingUtilities in this scenario (see CompileStepBeforeRun.)
TransactionGuard.submitTransaction(project, () -> {
gradleBuildInvoker.add(afterTask);
gradleBuildInvoker.executeTasks(tasks, buildMode, commandLineArguments);
});
done.waitFor();
return success.get();
}
};
}
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 FlexUnitExecutionTest method doTest.
private AbstractTestProxy doTest(boolean debugNotRun, FlexUnitRunnerParameters.Scope testScope, String testClassOrPackage, @Nullable String testMethod, @Nullable String projectRoot, @Nullable FlexUnitRunnerParameters.OutputLogLevel outputLogLevel, String... files) throws Exception {
configureByFiles(projectRoot, files);
final Ref<IXMLElement> expected = new Ref<>();
UIUtil.invokeAndWaitIfNeeded((Runnable) () -> WriteAction.run(() -> {
try {
Collection<IXMLElement> collection = JSTestUtils.extractXml(myEditor.getDocument(), "testResults");
assertEquals("Invalid expected structure", 1, collection.size());
expected.set(collection.iterator().next());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}));
UIUtil.invokeAndWaitIfNeeded((Runnable) () -> WriteAction.run(() -> FlexTestUtils.modifyBuildConfiguration(myModule, configuration -> configuration.setTargetPlatform(myTargetPlatform))));
final RunnerAndConfigurationSettings runnerAndConfigurationSettings = RunManager.getInstance(myProject).createRunConfiguration("test", FlexUnitRunConfigurationType.getFactory());
final FlexUnitRunConfiguration flexUnitRunConfig = (FlexUnitRunConfiguration) runnerAndConfigurationSettings.getConfiguration();
final FlexUnitRunnerParameters params = flexUnitRunConfig.getRunnerParameters();
params.setModuleName(myModule.getName());
params.setBCName(FlexBuildConfigurationManager.getInstance(myModule).getBuildConfigurations()[0].getName());
params.setOutputLogLevel(outputLogLevel);
params.setScope(testScope);
switch(testScope) {
case Class:
params.setClassName(testClassOrPackage);
break;
case Method:
params.setClassName(testClassOrPackage);
params.setMethodName(testMethod);
break;
case Package:
params.setPackageName(testClassOrPackage);
break;
default:
fail("Unknown scope: " + testScope);
}
flexUnitRunConfig.checkConfiguration();
final ProgramRunner runner = new FlexUnitTestRunner();
final Executor executor = debugNotRun ? DefaultDebugExecutor.getDebugExecutorInstance() : DefaultRunExecutor.getRunExecutorInstance();
final ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, runnerAndConfigurationSettings, getProject());
final Semaphore compilation = new Semaphore();
compilation.down();
final Semaphore execution = new Semaphore();
execution.down();
final Semaphore startup = new Semaphore();
final ProcessListener listener = new ProcessListener() {
@Override
public void startNotified(ProcessEvent event) {
startup.up();
}
@Override
public void processTerminated(ProcessEvent event) {
execution.up();
}
@Override
public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
}
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
System.out.println("FlexUnit: " + event.getText());
}
};
final Ref<ExecutionConsole> executionConsole = new Ref<>();
ApplicationManager.getApplication().invokeLater(() -> {
try {
runner.execute(env, new ProgramRunner.Callback() {
@Override
public void processStarted(RunContentDescriptor descriptor) {
compilation.up();
startup.down();
descriptor.getProcessHandler().addProcessListener(listener);
executionConsole.set(descriptor.getExecutionConsole());
}
});
} catch (Throwable t) {
t.printStackTrace();
fail(t.getMessage());
compilation.up();
startup.up();
execution.up();
}
});
if (!compilation.waitFor(COMPILATION_TIMEOUT * 1000)) {
fail("Compilation did not succeed in " + COMPILATION_TIMEOUT + " seconds. There was an error or it took too long\n" + FlexCompilerHandler.getInstance(myProject).getLastCompilationMessages());
}
if (!startup.waitFor(STARTUP_TIMEOUT * 1000)) {
fail("Process was not started in " + STARTUP_TIMEOUT + " seconds");
}
if (!execution.waitFor(EXECUTION_TIMEOUT * 1000)) {
fail("Execution did not finish in " + EXECUTION_TIMEOUT + " seconds");
}
// give tests tree some time to stabilize
Thread.sleep(200);
final AbstractTestProxy testRoot = ((SMTRunnerConsoleView) executionConsole.get()).getResultsViewer().getRoot();
checkResults(expected.get(), testRoot);
if (outputLogLevel == null) {
checkOutput(testRoot, outputLogLevel);
}
return testRoot;
}
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();
}
Aggregations