Search in sources :

Example 1 with RunProfileWithCompileBeforeLaunchOption

use of com.intellij.execution.configurations.RunProfileWithCompileBeforeLaunchOption in project intellij-community by JetBrains.

the class CompileStepBeforeRun method doMake.

static boolean doMake(final Project myProject, final RunConfiguration configuration, final ExecutionEnvironment env, final boolean ignoreErrors, final boolean forceMakeProject) {
    if (!(configuration instanceof RunProfileWithCompileBeforeLaunchOption)) {
        return true;
    }
    if (configuration instanceof RunConfigurationBase && ((RunConfigurationBase) configuration).excludeCompileBeforeLaunchOption()) {
        return true;
    }
    final RunProfileWithCompileBeforeLaunchOption runConfiguration = (RunProfileWithCompileBeforeLaunchOption) configuration;
    final Ref<Boolean> result = new Ref<>(Boolean.FALSE);
    try {
        final Semaphore done = new Semaphore();
        done.down();
        final ProjectTaskNotification callback = new ProjectTaskNotification() {

            public void finished(@NotNull ProjectTaskResult executionResult) {
                if ((executionResult.getErrors() == 0 || ignoreErrors) && !executionResult.isAborted()) {
                    result.set(Boolean.TRUE);
                }
                done.up();
            }
        };
        TransactionGuard.submitTransaction(myProject, () -> {
            ProjectTask projectTask;
            Object sessionId = ExecutionManagerImpl.EXECUTION_SESSION_ID_KEY.get(env);
            final ProjectTaskManager projectTaskManager = ProjectTaskManager.getInstance(myProject);
            if (forceMakeProject) {
                // user explicitly requested whole-project make
                projectTask = projectTaskManager.createAllModulesBuildTask(true, myProject);
            } else {
                final Module[] modules = runConfiguration.getModules();
                if (modules.length > 0) {
                    for (Module module : modules) {
                        if (module == null) {
                            LOG.error("RunConfiguration should not return null modules. Configuration=" + runConfiguration.getName() + "; class=" + runConfiguration.getClass().getName());
                        }
                    }
                    projectTask = projectTaskManager.createModulesBuildTask(modules, true, true, true);
                } else {
                    projectTask = projectTaskManager.createAllModulesBuildTask(true, myProject);
                }
            }
            if (!myProject.isDisposed()) {
                projectTaskManager.run(new ProjectTaskContext(sessionId, configuration), projectTask, callback);
            } else {
                done.up();
            }
        });
        done.waitFor();
    } catch (Exception e) {
        return false;
    }
    return result.get();
}
Also used : Semaphore(com.intellij.util.concurrency.Semaphore) NotNull(org.jetbrains.annotations.NotNull) RunConfigurationBase(com.intellij.execution.configurations.RunConfigurationBase) Ref(com.intellij.openapi.util.Ref) RunProfileWithCompileBeforeLaunchOption(com.intellij.execution.configurations.RunProfileWithCompileBeforeLaunchOption) Module(com.intellij.openapi.module.Module)

Aggregations

RunConfigurationBase (com.intellij.execution.configurations.RunConfigurationBase)1 RunProfileWithCompileBeforeLaunchOption (com.intellij.execution.configurations.RunProfileWithCompileBeforeLaunchOption)1 Module (com.intellij.openapi.module.Module)1 Ref (com.intellij.openapi.util.Ref)1 Semaphore (com.intellij.util.concurrency.Semaphore)1 NotNull (org.jetbrains.annotations.NotNull)1