IDEA-100270 Unable to start Grails

This commit is contained in:
Sergey Evdokimov
2013-02-03 15:32:22 +04:00
parent 1078d1220f
commit 369a4a5da1
8 changed files with 173 additions and 73 deletions
@@ -15,13 +15,12 @@
*/
package org.jetbrains.plugins.groovy.griffon;
import com.intellij.execution.configurations.ParametersList;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.mvc.MvcCommand;
import javax.swing.*;
@@ -50,20 +49,29 @@ public class GriffonCreateProjectDialog extends DialogWrapper {
return myComponent;
}
String getCommand() {
if (myCreateAddon.isSelected()) return "create-addon";
if (myCreateApp.isSelected()) return "create-app";
if (myCreateArchetype.isSelected()) return "create-archetype";
if (myCreatePlugin.isSelected()) return "create-plugin";
throw new AssertionError("No selection");
}
MvcCommand getCommand() {
String cmd;
String[] getArguments() {
String text = myOptionField.getText();
if (StringUtil.isEmptyOrSpaces(text)) {
return ArrayUtil.EMPTY_STRING_ARRAY;
if (myCreateAddon.isSelected()) {
cmd = "create-addon";
}
return text.split(" ");
else if (myCreateApp.isSelected()) {
cmd = "create-app";
}
else if (myCreateArchetype.isSelected()) {
cmd = "create-archetype";
}
else if (myCreatePlugin.isSelected()) {
cmd = "create-plugin";
}
else {
throw new AssertionError("No selection");
}
String text = myOptionField.getText();
if (text == null) text = "";
return new MvcCommand(cmd, ParametersList.parse(text));
}
}
@@ -19,6 +19,7 @@ package org.jetbrains.plugins.groovy.griffon;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.configurations.JavaParameters;
import com.intellij.execution.configurations.ParametersList;
import com.intellij.lang.properties.IProperty;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.application.AccessToken;
@@ -41,17 +42,13 @@ import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.util.ArrayUtil;
import gnu.trove.TIntArrayList;
import icons.JetgroovyIcons;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.GroovyFileType;
import org.jetbrains.plugins.groovy.mvc.MvcFramework;
import org.jetbrains.plugins.groovy.mvc.MvcModuleStructureUtil;
import org.jetbrains.plugins.groovy.mvc.MvcPathMacros;
import org.jetbrains.plugins.groovy.mvc.MvcProjectStructure;
import org.jetbrains.plugins.groovy.mvc.*;
import javax.swing.*;
import java.io.File;
@@ -105,7 +102,7 @@ public class GriffonFramework extends MvcFramework {
return null;
}
return createCommandAndShowErrors(null, module, true, dialog.getCommand(), dialog.getArguments());
return createCommandAndShowErrors(null, module, true, dialog.getCommand());
}
@Override
@@ -231,8 +228,7 @@ public class GriffonFramework extends MvcFramework {
public JavaParameters createJavaParameters(@NotNull Module module, boolean forCreation, boolean forTests,
boolean classpathFromDependencies,
@Nullable String jvmParams,
@NotNull String command,
@NotNull String... args) throws ExecutionException {
@NotNull MvcCommand command) throws ExecutionException {
JavaParameters params = new JavaParameters();
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
@@ -284,7 +280,8 @@ public class GriffonFramework extends MvcFramework {
throw new ExecutionException("Failed to initialize griffon module: module " + module.getName() + " contains more than one root");
}
args = ArrayUtil.mergeArrays(new String[]{roots[0].getName()}, args);
command.getArgs().add(0, roots[0].getName());
rootFile = roots[0].getParent();
}
else {
@@ -331,8 +328,9 @@ public class GriffonFramework extends MvcFramework {
params.setWorkingDirectory(workDir);
String argsString = args.length == 0 ? command : command + ' ' + StringUtil.join(args, " ");
params.getProgramParametersList().add(argsString);
ParametersList paramList = new ParametersList();
command.addToParametersList(paramList);
params.getProgramParametersList().add(paramList.getParametersString());
params.setDefaultCharset(module.getProject());
@@ -0,0 +1,118 @@
package org.jetbrains.plugins.groovy.mvc;
import com.intellij.execution.configurations.ParametersList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
/**
* @author Sergey Evdokimov
*/
public class MvcCommand {
public static final Collection<String> ourEnvironments = Arrays.asList("prod", "test", "dev");
private String myEnv;
private String myCommand;
private final ArrayList<String> myArgs = new ArrayList<String>();
private final ArrayList<String> myProperties = new ArrayList<String>();
public MvcCommand() {
}
public MvcCommand(String command, String ... args) {
myCommand = command;
Collections.addAll(myArgs, args);
}
@Nullable
public String getEnv() {
return myEnv;
}
public void setEnv(@Nullable String env) {
myEnv = env;
}
@Nullable
public String getCommand() {
return myCommand;
}
public void setCommand(@Nullable String command) {
myCommand = command;
}
/**
* Returns MODIFIABLE list of arguments
*/
public ArrayList<String> getArgs() {
return myArgs;
}
public void setArgs(List<String> args) {
if (args == myArgs) return;
myArgs.clear();
myArgs.addAll(args);
}
/**
* Returns MODIFIABLE list of system properties definition written before command (e.g. -Dgrails.port=9090 run-app)
*/
public ArrayList<String> getProperties() {
return myProperties;
}
public void setProperties(List<String> properties) {
if (myProperties == properties) return;
myProperties.clear();
myProperties.addAll(properties);
}
public void addToParametersList(@NotNull ParametersList list) {
if (myEnv != null) {
list.add(myEnv);
}
list.addAll(myProperties);
if (myCommand != null) {
list.add(myCommand);
}
list.addAll(myArgs);
}
@NotNull
public static MvcCommand parse(@NotNull String cmd) {
String[] args = ParametersList.parse(cmd);
MvcCommand res = new MvcCommand();
int i = 0;
while (res.myCommand == null && i < args.length) {
String s = args[i];
if (s.startsWith("-D")) {
res.myProperties.add(s);
}
else if (res.myEnv == null && ourEnvironments.contains(s)) {
res.myEnv = s;
}
else {
res.myCommand = s;
}
i++;
}
res.myArgs.addAll(Arrays.asList(args).subList(i, args.length));
return res;
}
}
@@ -166,7 +166,7 @@ public abstract class MvcFramework {
return null;
}
return createCommandAndShowErrors(null, module, true, result == 0 ? "create-app" : "create-plugin");
return createCommandAndShowErrors(null, module, true, new MvcCommand(result == 0 ? "create-app" : "create-plugin"));
}
public abstract void updateProjectStructure(@NotNull final Module module);
@@ -316,32 +316,12 @@ public abstract class MvcFramework {
from.remove(extension.getCompilerOutputPathForTests());
}
public static Pair<String, String[]> parsedCmd(String cmdLine) {
return parsedCmd(ParametersList.parse(cmdLine));
}
public static Pair<String, String[]> parsedCmd(String[] args) {
if (args.length == 0) {
return new Pair<String, String[]>("", ArrayUtil.EMPTY_STRING_ARRAY);
}
if (args.length == 1) {
return new Pair<String, String[]>(args[0], ArrayUtil.EMPTY_STRING_ARRAY);
}
String[] array = new String[args.length - 1];
System.arraycopy(args, 1, array, 0, array.length);
return new Pair<String, String[]>(args[0], array);
}
public abstract JavaParameters createJavaParameters(@NotNull Module module,
boolean forCreation,
boolean forTests,
boolean classpathFromDependencies,
@Nullable String jvmParams,
@NotNull String command,
@NotNull String... args) throws ExecutionException;
@NotNull MvcCommand command) throws ExecutionException;
protected static void ensureRunConfigurationExists(Module module, ConfigurationType configurationType, String name) {
final RunManagerEx runManager = RunManagerEx.getInstanceEx(module.getProject());
@@ -373,19 +353,24 @@ public abstract class MvcFramework {
public abstract String getSdkHomePropertyName();
@Nullable
public GeneralCommandLine createCommandAndShowErrors(@NotNull Module module, @NotNull String command, @NotNull String... args) {
return createCommandAndShowErrors(null, module, command, args);
public GeneralCommandLine createCommandAndShowErrors(@NotNull Module module, @NotNull String command, String... args) {
return createCommandAndShowErrors(null, module, new MvcCommand(command, args));
}
@Nullable
public GeneralCommandLine createCommandAndShowErrors(@Nullable String vmOptions, @NotNull Module module, @NotNull String command, @NotNull String... args) {
return createCommandAndShowErrors(vmOptions, module, false, command, args);
public GeneralCommandLine createCommandAndShowErrors(@NotNull Module module, @NotNull MvcCommand command) {
return createCommandAndShowErrors(null, module, command);
}
@Nullable
public GeneralCommandLine createCommandAndShowErrors(@Nullable String vmOptions, @NotNull Module module, final boolean forCreation, @NotNull String command, @NotNull String... args) {
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) {
try {
return createCommand(module, vmOptions, forCreation, command, args);
return createCommand(module, vmOptions, forCreation, command);
}
catch (ExecutionException e) {
Messages.showErrorDialog(e.getMessage(), "Failed to run grails command: " + command);
@@ -397,9 +382,8 @@ public abstract class MvcFramework {
public GeneralCommandLine createCommand(@NotNull Module module,
@Nullable String jvmParams,
final boolean forCreation,
@NotNull String command,
@NotNull String... args) throws ExecutionException {
final JavaParameters params = createJavaParameters(module, forCreation, false, true, jvmParams, command, args);
@NotNull MvcCommand command) throws ExecutionException {
final JavaParameters params = createJavaParameters(module, forCreation, false, true, jvmParams, command);
addJavaHome(params, module);
final GeneralCommandLine commandLine = createCommandLine(params);
@@ -288,10 +288,9 @@ public abstract class MvcRunConfiguration extends ModuleBasedConfiguration<RunCo
}
protected JavaParameters createJavaParametersMVC() throws ExecutionException {
Pair<String, String[]> parsedCmd = MvcFramework.parsedCmd(myCmdLine);
MvcCommand cmd = MvcCommand.parse(myCmdLine);
final JavaParameters params = myFramework.createJavaParameters(myModule, false, myForTests, depsClasspath, vmParams, parsedCmd.first,
parsedCmd.second);
final JavaParameters params = myFramework.createJavaParameters(myModule, false, myForTests, depsClasspath, vmParams, cmd);
addEnvVars(params);
@@ -18,7 +18,6 @@ package org.jetbrains.plugins.groovy.mvc;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull;
/**
@@ -36,11 +35,9 @@ public class MvcRunTarget extends MvcActionBase {
Module selectedModule = dialog.getSelectedModule();
String[] targetArgs = dialog.getTargetArguments();
MvcCommand cmd = MvcCommand.parse(dialog.getTargetArguments());
Pair<String, String[]> parsedCmd = MvcFramework.parsedCmd(targetArgs);
final GeneralCommandLine commandLine = framework.createCommandAndShowErrors(dialog.getVmOptions(), selectedModule, parsedCmd.first, parsedCmd.second);
final GeneralCommandLine commandLine = framework.createCommandAndShowErrors(dialog.getVmOptions(), selectedModule, cmd);
if (commandLine == null) return;
MvcConsole.executeProcess(selectedModule, commandLine, null, false);
@@ -147,7 +147,8 @@ public class MvcRunTargetDialog extends DialogWrapper {
return (String)myTargetField.getEditor().getItem();
}
public String[] getTargetArguments() {
@NotNull
public String getTargetArguments() {
String text = getSelectedText();
text = text.trim();
@@ -155,12 +156,7 @@ public class MvcRunTargetDialog extends DialogWrapper {
text = text.substring(GRAILS_PREFIX.length());
}
Iterable<String> iterable = StringUtil.tokenize(text, " ");
ArrayList<String> args = new ArrayList<String>();
for (String s : iterable) {
args.add(s);
}
return ArrayUtil.toStringArray(args);
return text;
}
protected JComponent createCenterPanel() {
@@ -77,7 +77,7 @@ public class MvcTargetDialogCompletionUtils {
List<LookupElement> res = new ArrayList<LookupElement>();
if (text.substring(0, offset).matches("\\s*(grails\\s*)?(?:(:?-\\S+|dev|prod|test)\\s+)*\\S*")) {
if (text.substring(0, offset).matches("\\s*(grails\\s*)?(?:(:?-D\\S+|dev|prod|test)\\s+)*\\S*")) {
// Complete command name because command name is not typed.
for (String completionVariant : getAllTargetNames(module)) {
res.add(TailTypeDecorator.withTail(LookupElementBuilder.create(completionVariant), TailType.SPACE));