Search in sources :

Example 1 with CompilationStatusListener

use of com.intellij.openapi.compiler.CompilationStatusListener in project android by JetBrains.

the class IdeFrameFixture method invokeProjectMakeUsingJps.

@NotNull
public CompileContext invokeProjectMakeUsingJps() {
    Project project = getProject();
    AndroidGradleBuildConfiguration buildConfiguration = AndroidGradleBuildConfiguration.getInstance(project);
    buildConfiguration.USE_EXPERIMENTAL_FASTER_BUILD = false;
    AtomicReference<CompileContext> contextRef = new AtomicReference<>();
    CompilerManager compilerManager = CompilerManager.getInstance(project);
    Disposable disposable = new NoOpDisposable();
    compilerManager.addCompilationStatusListener(new CompilationStatusListener() {

        @Override
        public void compilationFinished(boolean aborted, int errors, int warnings, CompileContext compileContext) {
            contextRef.set(compileContext);
        }
    }, disposable);
    try {
        selectProjectMakeAction();
        Wait.seconds(10).expecting("Build (" + COMPILE_JAVA + ") for project " + quote(project.getName()) + " to finish'").until(() -> contextRef.get() != null);
        return contextRef.get();
    } finally {
        Disposer.dispose(disposable);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) Project(com.intellij.openapi.project.Project) CompilerManager(com.intellij.openapi.compiler.CompilerManager) CompilationStatusListener(com.intellij.openapi.compiler.CompilationStatusListener) AndroidGradleBuildConfiguration(com.android.tools.idea.gradle.project.build.compiler.AndroidGradleBuildConfiguration) AtomicReference(java.util.concurrent.atomic.AtomicReference) CompileContext(com.intellij.openapi.compiler.CompileContext) Assert.assertNotNull(junit.framework.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CompilationStatusListener

use of com.intellij.openapi.compiler.CompilationStatusListener in project intellij-community by JetBrains.

the class JavaAutoRunManager method createWatcher.

@NotNull
@Override
protected AutoTestWatcher createWatcher(Project project) {
    return new AutoTestWatcher() {

        private boolean myHasErrors = false;

        private CompilationStatusListener myStatusListener;

        @Override
        public void activate() {
            if (myStatusListener == null) {
                myStatusListener = new CompilationStatusListener() {

                    private boolean myFoundFilesToMake = false;

                    @Override
                    public void compilationFinished(boolean aborted, int errors, int warnings, CompileContext compileContext) {
                        if (!myFoundFilesToMake)
                            return;
                        if (errors == 0) {
                            restartAllAutoTests(0);
                        }
                        myHasErrors = errors == 0;
                        myFoundFilesToMake = false;
                    }

                    @Override
                    public void automakeCompilationFinished(int errors, int warnings, CompileContext compileContext) {
                        compilationFinished(false, errors, warnings, compileContext);
                    }

                    @Override
                    public void fileGenerated(String outputRoot, String relativePath) {
                        myFoundFilesToMake = true;
                    }
                };
                CompilerManager.getInstance(project).addCompilationStatusListener(myStatusListener, project);
            }
        }

        @Override
        public void deactivate() {
            if (myStatusListener != null) {
                CompilerManager.getInstance(project).removeCompilationStatusListener(myStatusListener);
            }
        }

        @Override
        public boolean isUpToDate(int modificationStamp) {
            return !myHasErrors;
        }
    };
}
Also used : AutoTestWatcher(com.intellij.execution.testframework.autotest.AutoTestWatcher) CompilationStatusListener(com.intellij.openapi.compiler.CompilationStatusListener) CompileContext(com.intellij.openapi.compiler.CompileContext) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

CompilationStatusListener (com.intellij.openapi.compiler.CompilationStatusListener)2 CompileContext (com.intellij.openapi.compiler.CompileContext)2 NotNull (org.jetbrains.annotations.NotNull)2 AndroidGradleBuildConfiguration (com.android.tools.idea.gradle.project.build.compiler.AndroidGradleBuildConfiguration)1 AutoTestWatcher (com.intellij.execution.testframework.autotest.AutoTestWatcher)1 Disposable (com.intellij.openapi.Disposable)1 CompilerManager (com.intellij.openapi.compiler.CompilerManager)1 Project (com.intellij.openapi.project.Project)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Assert.assertNotNull (junit.framework.Assert.assertNotNull)1