Package org.apache.felix.service.command

Examples of org.apache.felix.service.command.CommandSession


        if (opt.isSet("command") && args.isEmpty())
        {
            throw opt.usageError("option --command requires argument(s)");
        }

        CommandSession newSession = (login ? session : processor.createSession(
            session.getKeyboard(), session.getConsole(), System.err));

        if (opt.isSet("xtrace"))
        {
            newSession.put("echo", true);
        }

        if (login && interactive)
        {
            URI uri = baseURI.resolve("etc/gosh_profile");
            if (!new File(uri).exists())
            {
                URL url = getClass().getResource("/ext/gosh_profile");
                if (url == null) {
                    url = getClass().getResource("/gosh_profile");
                }
                uri = (url == null) ? null : url.toURI();
            }
            if (uri != null)
            {
                source(session, uri.toString());
            }
        }

        // export variables starting with upper-case to newSession
        for (String key : getVariables(session))
        {
            if (key.matches("[.]?[A-Z].*"))
            {
                newSession.put(key, session.get(key));
            }
        }

        Object result = null;

        if (args.isEmpty())
        {
            if (interactive)
            {
                result = console(newSession);
            }
        }
        else
        {
            CharSequence program;

            if (opt.isSet("command"))
            {
                StringBuilder buf = new StringBuilder();
                for (String arg : args)
                {
                    if (buf.length() > 0)
                    {
                        buf.append(' ');
                    }
                    buf.append(arg);
                }
                program = buf;
            }
            else
            {
                URI script = cwd(session).resolve(args.remove(0));

                // set script arguments
                newSession.put("0", script);
                newSession.put("args", args);

                for (int i = 0; i < args.size(); ++i)
                {
                    newSession.put(String.valueOf(i + 1), args.get(i));
                }

                program = readScript(script);
            }

            result = newSession.execute(program);
        }

        if (login && interactive && !opt.isSet("noshutdown"))
        {
            System.out.println("gosh: stopping framework");
View Full Code Here


    protected String executeCommand(final String command, final Long timeout, final Boolean silent) {
        String response;
        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        final PrintStream printStream = new PrintStream(byteArrayOutputStream);
        final CommandProcessor commandProcessor = getOsgiService(CommandProcessor.class);
        final CommandSession commandSession = commandProcessor.createSession(System.in, printStream, System.err);
        FutureTask<String> commandFuture = new FutureTask<String>(
                new Callable<String>() {
                    public String call() {
                        try {
                            if (!silent) {
                                System.err.println(command);
                            }
                            commandSession.execute(command);
                        } catch (Exception e) {
                            e.printStackTrace(System.err);
                        }
                        printStream.flush();
                        return byteArrayOutputStream.toString();
View Full Code Here

    protected String executeCommands(final String... commands) {
        String response;
        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        final PrintStream printStream = new PrintStream(byteArrayOutputStream);
        final CommandProcessor commandProcessor = getOsgiService(CommandProcessor.class);
        final CommandSession commandSession = commandProcessor.createSession(System.in, printStream, System.err);
        FutureTask<String> commandFuture = new FutureTask<String>(
                new Callable<String>() {
                    public String call() {
                        try {
                            for (String command : commands) {
                                System.err.println(command);
                                commandSession.execute(command);
                            }
                        } catch (Exception e) {
                            e.printStackTrace(System.err);
                        }
                        return byteArrayOutputStream.toString();
View Full Code Here

    public abstract K getCacheableKey(T type);

   @Override
   public int complete(String buffer, int cursor, List<String> candidates) {
     CommandSession commandSession = CommandSessionHolder.getSession();
     ArgumentCompleter.ArgumentList list = (ArgumentCompleter.ArgumentList) commandSession.get(ArgumentCompleter.ARGUMENTS_LIST);
     delegate.getStrings().clear();

     if (list != null) {
        String contextName = extractContextName(list.getArguments());
       String providerOrApi = extractProviderOrApiFromArguments(list.getArguments());
View Full Code Here

       
        public void execute(String command, String expectedOutput, String expectedError) {
            try {
                ByteArrayOutputStream output = new ByteArrayOutputStream();
                ByteArrayOutputStream error = new ByteArrayOutputStream();
                CommandSession session = m_commandProcessor.createSession(System.in, new PrintStream(output), new PrintStream(error));
                session.execute(command);
               
                String out = output.toString();                               
                Pattern p = Pattern.compile(expectedOutput, Pattern.MULTILINE);               
                               
                Assert.assertTrue("\n\nexpected:\n\n" + expectedOutput + "\nbut got:\n\n" + out, p.matcher(out).matches());
View Full Code Here

    private ConfigurationAdmin configAdmin;

    @SuppressWarnings("rawtypes")
    public int complete(final String buffer, final int cursor, final List candidates) {
        CommandSession session = CommandSessionHolder.getSession();
        if (session != null) {
            String pid = getPid(session);
            Set<String> propertyNames = getPropertyNames(pid);
            delegate.getStrings().clear();
            if (propertyNames != null && !propertyNames.isEmpty()) {
View Full Code Here

        // prepare command
        cmd.index = index;
        cmd.setRealms(Arrays.<JaasRealm> asList(realms));

        // prepare mocks
        CommandSession session = createMock(CommandSession.class);
        BundleContext bundleContext = createMock(BundleContext.class);
        Bundle bundle = createMock(Bundle.class);

        for (Config realm : realms)
            realm.setBundleContext(bundleContext);

        Object[] mocks = { session, bundleContext, bundle };

        expect(session.get(ManageRealmCommand.JAAS_REALM)).andReturn(null).anyTimes();
        expect(session.get(ManageRealmCommand.JAAS_ENTRY)).andReturn(null).anyTimes();
        expect(session.get(ManageRealmCommand.JAAS_CMDS)).andReturn(null).anyTimes();
        expect(bundleContext.getBundle()).andReturn(bundle).anyTimes();
        expect(bundle.getBundleId()).andReturn(4711L).anyTimes();

        // verify that the correct realm is returned -- cmd.index is 1-based
        session.put(ManageRealmCommand.JAAS_REALM, realms[index - 1]);
        session.put(eq(ManageRealmCommand.JAAS_ENTRY), anyObject());
        session.put(eq(ManageRealmCommand.JAAS_CMDS), anyObject());

        // start the test
        replay(mocks);
        cmd.execute(session);
        verify(mocks);
View Full Code Here

        public String printHelp(String format) throws Exception {
            PrintStream oldout = System.out;
            try {
                Action action = actionClass.newInstance();
                CommandSession session = new DummyCommandSession();
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                PrintStream newout = new PrintStream(baos);
                System.setOut(newout);
                ActionPreparator preparator;
                if (FORMAT_DOCBX.equals(format)) {
View Full Code Here

     */
    protected String executeCommand(String command) {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        PrintStream printStream = new PrintStream(byteArrayOutputStream);
        CommandProcessor commandProcessor = getOsgiService(CommandProcessor.class);
        CommandSession commandSession = commandProcessor.createSession(System.in, printStream, System.err);
        //This is required in order to run scripts that use those session variables.
        commandSession.put("APPLICATION", System.getProperty("karaf.name", "root"));
        commandSession.put("USER", "karaf");

        try {
            System.err.println(command);
            commandSession.execute(command);
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }
        return byteArrayOutputStream.toString();
    }
View Full Code Here

     */
    protected String executeCommands(final String ...commands) {
        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        final PrintStream printStream = new PrintStream(byteArrayOutputStream);
        final CommandProcessor commandProcessor = getOsgiService(CommandProcessor.class);
        final CommandSession commandSession = commandProcessor.createSession(System.in, printStream, System.err);
        commandSession.put("APPLICATION", System.getProperty("karaf.name", "root"));
        commandSession.put("USER", "karaf");

        for (String command : commands) {
            try {
                System.err.println(command);
                commandSession.execute(command);
            } catch (Exception e) {
                e.printStackTrace(System.err);
            }
        }

View Full Code Here

TOP

Related Classes of org.apache.felix.service.command.CommandSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.