Search in sources :

Example 1 with ExitStatus

use of com.intellij.compiler.impl.ExitStatus in project intellij-community by JetBrains.

the class BaseCompilerTestCase method compile.

private CompilationLog compile(final Consumer<CompileStatusNotification> action) {
    final Ref<CompilationLog> result = Ref.create(null);
    final Semaphore semaphore = new Semaphore();
    semaphore.down();
    final List<String> generatedFilePaths = new ArrayList<>();
    getCompilerManager().addCompilationStatusListener(new CompilationStatusAdapter() {

        @Override
        public void fileGenerated(String outputRoot, String relativePath) {
            generatedFilePaths.add(relativePath);
        }
    }, getTestRootDisposable());
    UIUtil.invokeAndWaitIfNeeded((Runnable) () -> {
        final CompileStatusNotification callback = new CompileStatusNotification() {

            @Override
            public void finished(boolean aborted, int errors, int warnings, CompileContext compileContext) {
                try {
                    if (aborted) {
                        Assert.fail("compilation aborted");
                    }
                    ExitStatus status = CompileDriver.getExternalBuildExitStatus(compileContext);
                    result.set(new CompilationLog(status == ExitStatus.UP_TO_DATE, generatedFilePaths, compileContext.getMessages(CompilerMessageCategory.ERROR), compileContext.getMessages(CompilerMessageCategory.WARNING)));
                } finally {
                    semaphore.up();
                }
            }
        };
        PlatformTestUtil.saveProject(myProject);
        CompilerTestUtil.saveApplicationSettings();
        action.accept(callback);
    });
    final long start = System.currentTimeMillis();
    while (!semaphore.waitFor(10)) {
        if (System.currentTimeMillis() - start > 5 * 60 * 1000) {
            throw new RuntimeException("timeout");
        }
        if (SwingUtilities.isEventDispatchThread()) {
            UIUtil.dispatchAllInvocationEvents();
        }
    }
    if (SwingUtilities.isEventDispatchThread()) {
        UIUtil.dispatchAllInvocationEvents();
    }
    return result.get();
}
Also used : Semaphore(com.intellij.util.concurrency.Semaphore) ExitStatus(com.intellij.compiler.impl.ExitStatus)

Aggregations

ExitStatus (com.intellij.compiler.impl.ExitStatus)1 Semaphore (com.intellij.util.concurrency.Semaphore)1