From 5faa3dfd9c8b81a4feac85fd07dd0d822a71bad3 Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Wed, 25 Mar 2015 18:09:47 +0300 Subject: [PATCH] gradle: check for gradle cancellation support reworked --- .../execution/NotSupportedException.java | 42 ++++++++++ .../internal/AbstractExternalSystemTask.java | 9 ++- .../GradleBuildProcessParametersProvider.java | 2 +- .../UnsupportedCancellationToken.java | 36 +++++++++ .../project/GradleExecutionHelper.java | 14 +++- .../project/GradleProjectResolver.java | 21 +++-- .../service/task/GradleTaskManager.java | 14 +++- .../plugins/gradle/util/GradleLog.java | 76 ------------------- .../gradle/model/ProjectImportAction.java | 4 - 9 files changed, 121 insertions(+), 97 deletions(-) create mode 100644 platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/NotSupportedException.java create mode 100644 plugins/gradle/src/org/jetbrains/plugins/gradle/service/execution/UnsupportedCancellationToken.java diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/NotSupportedException.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/NotSupportedException.java new file mode 100644 index 000000000000..31e6533c685c --- /dev/null +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/NotSupportedException.java @@ -0,0 +1,42 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.externalSystem.service.execution; + +import com.intellij.openapi.externalSystem.model.ExternalSystemException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Vladislav.Soroka + * @since 12/12/2014 + */ +public class NotSupportedException extends ExternalSystemException { + public NotSupportedException(@Nullable String message) { + super(message); + } + + public NotSupportedException(@Nullable Throwable cause) { + super(cause); + } + + public NotSupportedException(@Nullable String message, @NotNull String... quickFixes) { + super(message, quickFixes); + } + + public NotSupportedException(@Nullable String message, @Nullable Throwable cause, @NotNull String... quickFixes) { + super(message, cause, quickFixes); + } +} diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/internal/AbstractExternalSystemTask.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/internal/AbstractExternalSystemTask.java index 305114cad264..3c7f5474e7e1 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/internal/AbstractExternalSystemTask.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/internal/AbstractExternalSystemTask.java @@ -6,7 +6,8 @@ import com.intellij.openapi.externalSystem.model.ProjectSystemId; import com.intellij.openapi.externalSystem.model.task.*; import com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager; import com.intellij.openapi.externalSystem.service.RemoteExternalSystemFacade; -import com.intellij.openapi.externalSystem.service.notification.ExternalSystemProgressNotificationManager; +import com.intellij.openapi.externalSystem.service.execution.NotSupportedException; +import com.intellij.openapi.externalSystem.service.notification.*; import com.intellij.openapi.externalSystem.util.ExternalSystemBundle; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; @@ -190,6 +191,12 @@ public abstract class AbstractExternalSystemTask implements ExternalSystemTask { setState(result ? ExternalSystemTaskState.CANCELED : ExternalSystemTaskState.CANCELLATION_FAILED); return result; } + catch (NotSupportedException e) { + NotificationData notification = + new NotificationData("Cancellation failed", e.getMessage(), NotificationCategory.WARNING, NotificationSource.PROJECT_SYNC); + notification.setBalloonNotification(true); + ExternalSystemNotificationManager.getInstance(getIdeProject()).showNotification(getExternalSystemId(), notification); + } catch (Throwable e) { setState(ExternalSystemTaskState.CANCELLATION_FAILED); myError.set(e); diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/compiler/GradleBuildProcessParametersProvider.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/compiler/GradleBuildProcessParametersProvider.java index c8ac2eb5699e..3b0d8a968747 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/compiler/GradleBuildProcessParametersProvider.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/compiler/GradleBuildProcessParametersProvider.java @@ -80,7 +80,7 @@ public class GradleBuildProcessParametersProvider extends BuildProcessParameters File[] children = FileUtil.notNullize(gradleLibDir.listFiles()); for (File child : children) { final String fileName = child.getName(); - if (fileName.endsWith(".jar") && !fileName.startsWith("logback-") && child.isFile()) { + if (fileName.endsWith(".jar") && child.isFile()) { classpath.add(child.getAbsolutePath()); } } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/execution/UnsupportedCancellationToken.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/execution/UnsupportedCancellationToken.java new file mode 100644 index 000000000000..06588f9c78f0 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/execution/UnsupportedCancellationToken.java @@ -0,0 +1,36 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.gradle.service.execution; + +import com.intellij.openapi.externalSystem.service.execution.NotSupportedException; +import org.gradle.tooling.CancellationToken; +import org.gradle.tooling.CancellationTokenSource; + +/** + * @author Vladislav.Soroka + * @since 3/25/2015 + */ +public class UnsupportedCancellationToken implements CancellationTokenSource { + @Override + public void cancel() { + throw new NotSupportedException("Configured version of Gradle does not support cancellation. \nPlease, use Gradle 2.1 or newer."); + } + + @Override + public CancellationToken token() { + return null; + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleExecutionHelper.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleExecutionHelper.java index 19337a39a90c..a9c51a871b03 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleExecutionHelper.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleExecutionHelper.java @@ -35,6 +35,7 @@ import org.gradle.tooling.internal.consumer.DefaultExecutorServiceFactory; import org.gradle.tooling.internal.consumer.DefaultGradleConnector; import org.gradle.tooling.internal.consumer.Distribution; import org.gradle.tooling.model.build.BuildEnvironment; +import org.gradle.util.GradleVersion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.gradle.settings.DistributionType; @@ -443,7 +444,18 @@ public class GradleExecutionHelper { } @Nullable - private static BuildEnvironment getBuildEnvironment(@NotNull ProjectConnection connection) { + public static GradleVersion getGradleVersion(@NotNull ProjectConnection connection) { + final BuildEnvironment buildEnvironment = getBuildEnvironment(connection); + + GradleVersion gradleVersion = null; + if (buildEnvironment != null) { + gradleVersion = GradleVersion.version(buildEnvironment.getGradle().getGradleVersion()); + } + return gradleVersion; + } + + @Nullable + public static BuildEnvironment getBuildEnvironment(@NotNull ProjectConnection connection) { try { return connection.getModel(BuildEnvironment.class); } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolver.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolver.java index 4f966f73f09d..83de04c74e6f 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolver.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolver.java @@ -44,10 +44,12 @@ import org.gradle.tooling.model.build.BuildEnvironment; import org.gradle.tooling.model.idea.BasicIdeaProject; import org.gradle.tooling.model.idea.IdeaModule; import org.gradle.tooling.model.idea.IdeaProject; +import org.gradle.util.GradleVersion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.gradle.model.ProjectImportAction; import org.jetbrains.plugins.gradle.remote.impl.GradleLibraryNamesMixer; +import org.jetbrains.plugins.gradle.service.execution.UnsupportedCancellationToken; import org.jetbrains.plugins.gradle.settings.ClassHolder; import org.jetbrains.plugins.gradle.settings.GradleExecutionSettings; import org.jetbrains.plugins.gradle.util.GradleConstants; @@ -150,6 +152,11 @@ public class GradleProjectResolver implements ExternalSystemProjectResolver buildActionExecutor = resolverCtx.getConnection().action(projectImportAction); @@ -169,6 +176,9 @@ public class GradleProjectResolver implements ExternalSystemProjectResolver resultProjectDataNode, @NotNull final ProjectConnectionDataNodeFunction projectConnectionDataNodeFunction) { diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/task/GradleTaskManager.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/task/GradleTaskManager.java index 3df75378985e..2120f77a3a3b 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/task/GradleTaskManager.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/task/GradleTaskManager.java @@ -32,11 +32,13 @@ import org.gradle.tooling.BuildLauncher; import org.gradle.tooling.CancellationTokenSource; import org.gradle.tooling.GradleConnector; import org.gradle.tooling.ProjectConnection; +import org.gradle.util.GradleVersion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.gradle.service.project.GradleExecutionHelper; import org.jetbrains.plugins.gradle.service.project.GradleProjectResolver; import org.jetbrains.plugins.gradle.service.project.GradleProjectResolverExtension; +import org.jetbrains.plugins.gradle.service.execution.UnsupportedCancellationToken; import org.jetbrains.plugins.gradle.settings.GradleExecutionSettings; import org.jetbrains.plugins.gradle.util.GradleConstants; @@ -118,11 +120,17 @@ public class GradleTaskManager extends AbstractExternalSystemTaskManager { - - @Override - protected void append(ILoggingEvent event) { - ThrowableProxy throwableProxy = - event.getThrowableProxy() instanceof ThrowableProxy ? (ThrowableProxy)event.getThrowableProxy() : null; - Throwable throwable = throwableProxy == null ? null : throwableProxy.getThrowable(); - - switch (event.getLevel().toInt()) { - case Level.ALL_INT: - case Level.TRACE_INT: - case Level.DEBUG_INT: - LOG.debug(event.getFormattedMessage(), throwable); - break; - case Level.INFO_INT: - LOG.info(event.getFormattedMessage(), throwable); - break; - case Level.WARN_INT: - LOG.warn(event.getFormattedMessage(), throwable); - break; - case Level.ERROR_INT: - LOG.error(event.getFormattedMessage(), throwable); - break; - case Level.OFF_INT: - break; - default: - LOG.debug(event.getFormattedMessage(), throwable); - break; - } - - if (NonCancellableConsumerConnectionAdapter.class.getName().equals(event.getLoggerName()) && - GRADLE_PROVIDER_DOES_NOT_SUPPORT_CANCELLATION_MESSAGE.equals(event.getMessage())) { - // see org.gradle.tooling.internal.consumer.connection.NonCancellableConsumerConnectionAdapter#handleCancellationPreOperation - - ExternalSystemProcessingManager processingManager = ServiceManager.getService(ExternalSystemProcessingManager.class); - final List canceledTasks = - processingManager - .findTasksOfState(GradleConstants.SYSTEM_ID, ExternalSystemTaskState.CANCELING, ExternalSystemTaskState.CANCELED); - for (ExternalSystemTask canceledTask : canceledTasks) { - final Project project = canceledTask.getId().findProject(); - if (project != null) { - String errorMessage = String.format("%s Open Gradle settings", - "Configured version of Gradle does not support cancellation. Please, use Gradle 2.1 or newer.\n", - OpenGradleSettingsCallback.ID); - NotificationData notification = new NotificationData( - "Gradle supports cancellation since 2.1 version", errorMessage, NotificationCategory.WARNING, - NotificationSource.PROJECT_SYNC); - notification.setListener(OpenGradleSettingsCallback.ID, new OpenGradleSettingsCallback(project)); - notification.setBalloonNotification(true); - ExternalSystemNotificationManager.getInstance(project).showNotification(GradleConstants.SYSTEM_ID, notification); - } - } - } - } - } } diff --git a/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ProjectImportAction.java b/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ProjectImportAction.java index 5b20894b318d..37b20de6ba83 100644 --- a/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ProjectImportAction.java +++ b/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ProjectImportAction.java @@ -55,10 +55,6 @@ public class ProjectImportAction implements BuildAction