Search in sources :

Example 1 with ExternalSystemTaskExecutionEvent

use of com.intellij.openapi.externalSystem.model.task.event.ExternalSystemTaskExecutionEvent in project intellij-community by JetBrains.

the class GradleTaskManager method executeTasks.

@Override
public void executeTasks(@NotNull final ExternalSystemTaskId id, @NotNull final List<String> taskNames, @NotNull String projectPath, @Nullable GradleExecutionSettings settings, @Nullable final String jvmAgentSetup, @NotNull final ExternalSystemTaskNotificationListener listener) throws ExternalSystemException {
    // TODO add support for external process mode
    if (ExternalSystemApiUtil.isInProcessMode(GradleConstants.SYSTEM_ID)) {
        for (GradleTaskManagerExtension gradleTaskManagerExtension : GradleTaskManagerExtension.EP_NAME.getExtensions()) {
            if (gradleTaskManagerExtension.executeTasks(id, taskNames, projectPath, settings, jvmAgentSetup, listener)) {
                return;
            }
        }
    }
    GradleExecutionSettings effectiveSettings = settings == null ? new GradleExecutionSettings(null, null, DistributionType.BUNDLED, false) : settings;
    Function<ProjectConnection, Void> f = connection -> {
        final List<String> initScripts = ContainerUtil.newArrayList();
        final GradleProjectResolverExtension projectResolverChain = GradleProjectResolver.createProjectResolverChain(effectiveSettings);
        for (GradleProjectResolverExtension resolverExtension = projectResolverChain; resolverExtension != null; resolverExtension = resolverExtension.getNext()) {
            final String resolverClassName = resolverExtension.getClass().getName();
            resolverExtension.enhanceTaskProcessing(taskNames, jvmAgentSetup, script -> {
                if (StringUtil.isNotEmpty(script)) {
                    ContainerUtil.addAllNotNull(initScripts, "//-- Generated by " + resolverClassName, script, "//");
                }
            });
        }
        final String initScript = effectiveSettings.getUserData(INIT_SCRIPT_KEY);
        if (StringUtil.isNotEmpty(initScript)) {
            ContainerUtil.addAll(initScripts, "//-- Additional script", initScript, "//");
        }
        if (!initScripts.isEmpty()) {
            try {
                File tempFile = GradleExecutionHelper.writeToFileGradleInitScript(StringUtil.join(initScripts, SystemProperties.getLineSeparator()));
                effectiveSettings.withArguments(GradleConstants.INIT_SCRIPT_CMD_OPTION, tempFile.getAbsolutePath());
            } catch (IOException e) {
                throw new ExternalSystemException(e);
            }
        }
        GradleVersion gradleVersion = GradleExecutionHelper.getGradleVersion(connection);
        if (gradleVersion != null && gradleVersion.compareTo(GradleVersion.version("2.5")) < 0) {
            listener.onStatusChange(new ExternalSystemTaskExecutionEvent(id, new ExternalSystemProgressEventUnsupportedImpl(gradleVersion + " does not support executions view")));
        }
        for (GradleBuildParticipant buildParticipant : effectiveSettings.getExecutionWorkspace().getBuildParticipants()) {
            effectiveSettings.withArguments(GradleConstants.INCLUDE_BUILD_CMD_OPTION, buildParticipant.getProjectPath());
        }
        BuildLauncher launcher = myHelper.getBuildLauncher(id, connection, effectiveSettings, listener);
        launcher.forTasks(ArrayUtil.toStringArray(taskNames));
        if (gradleVersion != null && gradleVersion.compareTo(GradleVersion.version("2.1")) < 0) {
            myCancellationMap.put(id, new UnsupportedCancellationToken());
        } else {
            final CancellationTokenSource cancellationTokenSource = GradleConnector.newCancellationTokenSource();
            launcher.withCancellationToken(cancellationTokenSource.token());
            myCancellationMap.put(id, cancellationTokenSource);
        }
        try {
            launcher.run();
        } finally {
            myCancellationMap.remove(id);
        }
        return null;
    };
    myHelper.execute(projectPath, effectiveSettings, f);
}
Also used : GradleExecutionSettings(org.jetbrains.plugins.gradle.settings.GradleExecutionSettings) ExternalSystemTaskNotificationListener(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener) ArrayUtil(com.intellij.util.ArrayUtil) GradleExecutionSettings(org.jetbrains.plugins.gradle.settings.GradleExecutionSettings) GradleProjectResolver(org.jetbrains.plugins.gradle.service.project.GradleProjectResolver) ContainerUtil(com.intellij.util.containers.ContainerUtil) GradleExecutionHelper(org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper) ExternalSystemApiUtil(com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil) UnsupportedCancellationToken(org.jetbrains.plugins.gradle.service.execution.UnsupportedCancellationToken) Map(java.util.Map) GradleConnector(org.gradle.tooling.GradleConnector) GradleBuildParticipant(org.jetbrains.plugins.gradle.settings.GradleBuildParticipant) GradleProjectResolverExtension(org.jetbrains.plugins.gradle.service.project.GradleProjectResolverExtension) GradleVersion(org.gradle.util.GradleVersion) BuildLauncher(org.gradle.tooling.BuildLauncher) ExternalSystemTaskManager(com.intellij.openapi.externalSystem.task.ExternalSystemTaskManager) StringUtil(com.intellij.openapi.util.text.StringUtil) ExternalSystemTaskExecutionEvent(com.intellij.openapi.externalSystem.model.task.event.ExternalSystemTaskExecutionEvent) Key(com.intellij.openapi.util.Key) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) IOException(java.io.IOException) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) ExternalSystemTaskId(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId) CancellationTokenSource(org.gradle.tooling.CancellationTokenSource) DistributionType(org.jetbrains.plugins.gradle.settings.DistributionType) List(java.util.List) SystemProperties(com.intellij.util.SystemProperties) Function(com.intellij.util.Function) ExternalSystemProgressEventUnsupportedImpl(com.intellij.openapi.externalSystem.model.task.event.ExternalSystemProgressEventUnsupportedImpl) GradleConstants(org.jetbrains.plugins.gradle.util.GradleConstants) ProjectConnection(org.gradle.tooling.ProjectConnection) NotNull(org.jetbrains.annotations.NotNull) GradleProjectResolverExtension(org.jetbrains.plugins.gradle.service.project.GradleProjectResolverExtension) UnsupportedCancellationToken(org.jetbrains.plugins.gradle.service.execution.UnsupportedCancellationToken) ProjectConnection(org.gradle.tooling.ProjectConnection) ExternalSystemTaskExecutionEvent(com.intellij.openapi.externalSystem.model.task.event.ExternalSystemTaskExecutionEvent) IOException(java.io.IOException) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) BuildLauncher(org.gradle.tooling.BuildLauncher) CancellationTokenSource(org.gradle.tooling.CancellationTokenSource) List(java.util.List) GradleVersion(org.gradle.util.GradleVersion) File(java.io.File) GradleBuildParticipant(org.jetbrains.plugins.gradle.settings.GradleBuildParticipant) ExternalSystemProgressEventUnsupportedImpl(com.intellij.openapi.externalSystem.model.task.event.ExternalSystemProgressEventUnsupportedImpl)

Aggregations

ExternalSystemException (com.intellij.openapi.externalSystem.model.ExternalSystemException)1 ExternalSystemTaskId (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId)1 ExternalSystemTaskNotificationListener (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener)1 ExternalSystemProgressEventUnsupportedImpl (com.intellij.openapi.externalSystem.model.task.event.ExternalSystemProgressEventUnsupportedImpl)1 ExternalSystemTaskExecutionEvent (com.intellij.openapi.externalSystem.model.task.event.ExternalSystemTaskExecutionEvent)1 ExternalSystemTaskManager (com.intellij.openapi.externalSystem.task.ExternalSystemTaskManager)1 ExternalSystemApiUtil (com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil)1 Key (com.intellij.openapi.util.Key)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 ArrayUtil (com.intellij.util.ArrayUtil)1 Function (com.intellij.util.Function)1 SystemProperties (com.intellij.util.SystemProperties)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 File (java.io.File)1 IOException (java.io.IOException)1 List (java.util.List)1 Map (java.util.Map)1 BuildLauncher (org.gradle.tooling.BuildLauncher)1 CancellationTokenSource (org.gradle.tooling.CancellationTokenSource)1 GradleConnector (org.gradle.tooling.GradleConnector)1