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:
Costin Leau
2012-07-12 11:01:17 +03:00
parent 3f0f29fd00
commit ac33f37e6f
6 changed files with 71 additions and 46 deletions

View File

@@ -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

View 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;
}
}

View File

@@ -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);

View File

@@ -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;
}
}

View File

@@ -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
}
}