fix start-up loop
remove thread.sleep with proper methods disable logging (seems to be broken on JDK 1.6.0_18 or higher) some code cleanup add debugging instructions for Eclipse
This commit is contained in:
32
readme.dev
Normal file
32
readme.dev
Normal file
@@ -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.
|
||||
@@ -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<String, CommandMarker> commands = BeanFactoryUtils.beansOfTypeIncludingAncestors(ctx, CommandMarker.class);
|
||||
for (CommandMarker command : commands.values()) {
|
||||
//System.out.println("Registering command " + command);
|
||||
shell.getSimpleParser().add(command);
|
||||
}
|
||||
|
||||
Map<String, Converter> 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
|
||||
|
||||
28
src/main/java/org/springframework/shell/IdeTerminal.java
Normal file
28
src/main/java/org/springframework/shell/IdeTerminal.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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<Object>() {
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user