mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-117792 Gradle Run/Debug Configuration: support adding Gradle specific parameters. Fix after review.
+ fix bug - http://youtrack.jetbrains.com/issue/IDEA-118470
This commit is contained in:
+1
@@ -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;
|
||||
|
||||
+41
@@ -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<S extends ExternalSystemExecutionSettings> implements ExternalSystemTaskManager<S> {
|
||||
|
||||
public abstract void executeTasks(@NotNull ExternalSystemTaskId id,
|
||||
@NotNull List<String> taskNames,
|
||||
@NotNull String projectPath,
|
||||
@Nullable S settings,
|
||||
@NotNull final List<String> vmOptions,
|
||||
@NotNull List<String> scriptParameters,
|
||||
@Nullable String debuggerSetup,
|
||||
@NotNull ExternalSystemTaskNotificationListener listener) throws ExternalSystemException;
|
||||
}
|
||||
+5
-1
@@ -32,12 +32,16 @@ import java.util.List;
|
||||
*/
|
||||
public interface ExternalSystemTaskManager<S extends ExternalSystemExecutionSettings> {
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated will be removed in 13.1
|
||||
*/
|
||||
@Deprecated
|
||||
void executeTasks(@NotNull ExternalSystemTaskId id,
|
||||
@NotNull List<String> taskNames,
|
||||
@NotNull String projectPath,
|
||||
@Nullable S settings,
|
||||
@Nullable String vmOptions,
|
||||
@Nullable String scriptParameters,
|
||||
@Nullable String debuggerSetup,
|
||||
@NotNull ExternalSystemTaskNotificationListener listener)
|
||||
throws ExternalSystemException;
|
||||
|
||||
+22
-1
@@ -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<String> taskNames = ContainerUtilRt.map2List(myTasksToExecute, MAPPER);
|
||||
|
||||
taskManager.executeTasks(getId(), taskNames, getExternalProjectPath(), settings, myVmOptions, myScriptParameters, myDebuggerSetup);
|
||||
final List<String> vmOptions = parseCmdParameters(myVmOptions);
|
||||
final List<String> 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<String> parseCmdParameters(@Nullable String cmdArgsLine) {
|
||||
final List<String> scriptParametersList = ContainerUtil.newArrayList();
|
||||
if (cmdArgsLine != null) {
|
||||
// filter nulls and empty strings
|
||||
scriptParametersList.addAll(ContainerUtil.mapNotNull(
|
||||
StringUtil.split(cmdArgsLine.trim(), " "), new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String s) {
|
||||
return StringUtil.isEmpty(s) ? null : s.trim();
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
return scriptParametersList;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -45,8 +45,8 @@ public interface RemoteExternalSystemTaskManager<S extends ExternalSystemExecuti
|
||||
@NotNull List<String> taskNames,
|
||||
@NotNull String projectPath,
|
||||
@Nullable ExternalSystemExecutionSettings settings,
|
||||
@Nullable String vmOptions,
|
||||
@Nullable String scriptParameters,
|
||||
@NotNull List<String> vmOptions,
|
||||
@NotNull List<String> scriptParameters,
|
||||
@Nullable String debuggerSetup) throws RemoteException, ExternalSystemException
|
||||
{
|
||||
}
|
||||
@@ -81,8 +81,8 @@ public interface RemoteExternalSystemTaskManager<S extends ExternalSystemExecuti
|
||||
@NotNull List<String> taskNames,
|
||||
@NotNull String projectPath,
|
||||
@Nullable S settings,
|
||||
@Nullable String vmOptions,
|
||||
@Nullable String scriptParameters,
|
||||
@NotNull List<String> vmOptions,
|
||||
@NotNull List<String> scriptParameters,
|
||||
@Nullable String debuggerSetup) throws RemoteException, ExternalSystemException;
|
||||
|
||||
boolean cancelTask(@NotNull ExternalSystemTaskId id) throws RemoteException, ExternalSystemException;
|
||||
|
||||
+10
-3
@@ -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<S extends ExternalSystemExecuti
|
||||
@NotNull final List<String> taskNames,
|
||||
@NotNull final String projectPath,
|
||||
@Nullable final S settings,
|
||||
@Nullable final String vmOptions,
|
||||
@Nullable final String scriptParameters,
|
||||
@NotNull final List<String> vmOptions,
|
||||
@NotNull final List<String> scriptParameters,
|
||||
@Nullable final String debuggerSetup) throws RemoteException, ExternalSystemException
|
||||
{
|
||||
execute(id, new Producer<Object>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Object produce() {
|
||||
myDelegate.executeTasks(id, taskNames, projectPath, settings, vmOptions, scriptParameters, debuggerSetup, getNotificationListener());
|
||||
if(myDelegate instanceof AbstractExternalSystemTaskManager) {
|
||||
((AbstractExternalSystemTaskManager<S>)myDelegate)
|
||||
.executeTasks(id, taskNames, projectPath, settings, vmOptions, scriptParameters, debuggerSetup, getNotificationListener());
|
||||
} else {
|
||||
myDelegate.executeTasks(id, taskNames, projectPath, settings, StringUtil.join(vmOptions, " "), debuggerSetup, getNotificationListener());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
+2
-2
@@ -49,8 +49,8 @@ public class ExternalSystemTaskManagerWrapper<S extends ExternalSystemExecutionS
|
||||
@NotNull List<String> taskNames,
|
||||
@NotNull String projectPath,
|
||||
@Nullable S settings,
|
||||
@Nullable String vmOptions,
|
||||
@Nullable String scriptParameters,
|
||||
@NotNull List<String> vmOptions,
|
||||
@NotNull List<String> scriptParameters,
|
||||
@Nullable String debuggerSetup) throws RemoteException, ExternalSystemException
|
||||
{
|
||||
myProgressManager.onQueued(id);
|
||||
|
||||
+2
-22
@@ -77,29 +77,9 @@ public class GradleExecutionHelper {
|
||||
@NotNull ProjectConnection connection,
|
||||
@Nullable GradleExecutionSettings settings,
|
||||
@NotNull ExternalSystemTaskNotificationListener listener,
|
||||
@Nullable final String vmOptions) {
|
||||
@NotNull final List<String> vmOptions) {
|
||||
BuildLauncher result = connection.newBuild();
|
||||
List<String> extraJvmArgs =
|
||||
vmOptions == null ? ContainerUtil.<String>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<String> extraJvmArgs =
|
||||
vmOptions == null ? ContainerUtil.<String>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;
|
||||
}
|
||||
|
||||
|
||||
+27
-24
@@ -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<GradleExecutionSettings> {
|
||||
public class GradleTaskManager extends AbstractExternalSystemTaskManager<GradleExecutionSettings>
|
||||
implements ExternalSystemTaskManager<GradleExecutionSettings> {
|
||||
|
||||
private final GradleExecutionHelper myHelper = new GradleExecutionHelper();
|
||||
|
||||
/**
|
||||
* TODO: remove the method in 13.1
|
||||
*/
|
||||
@Override
|
||||
public void executeTasks(@NotNull ExternalSystemTaskId id,
|
||||
@NotNull List<String> 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<String> taskNames,
|
||||
@NotNull String projectPath,
|
||||
@Nullable final GradleExecutionSettings settings,
|
||||
@Nullable final String vmOptions,
|
||||
@Nullable final String scriptParameters,
|
||||
@NotNull final List<String> vmOptions,
|
||||
@NotNull final List<String> scriptParameters,
|
||||
@Nullable final String debuggerSetup,
|
||||
@NotNull final ExternalSystemTaskNotificationListener listener) throws ExternalSystemException {
|
||||
|
||||
@@ -61,26 +77,13 @@ public class GradleTaskManager implements ExternalSystemTaskManager<GradleExecut
|
||||
myHelper.ensureInstalledWrapper(id, projectPath, settings, listener);
|
||||
}
|
||||
|
||||
final List<String> scriptParametersList;
|
||||
if (scriptParameters == null) {
|
||||
scriptParametersList = ContainerUtil.newArrayList();
|
||||
}
|
||||
else {
|
||||
// filter nulls and empty strings
|
||||
scriptParametersList = ContainerUtil.mapNotNull(
|
||||
StringUtil.split(scriptParameters.trim(), " "), new Function<String, String>() {
|
||||
@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<GradleExecut
|
||||
};
|
||||
FileUtil.writeToFile(tempFile, StringUtil.join(lines, SystemProperties.getLineSeparator()));
|
||||
|
||||
scriptParametersList.add("--init-script");
|
||||
scriptParametersList.add(tempFile.getAbsolutePath());
|
||||
scriptParameters.add("--init-script");
|
||||
scriptParameters.add(tempFile.getAbsolutePath());
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new ExternalSystemException(e);
|
||||
}
|
||||
}
|
||||
|
||||
if(!scriptParametersList.isEmpty()) {
|
||||
launcher.withArguments(ArrayUtil.toStringArray(scriptParametersList));
|
||||
if (!scriptParameters.isEmpty()) {
|
||||
launcher.withArguments(ArrayUtil.toStringArray(scriptParameters));
|
||||
}
|
||||
launcher.forTasks(ArrayUtil.toStringArray(taskNames));
|
||||
launcher.run();
|
||||
|
||||
+2
-1
@@ -37,7 +37,8 @@ public interface GradleTaskManagerExtension {
|
||||
@NotNull final List<String> taskNames,
|
||||
@NotNull String projectPath,
|
||||
@Nullable final GradleExecutionSettings settings,
|
||||
@Nullable final String vmOptions,
|
||||
@NotNull final List<String> vmOptions,
|
||||
@NotNull final List<String> scriptParameters,
|
||||
@Nullable final String debuggerSetup,
|
||||
@NotNull final ExternalSystemTaskNotificationListener listener) throws ExternalSystemException;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user