diff --git a/readme.dev b/readme.dev new file mode 100644 index 00000000..b2749a86 --- /dev/null +++ b/readme.dev @@ -0,0 +1,32 @@ +====================================================================== +DEBUGGING VIA ECLIPSE +====================================================================== + +Most of the time we just use the spring-shell line tool directly +from the command line. This we have found is the fastest approach and +also lets us see exactly what a user would see, including the TAB +completion features. Still, sometimes you have a tricky issue you'd +prefer to work through via the STS/Eclipse debugger. When you do this +you need to be aware that you lose the full capabilities of the shell, +as the JLine library (used for command line parsing) is unable to +fully hook into your operating system's keyboard and ANSI services. +Anyhow, for some issues a debugger is worth the minor price of losing +your full keyboard and colour services! :-) + +To setup debugging, open org.springframework.shell.Bootstrap. +Note it has a Java "main" method. Execute the class using Run As > +Java Application. Note the "Console" tab in Eclipse/STS will open. +Type "quit" then hit enter. Now select Run > Debug Configurations. +Select the Java Application > Bootstrap entry. Click on Arguments +and then add the following VM Arguments: + +*nix machines: + -Djline.terminal=org.springframework.shell.IdeTerminal + +Windows machines: + -Djline.WindowsTerminal.directConsole=false + -Djline.terminal=jline.UnsupportedTerminal + +Finally, set the working directory to "Other" and a location on your +disk where you'd like the spring-shell to be loaded. This is usually a +project you're intending to test with. \ No newline at end of file diff --git a/src/main/java/org/springframework/shell/Bootstrap.java b/src/main/java/org/springframework/shell/Bootstrap.java index b9699352..a973bd27 100644 --- a/src/main/java/org/springframework/shell/Bootstrap.java +++ b/src/main/java/org/springframework/shell/Bootstrap.java @@ -16,22 +16,18 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.roo.shell.CommandMarker; import org.springframework.roo.shell.Converter; import org.springframework.roo.shell.ExitShellRequest; -import org.springframework.roo.shell.event.ShellStatus; import org.springframework.roo.support.logging.HandlerUtils; import org.springframework.util.StopWatch; - - /** - * Main class, needs some cleanup + * Loads a {@link Shell} using Spring IoC container. * - * @author vnagaraja - * @author Jarred Li + * @author Ben Alex + * @since 1.0 + * */ public class Bootstrap { - private static final Logger logger = HandlerUtils.getLogger(Bootstrap.class); - private static Bootstrap bootstrap; private JLineShellComponent shell; private ConfigurableApplicationContext ctx; @@ -59,7 +55,7 @@ public class Bootstrap { } public Bootstrap(String applicationContextLocation) throws IOException { - setupLogging(); + //setupLogging(); createApplicationContext(); shell = ctx.getBean("shell", JLineShellComponent.class); @@ -71,31 +67,15 @@ public class Bootstrap { Map commands = BeanFactoryUtils.beansOfTypeIncludingAncestors(ctx, CommandMarker.class); for (CommandMarker command : commands.values()) { - //System.out.println("Registering command " + command); shell.getSimpleParser().add(command); } Map converters = BeanFactoryUtils.beansOfTypeIncludingAncestors(ctx, Converter.class); for (Converter converter : converters.values()) { - //System.out.println("Registering converter " + converter); shell.getSimpleParser().add(converter); } + shell.start(); - - //TODO use listener and latch.. - while (true) { - if (shell.getShellStatus().getStatus().equals(ShellStatus.Status.USER_INPUT)) { - break; - } - else { - try { - Thread.sleep(50); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } private void createApplicationContext() { @@ -127,8 +107,6 @@ public class Bootstrap { ctx = initPluginApplicationContext(annctx); ctx.refresh(); - - } /** @@ -157,6 +135,7 @@ public class Bootstrap { } } + // seems on JDK 1.6.0_18 or higher causes the output to disappear private void setupLogging() { // Ensure all JDK log messages are deferred until a target is registered Logger rootLogger = Logger.getLogger(""); @@ -168,7 +147,7 @@ public class Bootstrap { // Set a suitable priority level on Roo log messages // (see ROO-539 and HandlerUtils.getLogger(Class)) - Logger rooLogger = Logger.getLogger("org.springframework.roo"); + Logger rooLogger = Logger.getLogger("org.springframework.shell"); rooLogger.setLevel(Level.FINE); } @@ -193,6 +172,7 @@ public class Bootstrap { } } else { + shell.promptLoop(); exitShellRequest = shell.getExitShellRequest(); if (exitShellRequest == null) { // shouldn't really happen, but we'll fallback to this anyway diff --git a/src/main/java/org/springframework/shell/IdeTerminal.java b/src/main/java/org/springframework/shell/IdeTerminal.java new file mode 100644 index 00000000..e1bfa06d --- /dev/null +++ b/src/main/java/org/springframework/shell/IdeTerminal.java @@ -0,0 +1,28 @@ +/* + * Copyright 2011-2012 the original author or authors. + * + * 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.springframework.shell; + +import jline.UnsupportedTerminal; + +/** + * Terminal used for debugging inside an IDE. See the development instructions. + */ +public class IdeTerminal extends UnsupportedTerminal { + + public boolean isANSISupported() { + return false; + } +} diff --git a/src/main/java/org/springframework/shell/JLineShell.java b/src/main/java/org/springframework/shell/JLineShell.java index 75f759a3..4d2119df 100644 --- a/src/main/java/org/springframework/shell/JLineShell.java +++ b/src/main/java/org/springframework/shell/JLineShell.java @@ -454,7 +454,7 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker, String line; try { - while (exitShellRequest == null && ((line = reader.readLine()) != null)) { + while (exitShellRequest == null && (reader != null && ((line = reader.readLine()) != null))) { JLineLogHandler.resetMessageTracking(); setShellStatus(Status.USER_INPUT); diff --git a/src/main/java/org/springframework/shell/JLineShellComponent.java b/src/main/java/org/springframework/shell/JLineShellComponent.java index ce1b9f3f..e5b3525b 100644 --- a/src/main/java/org/springframework/shell/JLineShellComponent.java +++ b/src/main/java/org/springframework/shell/JLineShellComponent.java @@ -50,10 +50,6 @@ public class JLineShellComponent extends JLineShell implements Lifecycle { private ExecutionStrategy executionStrategy = new SimpleExecutionStrategy(); //ProcessManagerHostedExecutionStrategy is not what i think we need outside of Roo. private SimpleParser parser = new SimpleParser(); - // Dont' need this, used to get twitter status. - //@Reference private UrlInputStreamService urlInputStreamService; - // - public SimpleParser getSimpleParser() { return parser; @@ -224,6 +220,4 @@ public class JLineShellComponent extends JLineShell implements Lifecycle { protected String getVersion() { return version; } - - } \ No newline at end of file diff --git a/src/main/java/org/springframework/shell/SimpleExecutionStrategy.java b/src/main/java/org/springframework/shell/SimpleExecutionStrategy.java index 2c4db2d4..11a2c3ac 100644 --- a/src/main/java/org/springframework/shell/SimpleExecutionStrategy.java +++ b/src/main/java/org/springframework/shell/SimpleExecutionStrategy.java @@ -14,24 +14,15 @@ public class SimpleExecutionStrategy implements ExecutionStrategy { synchronized (mutex) { Assert.isTrue(isReadyForCommands(), "ProcessManagerHostedExecutionStrategy not yet ready for commands"); return ReflectionUtils.invokeMethod(parseResult.getMethod(), parseResult.getInstance(), parseResult.getArguments()); - /* - Assert.isTrue(isReadyForCommands(), "ProcessManagerHostedExecutionStrategy not yet ready for commands"); - return processManager.execute(new CommandCallback() { - public Object callback() { - return ReflectionUtils.invokeMethod(parseResult.getMethod(), parseResult.getInstance(), parseResult.getArguments()); - } - });*/ } } public boolean isReadyForCommands() { - // TODO Auto-generated method stub return true; } public void terminate() { - // TODO Auto-generated method stub - + // do nothing } }