Search in sources :

Example 1 with TaskCallback

use of com.intellij.openapi.externalSystem.task.TaskCallback in project intellij-community by JetBrains.

the class ExternalSystemTaskActivator method runTasksQueue.

private boolean runTasksQueue(final Queue<Pair<ProjectSystemId, ExternalSystemTaskExecutionSettings>> tasksQueue) {
    final Pair<ProjectSystemId, ExternalSystemTaskExecutionSettings> pair = tasksQueue.poll();
    if (pair == null)
        return true;
    final ProjectSystemId systemId = pair.first;
    final ExternalSystemTaskExecutionSettings executionSettings = pair.getSecond();
    final Semaphore targetDone = new Semaphore();
    targetDone.down();
    final Ref<Boolean> result = new Ref<>(false);
    ExternalSystemUtil.runTask(executionSettings, DefaultRunExecutor.EXECUTOR_ID, myProject, systemId, new TaskCallback() {

        @Override
        public void onSuccess() {
            result.set(runTasksQueue(tasksQueue));
            targetDone.up();
        }

        @Override
        public void onFailure() {
            targetDone.up();
        }
    }, ProgressExecutionMode.IN_BACKGROUND_ASYNC, false);
    targetDone.waitFor();
    return result.get();
}
Also used : Ref(com.intellij.openapi.util.Ref) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) TaskCallback(com.intellij.openapi.externalSystem.task.TaskCallback) Semaphore(com.intellij.util.concurrency.Semaphore) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)

Example 2 with TaskCallback

use of com.intellij.openapi.externalSystem.task.TaskCallback in project intellij-community by JetBrains.

the class GradleProjectTaskRunner method run.

@Override
public void run(@NotNull Project project, @NotNull ProjectTaskContext context, @Nullable ProjectTaskNotification callback, @NotNull Collection<? extends ProjectTask> tasks) {
    String executionName = "Gradle build";
    MultiMap<String, String> buildTasksMap = MultiMap.createLinkedSet();
    MultiMap<String, String> cleanTasksMap = MultiMap.createLinkedSet();
    Map<Class<? extends ProjectTask>, List<ProjectTask>> taskMap = InternalProjectTaskRunner.groupBy(tasks);
    addModulesBuildTasks(taskMap.get(ModuleBuildTask.class), cleanTasksMap, buildTasksMap);
    // TODO there should be 'gradle' way to build files instead of related modules entirely
    addModulesBuildTasks(taskMap.get(ModuleFilesBuildTask.class), cleanTasksMap, buildTasksMap);
    addArtifactsBuildTasks(taskMap.get(ArtifactBuildTask.class), cleanTasksMap, buildTasksMap);
    // TODO send a message if nothing to build
    Set<String> rootPaths = buildTasksMap.keySet();
    AtomicInteger successCounter = new AtomicInteger();
    AtomicInteger errorCounter = new AtomicInteger();
    TaskCallback taskCallback = callback == null ? null : new TaskCallback() {

        @Override
        public void onSuccess() {
            handle(true);
        }

        @Override
        public void onFailure() {
            handle(false);
        }

        private void handle(boolean success) {
            int successes = success ? successCounter.incrementAndGet() : successCounter.get();
            int errors = success ? errorCounter.get() : errorCounter.incrementAndGet();
            if (successes + errors == rootPaths.size()) {
                callback.finished(new ProjectTaskResult(false, errors, 0));
            }
        }
    };
    String gradleVmOptions = GradleSettings.getInstance(project).getGradleVmOptions();
    for (String rootProjectPath : rootPaths) {
        Collection<String> buildTasks = buildTasksMap.get(rootProjectPath);
        if (buildTasks.isEmpty())
            continue;
        Collection<String> cleanTasks = cleanTasksMap.get(rootProjectPath);
        ExternalSystemTaskExecutionSettings settings = new ExternalSystemTaskExecutionSettings();
        settings.setExecutionName(executionName);
        settings.setExternalProjectPath(rootProjectPath);
        settings.setTaskNames(ContainerUtil.collect(ContainerUtil.concat(cleanTasks, buildTasks).iterator()));
        //settings.setScriptParameters(scriptParameters);
        settings.setVmOptions(gradleVmOptions);
        settings.setExternalSystemIdString(GradleConstants.SYSTEM_ID.getId());
        ExternalSystemUtil.runTask(settings, DefaultRunExecutor.EXECUTOR_ID, project, GradleConstants.SYSTEM_ID, taskCallback, ProgressExecutionMode.IN_BACKGROUND_ASYNC, false);
    }
}
Also used : TaskCallback(com.intellij.openapi.externalSystem.task.TaskCallback) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) List(java.util.List) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)

Aggregations

ExternalSystemTaskExecutionSettings (com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)2 TaskCallback (com.intellij.openapi.externalSystem.task.TaskCallback)2 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)1 Ref (com.intellij.openapi.util.Ref)1 Semaphore (com.intellij.util.concurrency.Semaphore)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1