use of com.intellij.compiler.progress.CompilerTask in project intellij-community by JetBrains.
the class CompileDriver method executeCompileTasks.
private boolean executeCompileTasks(final CompileContext context, final boolean beforeTasks) {
if (myProject.isDisposed()) {
return false;
}
final CompilerManager manager = CompilerManager.getInstance(myProject);
final ProgressIndicator progressIndicator = context.getProgressIndicator();
progressIndicator.pushState();
try {
CompileTask[] tasks = beforeTasks ? manager.getBeforeTasks() : manager.getAfterTasks();
if (tasks.length > 0) {
progressIndicator.setText(CompilerBundle.message(beforeTasks ? "progress.executing.precompile.tasks" : "progress.executing.postcompile.tasks"));
for (CompileTask task : tasks) {
if (!task.execute(context)) {
return false;
}
}
}
} finally {
progressIndicator.popState();
StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject);
if (statusBar != null) {
statusBar.setInfo("");
}
if (progressIndicator instanceof CompilerTask) {
ApplicationManager.getApplication().invokeLater(((CompilerTask) progressIndicator)::showCompilerContent);
}
}
return true;
}
use of com.intellij.compiler.progress.CompilerTask 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());
}
use of com.intellij.compiler.progress.CompilerTask in project intellij-community by JetBrains.
the class CompileDriver method executeCompileTask.
public void executeCompileTask(final CompileTask task, final CompileScope scope, final String contentName, final Runnable onTaskFinished) {
final CompilerTask progressManagerTask = new CompilerTask(myProject, contentName, false, false, true, isCompilationStartedAutomatically(scope));
final CompileContextImpl compileContext = new CompileContextImpl(myProject, progressManagerTask, scope, false, false);
FileDocumentManager.getInstance().saveAllDocuments();
progressManagerTask.start(() -> {
try {
task.execute(compileContext);
} catch (ProcessCanceledException ex) {
// suppressed
} finally {
if (onTaskFinished != null) {
onTaskFinished.run();
}
}
}, null);
}
use of com.intellij.compiler.progress.CompilerTask 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);
});
}
use of com.intellij.compiler.progress.CompilerTask in project android by JetBrains.
the class AndroidCompileUtil method doGenerate.
public static boolean doGenerate(AndroidFacet facet, final AndroidAutogeneratorMode mode) {
assert !ApplicationManager.getApplication().isDispatchThread();
final CompileContext[] contextWrapper = new CompileContext[1];
final Module module = facet.getModule();
final Project project = module.getProject();
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
if (project.isDisposed())
return;
CompilerTask task = new CompilerTask(project, "Android auto-generation", true, false, true, true);
CompileScope scope = new ModuleCompileScope(module, false);
contextWrapper[0] = new CompileContextImpl(project, task, scope, false, false);
}
});
CompileContext context = contextWrapper[0];
if (context == null) {
return false;
}
generate(facet, mode, context, false);
return context.getMessages(CompilerMessageCategory.ERROR).length == 0;
}
Aggregations