use of org.apache.felix.gogo.runtime.CommandProcessorImpl in project felix by apache.
the class Activator method newProcessor.
protected ServiceRegistration newProcessor(ThreadIO tio, BundleContext context) {
processor = new CommandProcessorImpl(tio);
try {
processor.addListener(new EventAdminListener(context));
} catch (NoClassDefFoundError error) {
// Ignore the listener if EventAdmin package isn't present
}
// Setup the variables and commands exposed in an OSGi environment.
processor.addConstant(CONTEXT, context);
processor.addCommand("osgi", processor, "addCommand");
processor.addCommand("osgi", processor, "removeCommand");
processor.addCommand("osgi", processor, "eval");
return context.registerService(CommandProcessor.class.getName(), processor, null);
}
use of org.apache.felix.gogo.runtime.CommandProcessorImpl in project felix by apache.
the class Main method main.
public static void main(String[] args) throws IOException {
try (Terminal terminal = TerminalBuilder.builder().name("gogo").system(true).nativeSignals(true).signalHandler(Terminal.SignalHandler.SIG_IGN).build()) {
ThreadIOImpl tio = new ThreadIOImpl();
tio.start();
try {
CommandProcessorImpl processor = new CommandProcessorImpl(tio);
Context context = new MyContext();
Shell shell = new Shell(context, processor, tio, null);
processor.addCommand("gogo", processor, "addCommand");
processor.addCommand("gogo", processor, "removeCommand");
processor.addCommand("gogo", processor, "eval");
processor.addConverter(new BaseConverters());
register(processor, new Builtin(), Builtin.functions);
register(processor, new Procedural(), Procedural.functions);
register(processor, new Posix(processor), Posix.functions);
register(processor, shell, Shell.functions);
InputStream in = new FilterInputStream(terminal.input()) {
@Override
public void close() throws IOException {
}
};
OutputStream out = new FilterOutputStream(terminal.output()) {
@Override
public void close() throws IOException {
}
};
CommandSession session = processor.createSession(in, out, out);
session.put(Shell.VAR_CONTEXT, context);
session.put(Shell.VAR_TERMINAL, terminal);
try {
String[] argv = new String[args.length + 1];
argv[0] = "--login";
System.arraycopy(args, 0, argv, 1, args.length);
shell.gosh(session, argv);
} catch (Exception e) {
Object loc = session.get(".location");
if (null == loc || !loc.toString().contains(":")) {
loc = "gogo";
}
System.err.println(loc + ": " + e.getClass().getSimpleName() + ": " + e.getMessage());
e.printStackTrace();
} finally {
session.close();
}
} finally {
tio.stop();
}
}
}
use of org.apache.felix.gogo.runtime.CommandProcessorImpl in project karaf by apache.
the class ActionMaskingCallbackTest method setUp.
@Before
public void setUp() {
ThreadIO tio = new ThreadIOImpl();
CommandProcessor cp = new CommandProcessorImpl(tio);
SessionFactory sf = new SessionFactoryImpl(tio);
InputStream is = new ByteArrayInputStream(new byte[0]);
PrintStream os = new PrintStream(new ByteArrayOutputStream());
Session session = new HeadlessSessionImpl(sf, cp, is, os, os);
parser = new KarafParser(session);
ActionCommand cmd = new ActionCommand(null, UserAddCommand.class);
cb = ActionMaskingCallback.build(cmd);
}
Aggregations