Search in sources :

Example 1 with TaskFuture

use of org.jetbrains.jps.api.TaskFuture in project intellij-community by JetBrains.

the class CompileDriver method isUpToDate.

public boolean isUpToDate(CompileScope scope) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("isUpToDate operation started");
    }
    final CompilerTask task = new CompilerTask(myProject, "Classes up-to-date check", true, false, false, isCompilationStartedAutomatically(scope));
    final CompileContextImpl compileContext = new CompileContextImpl(myProject, task, scope, true, false);
    final Ref<ExitStatus> result = new Ref<>();
    task.start(() -> {
        final ProgressIndicator indicator = compileContext.getProgressIndicator();
        if (indicator.isCanceled() || myProject.isDisposed()) {
            return;
        }
        try {
            final TaskFuture future = compileInExternalProcess(compileContext, true);
            if (future != null) {
                while (!future.waitFor(200L, TimeUnit.MILLISECONDS)) {
                    if (indicator.isCanceled()) {
                        future.cancel(false);
                    }
                }
            }
        } catch (Throwable e) {
            LOG.error(e);
        } finally {
            result.set(COMPILE_SERVER_BUILD_STATUS.get(compileContext));
            if (!myProject.isDisposed()) {
                CompilerCacheManager.getInstance(myProject).flushCaches();
            }
        }
    }, null);
    if (LOG.isDebugEnabled()) {
        LOG.debug("isUpToDate operation finished");
    }
    return ExitStatus.UP_TO_DATE.equals(result.get());
}
Also used : Ref(com.intellij.openapi.util.Ref) CompilerTask(com.intellij.compiler.progress.CompilerTask) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) TaskFuture(org.jetbrains.jps.api.TaskFuture)

Example 2 with TaskFuture

use of org.jetbrains.jps.api.TaskFuture in project intellij-community by JetBrains.

the class CompileDriver method startup.

private void startup(final CompileScope scope, final boolean isRebuild, final boolean forceCompile, final CompileStatusNotification callback, final CompilerMessage message) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    final String contentName = CompilerBundle.message(forceCompile ? "compiler.content.name.compile" : "compiler.content.name.make");
    final boolean isUnitTestMode = ApplicationManager.getApplication().isUnitTestMode();
    final CompilerTask compileTask = new CompilerTask(myProject, contentName, isUnitTestMode, true, true, isCompilationStartedAutomatically(scope));
    StatusBar.Info.set("", myProject, "Compiler");
    // ensure the project model seen by build process is up-to-date
    myProject.save();
    if (!isUnitTestMode) {
        ApplicationManager.getApplication().saveSettings();
    }
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    FileDocumentManager.getInstance().saveAllDocuments();
    final CompileContextImpl compileContext = new CompileContextImpl(myProject, compileTask, scope, !isRebuild && !forceCompile, isRebuild);
    final Runnable compileWork = () -> {
        final ProgressIndicator indicator = compileContext.getProgressIndicator();
        if (indicator.isCanceled() || myProject.isDisposed()) {
            if (callback != null) {
                callback.finished(true, 0, 0, compileContext);
            }
            return;
        }
        CompilerCacheManager compilerCacheManager = CompilerCacheManager.getInstance(myProject);
        try {
            LOG.info("COMPILATION STARTED (BUILD PROCESS)");
            if (message != null) {
                compileContext.addMessage(message);
            }
            if (isRebuild) {
                CompilerUtil.runInContext(compileContext, "Clearing build system data...", (ThrowableRunnable<Throwable>) () -> compilerCacheManager.clearCaches(compileContext));
            }
            final boolean beforeTasksOk = executeCompileTasks(compileContext, true);
            final int errorCount = compileContext.getMessageCount(CompilerMessageCategory.ERROR);
            if (!beforeTasksOk || errorCount > 0) {
                COMPILE_SERVER_BUILD_STATUS.set(compileContext, errorCount > 0 ? ExitStatus.ERRORS : ExitStatus.CANCELLED);
                return;
            }
            final TaskFuture future = compileInExternalProcess(compileContext, false);
            if (future != null) {
                while (!future.waitFor(200L, TimeUnit.MILLISECONDS)) {
                    if (indicator.isCanceled()) {
                        future.cancel(false);
                    }
                }
                if (!executeCompileTasks(compileContext, false)) {
                    COMPILE_SERVER_BUILD_STATUS.set(compileContext, ExitStatus.CANCELLED);
                }
                if (compileContext.getMessageCount(CompilerMessageCategory.ERROR) > 0) {
                    COMPILE_SERVER_BUILD_STATUS.set(compileContext, ExitStatus.ERRORS);
                }
            }
        } catch (ProcessCanceledException ignored) {
            compileContext.putUserDataIfAbsent(COMPILE_SERVER_BUILD_STATUS, ExitStatus.CANCELLED);
        } catch (Throwable e) {
            // todo
            LOG.error(e);
        } finally {
            compilerCacheManager.flushCaches();
            final long duration = notifyCompilationCompleted(compileContext, callback, COMPILE_SERVER_BUILD_STATUS.get(compileContext));
            CompilerUtil.logDuration("\tCOMPILATION FINISHED (BUILD PROCESS); Errors: " + compileContext.getMessageCount(CompilerMessageCategory.ERROR) + "; warnings: " + compileContext.getMessageCount(CompilerMessageCategory.WARNING), duration);
        }
    };
    compileTask.start(compileWork, () -> {
        if (isRebuild) {
            final int rv = Messages.showOkCancelDialog(myProject, "You are about to rebuild the whole project.\nRun 'Build Project' instead?", "Confirm Project Rebuild", "Build", "Rebuild", Messages.getQuestionIcon());
            if (rv == Messages.OK) /*yes, please, do run make*/
            {
                startup(scope, false, false, callback, null);
                return;
            }
        }
        startup(scope, isRebuild, forceCompile, callback, message);
    });
}
Also used : CompilerTask(com.intellij.compiler.progress.CompilerTask) ThrowableRunnable(com.intellij.util.ThrowableRunnable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ThrowableRunnable(com.intellij.util.ThrowableRunnable) TaskFuture(org.jetbrains.jps.api.TaskFuture) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Aggregations

CompilerTask (com.intellij.compiler.progress.CompilerTask)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 TaskFuture (org.jetbrains.jps.api.TaskFuture)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Ref (com.intellij.openapi.util.Ref)1 ThrowableRunnable (com.intellij.util.ThrowableRunnable)1