From 3f06dc343b2792736fc12741174c75f4d70f2c1d Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Fri, 23 Oct 2015 21:10:48 +0300 Subject: [PATCH] [grails] pass VM options from Run Mvc Target dialog (IDEA-145433) There was a choice: - change MvcCommandExecutor to accept vmOptions parameter. - change MvcCommand and make vmOptions as a field of MvcCommand. The second approach was chosen because the first makes code less readable and GrailsCommandExecutor still needs `jvmArgs` parameter too. So this parameter was made a field of MvcCommand and it was removed from MvcFramework (and its inheritors) and GrailsCommandExecutor (and its inheritors). Setters for MvcCommand fields were removed to avoid changing outside of MvcCommand.parse() method, so `vmOptions` parameters was added to it. --- .../groovy/griffon/GriffonFramework.java | 7 ++-- .../groovy/mvc/MvcCliCommandExecutor.java | 4 +-- .../plugins/groovy/mvc/MvcCommand.java | 34 +++++++++++++------ .../plugins/groovy/mvc/MvcFramework.java | 17 +++------- .../groovy/mvc/MvcRunConfiguration.java | 4 +-- .../plugins/groovy/mvc/MvcRunTarget.java | 4 +-- .../groovy/mvc/MvcRunTargetDialog.java | 15 +++++--- 7 files changed, 47 insertions(+), 38 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonFramework.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonFramework.java index e4479a1dae6a..47bcf7751abc 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonFramework.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonFramework.java @@ -103,7 +103,7 @@ public class GriffonFramework extends MvcFramework { return null; } - return createCommandAndShowErrors(null, module, true, dialog.getCommand()); + return createCommandAndShowErrors(module, true, dialog.getCommand()); } @Override @@ -233,7 +233,6 @@ public class GriffonFramework extends MvcFramework { @Override public JavaParameters createJavaParameters(@NotNull Module module, boolean forCreation, boolean forTests, boolean classpathFromDependencies, - @Nullable String jvmParams, @NotNull MvcCommand command) throws ExecutionException { JavaParameters params = new JavaParameters(); @@ -294,9 +293,7 @@ public class GriffonFramework extends MvcFramework { String workDir = VfsUtilCore.virtualToIoFile(rootFile).getAbsolutePath(); - if (jvmParams != null) { - params.getVMParametersList().addParametersString(jvmParams); - } + params.getVMParametersList().addParametersString(command.getVmOptions()); if (!params.getVMParametersList().getParametersString().contains(XMX_JVM_PARAMETER)) { params.getVMParametersList().add("-Xmx256M"); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcCliCommandExecutor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcCliCommandExecutor.java index 120c5abf189b..bf6aaa69361a 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcCliCommandExecutor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcCliCommandExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -39,7 +39,7 @@ public class MvcCliCommandExecutor extends MvcCommandExecutor { boolean showConsole, boolean closeOnDone, String... input) { - final GeneralCommandLine commandLine = framework.createCommandAndShowErrors(null, module, mvcCommand); + final GeneralCommandLine commandLine = framework.createCommandAndShowErrors(module, mvcCommand); if (commandLine == null) return null; return MvcConsole.executeProcess(module, commandLine, onDone, closeOnDone, input); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcCommand.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcCommand.java index 5ddb553ab38b..3ac4f9f7e104 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcCommand.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcCommand.java @@ -1,3 +1,18 @@ +/* + * 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.groovy.mvc; import com.intellij.execution.configurations.ParametersList; @@ -13,8 +28,9 @@ public class MvcCommand { public static final Collection ourEnvironments = Arrays.asList("prod", "test", "dev"); - private String myEnv; - private String myCommand; + private @Nullable String myEnv; + private @Nullable String myCommand; + private @Nullable String myVmOptions; private final ArrayList myArgs = new ArrayList(); private final ArrayList myProperties = new ArrayList(); @@ -22,7 +38,7 @@ public class MvcCommand { public MvcCommand() { } - public MvcCommand(String command, String ... args) { + public MvcCommand(@Nullable String command, String... args) { myCommand = command; Collections.addAll(myArgs, args); } @@ -32,17 +48,14 @@ public class MvcCommand { return myEnv; } - public void setEnv(@Nullable String env) { - myEnv = env; - } - @Nullable public String getCommand() { return myCommand; } - public void setCommand(@Nullable String command) { - myCommand = command; + @Nullable + public String getVmOptions() { + return myVmOptions; } /** @@ -88,7 +101,7 @@ public class MvcCommand { } @NotNull - public static MvcCommand parse(@NotNull String cmd) { + public static MvcCommand parse(@NotNull String cmd, @Nullable String vmOptions) { String[] args = ParametersList.parse(cmd); MvcCommand res = new MvcCommand(); @@ -112,6 +125,7 @@ public class MvcCommand { } res.myArgs.addAll(Arrays.asList(args).subList(i, args.length)); + res.myVmOptions = vmOptions; return res; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcFramework.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcFramework.java index 56c3596ec918..dc3bc8d2c7ca 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcFramework.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcFramework.java @@ -337,7 +337,6 @@ public abstract class MvcFramework { boolean forCreation, boolean forTests, boolean classpathFromDependencies, - @Nullable String jvmParams, @NotNull MvcCommand command) throws ExecutionException; protected static void ensureRunConfigurationExists(Module module, ConfigurationType configurationType, String name) { @@ -375,23 +374,18 @@ public abstract class MvcFramework { @Nullable public GeneralCommandLine createCommandAndShowErrors(@NotNull Module module, @NotNull String command, String... args) { - return createCommandAndShowErrors(null, module, new MvcCommand(command, args)); + return createCommandAndShowErrors(module, new MvcCommand(command, args)); } @Nullable public GeneralCommandLine createCommandAndShowErrors(@NotNull Module module, @NotNull MvcCommand command) { - return createCommandAndShowErrors(null, module, command); + return createCommandAndShowErrors(module, false, command); } @Nullable - public GeneralCommandLine createCommandAndShowErrors(@Nullable String vmOptions, @NotNull Module module, @NotNull MvcCommand command) { - return createCommandAndShowErrors(vmOptions, module, false, command); - } - - @Nullable - public GeneralCommandLine createCommandAndShowErrors(@Nullable String vmOptions, @NotNull Module module, final boolean forCreation, @NotNull MvcCommand command) { + public GeneralCommandLine createCommandAndShowErrors(@NotNull Module module, final boolean forCreation, @NotNull MvcCommand command) { try { - return createCommand(module, vmOptions, forCreation, command); + return createCommand(module, forCreation, command); } catch (ExecutionException e) { Messages.showErrorDialog(e.getMessage(), "Failed to run grails command: " + command); @@ -401,10 +395,9 @@ public abstract class MvcFramework { @NotNull public GeneralCommandLine createCommand(@NotNull Module module, - @Nullable String jvmParams, boolean forCreation, @NotNull MvcCommand command) throws ExecutionException { - final JavaParameters params = createJavaParameters(module, forCreation, false, true, jvmParams, command); + final JavaParameters params = createJavaParameters(module, forCreation, false, true, command); addJavaHome(params, module); final GeneralCommandLine commandLine = createCommandLine(params); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunConfiguration.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunConfiguration.java index 8d3dd993d9ff..e33f035c1f73 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunConfiguration.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunConfiguration.java @@ -304,9 +304,9 @@ public abstract class MvcRunConfiguration extends ModuleBasedConfiguration