use of org.apache.felix.gogo.runtime.threadio.ThreadIOImpl in project karaf by apache.
the class Activator method start.
@Override
public void start(final BundleContext context) throws Exception {
threadIO = new ThreadIOImpl();
threadIO.start();
sessionFactory = new SecuredSessionFactoryImpl(context, threadIO);
sessionFactory.getCommandProcessor().addConverter(new Converters(context));
sessionFactory.getCommandProcessor().addConstant(".context", context.getBundle(0).getBundleContext());
final CopyOnWriteArraySet<CommandLoggingFilter> listeners = new CopyOnWriteArraySet<>();
filterTracker = new ServiceTracker<>(context, CommandLoggingFilter.class, new ServiceTrackerCustomizer<CommandLoggingFilter, CommandLoggingFilter>() {
@Override
public CommandLoggingFilter addingService(ServiceReference<CommandLoggingFilter> reference) {
CommandLoggingFilter service = context.getService(reference);
listeners.add(service);
return service;
}
@Override
public void modifiedService(ServiceReference<CommandLoggingFilter> reference, CommandLoggingFilter service) {
}
@Override
public void removedService(ServiceReference<CommandLoggingFilter> reference, CommandLoggingFilter service) {
listeners.remove(service);
context.ungetService(reference);
}
});
filterTracker.open();
LoggingCommandSessionListener loggingCommandSessionListener = new LoggingCommandSessionListener();
loggingCommandSessionListener.setFilters(listeners);
sessionFactory.getCommandProcessor().addListener(loggingCommandSessionListener);
try {
EventAdminListener listener = new EventAdminListener(context);
sessionFactory.getCommandProcessor().addListener(listener);
eventAdminListener = listener;
} catch (NoClassDefFoundError error) {
// Ignore the listener if EventAdmin package isn't present
}
sessionFactory.register(new ManagerImpl(sessionFactory, sessionFactory));
sessionFactoryRegistration = context.registerService(SessionFactory.class, sessionFactory, null);
actionExtender = new CommandExtender(sessionFactory);
actionExtender.start(context);
commandTracker = new CommandTracker(sessionFactory, context);
commandTracker.open();
if (Boolean.parseBoolean(context.getProperty(START_CONSOLE))) {
localConsoleManager = new LocalConsoleManager(context, sessionFactory);
localConsoleManager.start();
} else {
LOGGER.info("Not starting local console. To activate set " + START_CONSOLE + "=true");
}
}
use of org.apache.felix.gogo.runtime.threadio.ThreadIOImpl in project karaf by apache.
the class ParsingTest method testCommandLineParserMultiLine.
@Test
public void testCommandLineParserMultiLine() {
SessionFactoryImpl sessionFactory = new SessionFactoryImpl(new ThreadIOImpl());
ManagerImpl manager = new ManagerImpl(sessionFactory, sessionFactory);
sessionFactory.getRegistry().register(new ActionCommand(manager, FooCommand.class));
sessionFactory.getRegistry().register(new ActionCommand(manager, AnotherCommand.class));
sessionFactory.getRegistry().register(new CustomParser());
Session session = new HeadlessSessionImpl(sessionFactory, sessionFactory.getCommandProcessor(), new ByteArrayInputStream(new byte[0]), new PrintStream(new ByteArrayOutputStream()), new PrintStream(new ByteArrayOutputStream()));
String parsed = CommandLineParser.parse(session, "echo a\necho b");
assertEquals("echo a\necho b", parsed);
}
use of org.apache.felix.gogo.runtime.threadio.ThreadIOImpl in project karaf by apache.
the class ParsingTest method testCommandLineParser.
@Test
public void testCommandLineParser() {
SessionFactoryImpl sessionFactory = new SessionFactoryImpl(new ThreadIOImpl());
ManagerImpl manager = new ManagerImpl(sessionFactory, sessionFactory);
sessionFactory.getRegistry().register(new ActionCommand(manager, FooCommand.class));
sessionFactory.getRegistry().register(new ActionCommand(manager, AnotherCommand.class));
sessionFactory.getRegistry().register(new CustomParser());
Session session = new HeadlessSessionImpl(sessionFactory, sessionFactory.getCommandProcessor(), new ByteArrayInputStream(new byte[0]), new PrintStream(new ByteArrayOutputStream()), new PrintStream(new ByteArrayOutputStream()));
String parsed = CommandLineParser.parse(session, " foo bar (a + b); another command with spaces ");
assertEquals("foo bar (a + b) ; another \"command with spaces\"", parsed);
}
use of org.apache.felix.gogo.runtime.threadio.ThreadIOImpl in project karaf by apache.
the class ShellTableTest method testNonUtf8.
private void testNonUtf8(String encoding) throws Exception {
ShellTable table = new ShellTable();
table.column("col1");
table.column("col2").maxSize(-1).wrap();
table.addRow().addContent("my first column value", "my second column value is quite long");
table.size(50);
ThreadIO tio = new ThreadIOImpl();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos, false, encoding);
table.print(ps, true);
tio.setStreams(new FileInputStream(FileDescriptor.in), ps, ps);
table.print(System.out);
assertEquals("col1 | col2\n" + "----------------------+---------------------------\n" + "my first column value | my second column value is\n" + " | quite long\n" + "col1 | col2\n" + "----------------------+---------------------------\n" + "my first column value | my second column value is\n" + " | quite long\n", baos.toString());
}
use of org.apache.felix.gogo.runtime.threadio.ThreadIOImpl in project karaf by apache.
the class Main method run.
/**
* Use this method when the shell is being executed as a top level shell.
*
* @param args the arguments.
* @throws Exception in case of a failure.
*/
public void run(String[] args) throws Exception {
InputStream in = System.in;
PrintStream out = System.out;
PrintStream err = System.err;
ThreadIOImpl threadio = new ThreadIOImpl();
threadio.start();
run(threadio, args, in, out, err);
// TODO: do we need to stop the threadio that was started?
// threadio.stop();
}
Aggregations