From 6ee5fbcfe50c4e017eff321c5ebe208dd89d6945 Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Thu, 19 Dec 2013 13:20:52 +0400 Subject: [PATCH] IDEA-117792 Gradle Run/Debug Configuration: support adding Gradle specific parameters. Fix after review. + fix bug - http://youtrack.jetbrains.com/issue/IDEA-118470 --- .../ExternalSystemTaskExecutionSettings.java | 1 + .../AbstractExternalSystemTaskManager.java | 41 +++++++++++++++ .../task/ExternalSystemTaskManager.java | 6 ++- .../ExternalSystemExecuteTaskTask.java | 23 ++++++++- .../RemoteExternalSystemTaskManager.java | 8 +-- .../RemoteExternalSystemTaskManagerImpl.java | 13 +++-- .../ExternalSystemTaskManagerWrapper.java | 4 +- .../project/GradleExecutionHelper.java | 24 +-------- .../service/task/GradleTaskManager.java | 51 ++++++++++--------- .../task/GradleTaskManagerExtension.java | 3 +- 10 files changed, 116 insertions(+), 58 deletions(-) create mode 100644 platform/external-system-api/src/com/intellij/openapi/externalSystem/task/AbstractExternalSystemTaskManager.java diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/execution/ExternalSystemTaskExecutionSettings.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/execution/ExternalSystemTaskExecutionSettings.java index e3ae03fc9288..a9dacf975114 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/execution/ExternalSystemTaskExecutionSettings.java +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/execution/ExternalSystemTaskExecutionSettings.java @@ -102,6 +102,7 @@ public class ExternalSystemTaskExecutionSettings implements Cloneable { result.setExternalSystemIdString(getExternalSystemIdString()); result.setExternalProjectPath(getExternalProjectPath()); result.setVmOptions(getVmOptions()); + result.setScriptParameters(getScriptParameters()); result.setTaskNames(ContainerUtilRt.newArrayList(getTaskNames())); result.setTaskDescriptions(ContainerUtilRt.newArrayList(getTaskDescriptions())); return result; diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/task/AbstractExternalSystemTaskManager.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/task/AbstractExternalSystemTaskManager.java new file mode 100644 index 000000000000..0bb5a87464ba --- /dev/null +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/task/AbstractExternalSystemTaskManager.java @@ -0,0 +1,41 @@ +/* + * Copyright 2000-2013 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.task; + +import com.intellij.openapi.externalSystem.model.ExternalSystemException; +import com.intellij.openapi.externalSystem.model.settings.ExternalSystemExecutionSettings; +import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId; +import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +/** + * @author Vladislav.Soroka + * @since 12/19/13 + */ +public abstract class AbstractExternalSystemTaskManager implements ExternalSystemTaskManager { + + public abstract void executeTasks(@NotNull ExternalSystemTaskId id, + @NotNull List taskNames, + @NotNull String projectPath, + @Nullable S settings, + @NotNull final List vmOptions, + @NotNull List scriptParameters, + @Nullable String debuggerSetup, + @NotNull ExternalSystemTaskNotificationListener listener) throws ExternalSystemException; +} diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/task/ExternalSystemTaskManager.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/task/ExternalSystemTaskManager.java index 781f2edb93d2..c65c7a45fc26 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/task/ExternalSystemTaskManager.java +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/task/ExternalSystemTaskManager.java @@ -32,12 +32,16 @@ import java.util.List; */ public interface ExternalSystemTaskManager { + /** + * + * @deprecated will be removed in 13.1 + */ + @Deprecated void executeTasks(@NotNull ExternalSystemTaskId id, @NotNull List taskNames, @NotNull String projectPath, @Nullable S settings, @Nullable String vmOptions, - @Nullable String scriptParameters, @Nullable String debuggerSetup, @NotNull ExternalSystemTaskNotificationListener listener) throws ExternalSystemException; diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/internal/ExternalSystemExecuteTaskTask.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/internal/ExternalSystemExecuteTaskTask.java index d843e15dcefd..b5e4eb345823 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/internal/ExternalSystemExecuteTaskTask.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/internal/ExternalSystemExecuteTaskTask.java @@ -25,7 +25,9 @@ import com.intellij.openapi.externalSystem.service.RemoteExternalSystemFacade; import com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemTaskManager; import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.ContainerUtilRt; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -100,7 +102,10 @@ public class ExternalSystemExecuteTaskTask extends AbstractExternalSystemTask { RemoteExternalSystemTaskManager taskManager = facade.getTaskManager(); List taskNames = ContainerUtilRt.map2List(myTasksToExecute, MAPPER); - taskManager.executeTasks(getId(), taskNames, getExternalProjectPath(), settings, myVmOptions, myScriptParameters, myDebuggerSetup); + final List vmOptions = parseCmdParameters(myVmOptions); + final List scriptParametersList = parseCmdParameters(myScriptParameters); + + taskManager.executeTasks(getId(), taskNames, getExternalProjectPath(), settings, vmOptions, scriptParametersList, myDebuggerSetup); } @Override @@ -111,4 +116,20 @@ public class ExternalSystemExecuteTaskTask extends AbstractExternalSystemTask { return taskManager.cancelTask(getId()); } + + private static List parseCmdParameters(@Nullable String cmdArgsLine) { + final List scriptParametersList = ContainerUtil.newArrayList(); + if (cmdArgsLine != null) { + // filter nulls and empty strings + scriptParametersList.addAll(ContainerUtil.mapNotNull( + StringUtil.split(cmdArgsLine.trim(), " "), new Function() { + @Override + public String fun(String s) { + return StringUtil.isEmpty(s) ? null : s.trim(); + } + } + )); + } + return scriptParametersList; + } } diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/remote/RemoteExternalSystemTaskManager.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/remote/RemoteExternalSystemTaskManager.java index f801966e9cf0..ab3f6c55a3af 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/remote/RemoteExternalSystemTaskManager.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/remote/RemoteExternalSystemTaskManager.java @@ -45,8 +45,8 @@ public interface RemoteExternalSystemTaskManager taskNames, @NotNull String projectPath, @Nullable ExternalSystemExecutionSettings settings, - @Nullable String vmOptions, - @Nullable String scriptParameters, + @NotNull List vmOptions, + @NotNull List scriptParameters, @Nullable String debuggerSetup) throws RemoteException, ExternalSystemException { } @@ -81,8 +81,8 @@ public interface RemoteExternalSystemTaskManager taskNames, @NotNull String projectPath, @Nullable S settings, - @Nullable String vmOptions, - @Nullable String scriptParameters, + @NotNull List vmOptions, + @NotNull List scriptParameters, @Nullable String debuggerSetup) throws RemoteException, ExternalSystemException; boolean cancelTask(@NotNull ExternalSystemTaskId id) throws RemoteException, ExternalSystemException; diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/remote/RemoteExternalSystemTaskManagerImpl.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/remote/RemoteExternalSystemTaskManagerImpl.java index 5ccfc3da52d1..632d1508b0d2 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/remote/RemoteExternalSystemTaskManagerImpl.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/remote/RemoteExternalSystemTaskManagerImpl.java @@ -18,7 +18,9 @@ package com.intellij.openapi.externalSystem.service.remote; import com.intellij.openapi.externalSystem.model.ExternalSystemException; import com.intellij.openapi.externalSystem.model.settings.ExternalSystemExecutionSettings; import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId; +import com.intellij.openapi.externalSystem.task.AbstractExternalSystemTaskManager; import com.intellij.openapi.externalSystem.task.ExternalSystemTaskManager; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.Producer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -45,15 +47,20 @@ public class RemoteExternalSystemTaskManagerImpl taskNames, @NotNull final String projectPath, @Nullable final S settings, - @Nullable final String vmOptions, - @Nullable final String scriptParameters, + @NotNull final List vmOptions, + @NotNull final List scriptParameters, @Nullable final String debuggerSetup) throws RemoteException, ExternalSystemException { execute(id, new Producer() { @Nullable @Override public Object produce() { - myDelegate.executeTasks(id, taskNames, projectPath, settings, vmOptions, scriptParameters, debuggerSetup, getNotificationListener()); + if(myDelegate instanceof AbstractExternalSystemTaskManager) { + ((AbstractExternalSystemTaskManager)myDelegate) + .executeTasks(id, taskNames, projectPath, settings, vmOptions, scriptParameters, debuggerSetup, getNotificationListener()); + } else { + myDelegate.executeTasks(id, taskNames, projectPath, settings, StringUtil.join(vmOptions, " "), debuggerSetup, getNotificationListener()); + } return null; } }); diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/remote/wrapper/ExternalSystemTaskManagerWrapper.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/remote/wrapper/ExternalSystemTaskManagerWrapper.java index ba4d19ff000d..281bc8ea5970 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/remote/wrapper/ExternalSystemTaskManagerWrapper.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/remote/wrapper/ExternalSystemTaskManagerWrapper.java @@ -49,8 +49,8 @@ public class ExternalSystemTaskManagerWrapper taskNames, @NotNull String projectPath, @Nullable S settings, - @Nullable String vmOptions, - @Nullable String scriptParameters, + @NotNull List vmOptions, + @NotNull List scriptParameters, @Nullable String debuggerSetup) throws RemoteException, ExternalSystemException { myProgressManager.onQueued(id); 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 8ea7ec08c07f..d976b47cb3f1 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 @@ -77,29 +77,9 @@ public class GradleExecutionHelper { @NotNull ProjectConnection connection, @Nullable GradleExecutionSettings settings, @NotNull ExternalSystemTaskNotificationListener listener, - @Nullable final String vmOptions) { + @NotNull final List vmOptions) { BuildLauncher result = connection.newBuild(); - List extraJvmArgs = - vmOptions == null ? ContainerUtil.emptyList() : - ContainerUtil.newArrayList(StringUtil.split(vmOptions.trim(), " ")); - prepare(result, id, settings, listener, extraJvmArgs, connection); - return result; - } - - @SuppressWarnings({"MethodMayBeStatic", "UnusedDeclaration"}) - @NotNull - public BuildLauncher getBuildLauncher(@NotNull final ExternalSystemTaskId id, - @NotNull ProjectConnection connection, - @Nullable GradleExecutionSettings settings, - @NotNull ExternalSystemTaskNotificationListener listener, - @Nullable final String vmOptions, - @NotNull final OutputStream standardOutput, - @NotNull final OutputStream standardError) { - BuildLauncher result = connection.newBuild(); - List extraJvmArgs = - vmOptions == null ? ContainerUtil.emptyList() : - ContainerUtil.newArrayList(StringUtil.split(vmOptions.trim(), " ")); - prepare(result, id, settings, listener, extraJvmArgs, connection, standardOutput, standardError); + prepare(result, id, settings, listener, vmOptions, connection); return result; } 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 5ba703597bcd..da9d4a0fce0e 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 @@ -19,6 +19,7 @@ import com.intellij.openapi.externalSystem.model.ExternalSystemException; import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId; import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationEvent; import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener; +import com.intellij.openapi.externalSystem.task.AbstractExternalSystemTaskManager; import com.intellij.openapi.externalSystem.task.ExternalSystemTaskManager; import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; import com.intellij.openapi.util.io.FileUtil; @@ -43,17 +44,32 @@ import java.util.List; * @author Denis Zhdanov * @since 3/14/13 5:09 PM */ -public class GradleTaskManager implements ExternalSystemTaskManager { +public class GradleTaskManager extends AbstractExternalSystemTaskManager + implements ExternalSystemTaskManager { private final GradleExecutionHelper myHelper = new GradleExecutionHelper(); + /** + * TODO: remove the method in 13.1 + */ + @Override + public void executeTasks(@NotNull ExternalSystemTaskId id, + @NotNull List taskNames, + @NotNull String projectPath, + @Nullable GradleExecutionSettings settings, + @Nullable String vmOptions, + @Nullable String debuggerSetup, + @NotNull ExternalSystemTaskNotificationListener listener) throws ExternalSystemException { + throw new UnsupportedOperationException(); + } + @Override public void executeTasks(@NotNull final ExternalSystemTaskId id, @NotNull final List taskNames, @NotNull String projectPath, @Nullable final GradleExecutionSettings settings, - @Nullable final String vmOptions, - @Nullable final String scriptParameters, + @NotNull final List vmOptions, + @NotNull final List scriptParameters, @Nullable final String debuggerSetup, @NotNull final ExternalSystemTaskNotificationListener listener) throws ExternalSystemException { @@ -61,26 +77,13 @@ public class GradleTaskManager implements ExternalSystemTaskManager scriptParametersList; - if (scriptParameters == null) { - scriptParametersList = ContainerUtil.newArrayList(); - } - else { - // filter nulls and empty strings - scriptParametersList = ContainerUtil.mapNotNull( - StringUtil.split(scriptParameters.trim(), " "), new Function() { - @Override - public String fun(String s) { - return StringUtil.isEmpty(s) ? null : s.trim(); - } - } - ); - } - // 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, vmOptions, debuggerSetup, listener)) return; + if (gradleTaskManagerExtension.executeTasks( + id, taskNames, projectPath, settings, vmOptions, scriptParameters, debuggerSetup, listener)) { + return; + } } } @@ -100,16 +103,16 @@ public class GradleTaskManager implements ExternalSystemTaskManager taskNames, @NotNull String projectPath, @Nullable final GradleExecutionSettings settings, - @Nullable final String vmOptions, + @NotNull final List vmOptions, + @NotNull final List scriptParameters, @Nullable final String debuggerSetup, @NotNull final ExternalSystemTaskNotificationListener listener) throws ExternalSystemException;