[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.
This commit is contained in:
Daniil Ovchinnikov
2015-10-23 21:16:27 +03:00
parent ae06ff5880
commit 3f06dc343b
7 changed files with 47 additions and 38 deletions
@@ -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");
@@ -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);
}
@@ -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<String> 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<String> myArgs = new ArrayList<String>();
private final ArrayList<String> myProperties = new ArrayList<String>();
@@ -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;
}
@@ -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);
@@ -304,9 +304,9 @@ public abstract class MvcRunConfiguration extends ModuleBasedConfiguration<RunCo
}
protected JavaParameters createJavaParametersMVC() throws ExecutionException {
MvcCommand cmd = MvcCommand.parse(myCmdLine);
MvcCommand cmd = MvcCommand.parse(myCmdLine, vmParams);
final JavaParameters params = myFramework.createJavaParameters(myModule, false, myForTests, depsClasspath, vmParams, cmd);
final JavaParameters params = myFramework.createJavaParameters(myModule, false, myForTests, depsClasspath, cmd);
addEnvVars(params);
@@ -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.
@@ -32,7 +32,7 @@ public class MvcRunTarget extends MvcActionBase {
}
Module selectedModule = dialog.getSelectedModule();
MvcCommand cmd = MvcCommand.parse(dialog.getTargetArguments());
MvcCommand cmd = dialog.createCommand();
MvcCommandExecutor.run(selectedModule, framework, cmd, null, false);
}
@@ -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.
@@ -15,6 +15,7 @@
*/
package org.jetbrains.plugins.groovy.mvc;
import com.intellij.application.options.ModulesComboBox;
import com.intellij.codeInsight.completion.CompletionResultSet;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.openapi.editor.event.DocumentAdapter;
@@ -22,7 +23,6 @@ import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.fileTypes.PlainTextFileType;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.application.options.ModulesComboBox;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.text.StringUtil;
@@ -135,22 +135,27 @@ public class MvcRunTargetDialog extends DialogWrapper {
return myModule;
}
@NotNull
public MvcCommand createCommand() {
return MvcCommand.parse(getTargetArguments(), getVmOptions());
}
@Override
protected void doOKAction() {
super.doOKAction();
MvcRunTargetHistoryService.getInstance().addCommand(getSelectedText(), getVmOptions());
}
public String getVmOptions() {
private String getVmOptions() {
return myVmOptionsField.getText();
}
public String getSelectedText() {
private String getSelectedText() {
return (String)myTargetField.getEditor().getItem();
}
@NotNull
public String getTargetArguments() {
private String getTargetArguments() {
String text = getSelectedText();
text = text.trim();