diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/console/DefaultGroovyShellRunner.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/DefaultGroovyShellRunner.java index db046d1423c8..26e5cadd890c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/console/DefaultGroovyShellRunner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/DefaultGroovyShellRunner.java @@ -19,7 +19,6 @@ import com.intellij.execution.ExecutionException; import com.intellij.execution.configurations.JavaParameters; import com.intellij.openapi.module.Module; import com.intellij.openapi.roots.ModuleRootManager; -import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.search.GlobalSearchScope; @@ -28,12 +27,8 @@ import org.jetbrains.plugins.groovy.config.AbstractConfigUtils; import org.jetbrains.plugins.groovy.config.GroovyConfigUtils; import org.jetbrains.plugins.groovy.runner.DefaultGroovyScriptRunner; import org.jetbrains.plugins.groovy.runner.GroovyScriptRunConfiguration; -import org.jetbrains.plugins.groovy.runner.GroovyScriptRunner; -import org.jetbrains.plugins.groovy.util.GroovyUtils; import org.jetbrains.plugins.groovy.util.LibrariesUtil; -import java.io.File; - /** * @author Sergey Evdokimov */ @@ -49,58 +44,32 @@ public class DefaultGroovyShellRunner extends GroovyShellRunner { @Override public JavaParameters createJavaParameters(@NotNull Module module) throws ExecutionException { JavaParameters res = GroovyScriptRunConfiguration.createJavaParametersWithSdk(module); - boolean useBundled = !hasGroovyWithNeededJars(module); DefaultGroovyScriptRunner.configureGenericGroovyRunner(res, module, "org.codehaus.groovy.tools.shell.Main", false, true); - if (useBundled) { - String libRoot = GroovyUtils.getBundledGroovyJar().getParent(); - File libDir = new File(libRoot + "/groovy/lib"); - assert libDir.isDirectory(); - for (File file : libDir.listFiles()) { - res.getClassPath().add(file); - } - - GroovyScriptRunner.setGroovyHome(res, FileUtil.toCanonicalPath(libRoot + "/groovy")); - } res.setWorkingDirectory(getWorkingDirectory(module)); - return res; } @Override public boolean canRun(@NotNull Module module) { VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots(); - return contentRoots.length > 0; + return contentRoots.length > 0 && hasGroovyWithNeededJars(module); } @NotNull @Override public String getTitle(@NotNull Module module) { String homePath = LibrariesUtil.getGroovyHomePath(module); - boolean bundled = !hasGroovyWithNeededJars(module); - if (bundled) { - homePath = GroovyUtils.getBundledGroovyJar().getParentFile().getParent(); - } - else { - assert homePath != null; - } + assert homePath != null; String version = GroovyConfigUtils.getInstance().getSDKVersion(homePath); - return version == AbstractConfigUtils.UNDEFINED_VERSION ? "" : " (" + (bundled ? "Bundled " : "") + "Groovy " + version + ")"; + return version == AbstractConfigUtils.UNDEFINED_VERSION ? "" : " (Groovy " + version + ")"; } - private static boolean hasGroovyWithNeededJars(Module module) { + static boolean hasGroovyWithNeededJars(Module module) { GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module); JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject()); - return (facade.findClass("org.apache.commons.cli.CommandLineParser", scope) != null || - facade.findClass("groovyjarjarcommonscli.CommandLineParser", scope) != null) && + return (facade.findClass("org.apache.commons.cli.CommandLineParser", scope) != null || facade.findClass("groovyjarjarcommonscli.CommandLineParser", scope) != null) && facade.findClass("groovy.ui.GroovyMain", scope) != null && facade.findClass("org.fusesource.jansi.AnsiConsole", scope) != null; } - - @NotNull - @Override - public String transformUserInput(@NotNull String userInput) { - //return StringUtil.replace(userInput, "\n", "###\\n"); - return userInput; - } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsoleRunner.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsoleRunner.java index bf46a21b87e4..1932da4e2e10 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsoleRunner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsoleRunner.java @@ -69,13 +69,11 @@ public class GroovyConsoleRunner extends GroovyShellRunner { @NotNull @Override public String getTitle(@NotNull Module module) { - String homePath = LibrariesUtil.getGroovyHomePath(module); - boolean bundled = false; - if (homePath == null || !hasGroovyAll(module)) { - homePath = GroovyUtils.getBundledGroovyJar().getParentFile().getParent(); - bundled = true; - } - String version = GroovyConfigUtils.getInstance().getSDKVersion(homePath); + String moduleGroovyHomePath = LibrariesUtil.getGroovyHomePath(module); + boolean bundled = moduleGroovyHomePath == null || !hasGroovyAll(module); + String homePathToUse = bundled ? GroovyUtils.getBundledGroovyJar().getParentFile().getParent() : moduleGroovyHomePath; + + String version = GroovyConfigUtils.getInstance().getSDKVersion(homePathToUse); return version == AbstractConfigUtils.UNDEFINED_VERSION ? "" : " (" + (bundled ? "Bundled " : "") + "Groovy " + version + ")"; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyShellAction.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyShellAction.java index 835687a07aad..085cce5a6fdf 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyShellAction.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyShellAction.java @@ -22,6 +22,11 @@ import com.intellij.openapi.project.Project; * @author peter */ public class GroovyShellAction extends GroovyShellActionBase { + @Override + protected boolean isSuitableModule(Module module) { + return super.isSuitableModule(module) && DefaultGroovyShellRunner.hasGroovyWithNeededJars(module); + } + protected GroovyShellRunner getRunner(Module module) { return new DefaultGroovyShellRunner(); } @@ -33,31 +38,6 @@ public class GroovyShellAction extends GroovyShellActionBase { @Override protected GroovyShellConsoleImpl createConsole(Project project, String title) { - final GroovyShellConsoleImpl console = new GroovyShellConsoleImpl(project, title); - - /*UiNotifyConnector.doWhenFirstShown(console.getComponent(), new Runnable() { - @Override - public void run() { - final String key = "groovy.shell.is.really.groovy.shell"; - if (!PropertiesComponent.getInstance().isTrueValue(key)) { - final Alarm alarm = new Alarm(); - alarm.addRequest(new Runnable() { - @Override - public void run() { - GotItMessage.createMessage("Groovy Shell & Groovy Console", "