Search in sources :

Example 1 with CommandProcessorImpl

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);
}
Also used : CommandProcessorImpl(org.apache.felix.gogo.runtime.CommandProcessorImpl) CommandProcessor(org.apache.felix.service.command.CommandProcessor)

Example 2 with CommandProcessorImpl

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();
        }
    }
}
Also used : Context(org.apache.felix.gogo.jline.Shell.Context) FilterInputStream(java.io.FilterInputStream) ThreadIOImpl(org.apache.felix.gogo.runtime.threadio.ThreadIOImpl) FilterInputStream(java.io.FilterInputStream) InputStream(java.io.InputStream) CommandProcessorImpl(org.apache.felix.gogo.runtime.CommandProcessorImpl) OutputStream(java.io.OutputStream) FilterOutputStream(java.io.FilterOutputStream) Terminal(org.jline.terminal.Terminal) IOException(java.io.IOException) CommandSession(org.apache.felix.service.command.CommandSession) FilterOutputStream(java.io.FilterOutputStream)

Example 3 with CommandProcessorImpl

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);
}
Also used : ThreadIO(org.apache.felix.service.threadio.ThreadIO) SessionFactory(org.apache.karaf.shell.api.console.SessionFactory) PrintStream(java.io.PrintStream) HeadlessSessionImpl(org.apache.karaf.shell.impl.console.HeadlessSessionImpl) ThreadIOImpl(org.apache.felix.gogo.runtime.threadio.ThreadIOImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CommandProcessorImpl(org.apache.felix.gogo.runtime.CommandProcessorImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) KarafParser(org.apache.karaf.shell.impl.console.parsing.KarafParser) ByteArrayInputStream(java.io.ByteArrayInputStream) CommandProcessor(org.apache.felix.service.command.CommandProcessor) SessionFactoryImpl(org.apache.karaf.shell.impl.console.SessionFactoryImpl) Session(org.apache.karaf.shell.api.console.Session) Before(org.junit.Before)

Aggregations

CommandProcessorImpl (org.apache.felix.gogo.runtime.CommandProcessorImpl)3 InputStream (java.io.InputStream)2 ThreadIOImpl (org.apache.felix.gogo.runtime.threadio.ThreadIOImpl)2 CommandProcessor (org.apache.felix.service.command.CommandProcessor)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FilterInputStream (java.io.FilterInputStream)1 FilterOutputStream (java.io.FilterOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 Context (org.apache.felix.gogo.jline.Shell.Context)1 CommandSession (org.apache.felix.service.command.CommandSession)1 ThreadIO (org.apache.felix.service.threadio.ThreadIO)1 Session (org.apache.karaf.shell.api.console.Session)1 SessionFactory (org.apache.karaf.shell.api.console.SessionFactory)1 HeadlessSessionImpl (org.apache.karaf.shell.impl.console.HeadlessSessionImpl)1 SessionFactoryImpl (org.apache.karaf.shell.impl.console.SessionFactoryImpl)1 KarafParser (org.apache.karaf.shell.impl.console.parsing.KarafParser)1 Terminal (org.jline.terminal.Terminal)1