/** * <p> * Get the OSGI-INF/bundle.info entry from the bundle and display it. * </p> * * @param bundle the bundle. */ @Override protected void executeOnBundle(Bundle bundle) throws Exception { session.execute("*:help 'bundle|" + bundle.getBundleId() + "'"); }
/** * <p> * Get the OSGI-INF/bundle.info entry from the bundle and display it. * </p> * * @param bundle the bundle. */ @Override protected void executeOnBundle(Bundle bundle) throws Exception { session.execute("*:help 'bundle|" + bundle.getBundleId() + "'"); }
private void doExecuteScript(Session session, Path scriptFileName) { try { String script = String.join("\n", Files.readAllLines(scriptFileName)); session.execute(script); } catch (Exception e) { LOGGER.debug("Error in initialization script {}", scriptFileName, e); System.err.println("Error in initialization script: " + scriptFileName + ": " + e.getMessage()); } }
private void doExecuteScript(Session session, Path scriptFileName) { try { String script = String.join("\n", Files.readAllLines(scriptFileName)); session.execute(script); } catch (Exception e) { LOGGER.debug("Error in initialization script {}", scriptFileName, e); System.err.println("Error in initialization script: " + scriptFileName + ": " + e.getMessage()); } }
if (password == null) { if (keyFile == null) { session.execute("ssh:ssh -q -l " + username + " -p " + port + " localhost " + cmdStr); } else { session.execute("ssh:ssh -q -l " + username + " -p " + port + " -k " + keyFile + " localhost " + cmdStr); session.execute("ssh:ssh -q -l " + username + " -P " + password + " -p " + port + " localhost " + cmdStr); session.execute("ssh:ssh -q -p " + port + " localhost " + cmdStr); } else { session.execute("ssh:ssh -q -p " + port + " -k " + keyFile + " localhost " + cmdStr);
if (password == null) { if (keyFile == null) { session.execute("ssh:ssh -q -l " + username + " -p " + port + " localhost " + cmdStr); } else { session.execute("ssh:ssh -q -l " + username + " -p " + port + " -k " + keyFile + " localhost " + cmdStr); session.execute("ssh:ssh -q -l " + username + " -P " + password + " -p " + port + " localhost " + cmdStr); session.execute("ssh:ssh -q -p " + port + " localhost " + cmdStr); } else { session.execute("ssh:ssh -q -p " + port + " -k " + keyFile + " localhost " + cmdStr);
@Override public Object execute() throws Exception { SupportedPlugin st = SupportedPlugin.which( this.targetName ); if( st == null ) { this.out.println( "Unknown plug-in: " + this.targetName + ". Make sure it is correct or install it manually." ); } else if( this.roboconfVersion == null ) { this.out.println( "Error: the Roboconf version could not be determined." ); } else for( String cmd : st.findCommands( this.roboconfVersion )) { this.logger.fine( "Executing " + cmd + "..." ); this.out.println( "Executing " + cmd + "..." ); this.session.execute( cmd ); } return null; } }
@Override public final void doAction(String prefix, Dictionary<String, Object> config) throws Exception { if (id == null || "".equals(id.trim())) { System.err.println("Please specify ID of repository"); return; } MavenRepositoryURL[] repositories = repositories(config, !defaultRepository); MavenRepositoryURL[] repositoriesFromPidProperty = Arrays.stream(repositories) .filter((repo) -> repo.getFrom() == MavenRepositoryURL.FROM.PID) .toArray(MavenRepositoryURL[]::new); MavenRepositoryURL[] repositoriesFromSettings = Arrays.stream(repositories) .filter((repo) -> repo.getFrom() == MavenRepositoryURL.FROM.SETTINGS) .toArray(MavenRepositoryURL[]::new); edit(prefix, config, repositories, repositoriesFromPidProperty, repositoriesFromSettings); if (success) { if (showPasswords) { session.execute("maven:repository-list -v -x"); } else { session.execute("maven:repository-list -v"); } } }
public void run() { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(byteArrayOutputStream); try (Session session = sessionFactory.create(new ByteArrayInputStream(new byte[0]), printStream, printStream, WatchAction.this.session)) { executing = Thread.currentThread(); session.execute(arguments.trim()); } catch (InterruptedException e) { abort(null); } catch (Exception e) { ShellUtil.logException(session, e); } finally { executing = null; } printStream.flush(); if (!abort) { if (!append) { System.out.print("\33[2J"); System.out.print("\33[1;1H"); } System.out.print(byteArrayOutputStream.toString()); System.out.flush(); } } catch (Exception e) { //Ingore } }
public void run() { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(byteArrayOutputStream); try (Session session = sessionFactory.create(new ByteArrayInputStream(new byte[0]), printStream, printStream, WatchAction.this.session)) { executing = Thread.currentThread(); session.execute(arguments.trim()); } catch (InterruptedException e) { abort(null); } catch (Exception e) { ShellUtil.logException(session, e); } finally { executing = null; } printStream.flush(); if (!abort) { if (!append) { System.out.print("\33[2J"); System.out.print("\33[1;1H"); } System.out.print(byteArrayOutputStream.toString()); System.out.flush(); } } catch (Exception e) { //Ingore } }
@Override public Object execute() throws Exception { Subject subject = new Subject(); LoginContext loginContext = new LoginContext(realm, subject, callbacks -> { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { ((NameCallback) callback).setName(user); } else if (callback instanceof PasswordCallback) { String password = SudoCommand.this.session.readLine("Password: ", '*'); ((PasswordCallback) callback).setPassword(password.toCharArray()); } else { throw new UnsupportedCallbackException(callback); } } }); loginContext.login(); final StringBuilder sb = new StringBuilder(); for (String s : command) { if (sb.length() > 0) { sb.append(" "); } sb.append(s); } JaasHelper.doAs(subject, (PrivilegedExceptionAction<Object>) () -> session.execute(sb)); loginContext.logout(); return null; }
@Override public Object execute() throws Exception { Subject subject = new Subject(); LoginContext loginContext = new LoginContext(realm, subject, callbacks -> { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { ((NameCallback) callback).setName(user); } else if (callback instanceof PasswordCallback) { String password = SudoCommand.this.session.readLine("Password: ", '*'); ((PasswordCallback) callback).setPassword(password.toCharArray()); } else { throw new UnsupportedCallbackException(callback); } } }); loginContext.login(); final StringBuilder sb = new StringBuilder(); for (String s : command) { if (sb.length() > 0) { sb.append(" "); } sb.append(s); } JaasHelper.doAs(subject, (PrivilegedExceptionAction<Object>) () -> session.execute(sb)); loginContext.logout(); return null; }
@Override public Object execute() throws Exception { // Display information about Roboconf List<String> versions = new ArrayList<> (); for( Bundle bundle : this.ctx.getBundles()) { if( Constants.RBCF_CORE_SYMBOLIC_NAME.equals( bundle.getSymbolicName())) versions.add( bundle.getVersion().toString()); } this.out.println(); this.out.println( "Roboconf" ); // We format our stuff just like the "info" command. // See https://github.com/apache/karaf/blob/master/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/InfoAction.java if( versions.size() > 1 ) { this.out.println( "\n[ WARNING ] Several versions of Roboconf run in the server." ); this.out.println( "[ WARNING ] Please, run bundle:list | grep roboconf-core for more details." ); this.out.println(); printValue( "Roboconf versions", versions.get( 0 )); for( int i=1; i<versions.size(); i++ ) printValue( "", versions.get( i )); } else if( versions.size() == 1 ) { printValue( "Roboconf version", versions.get( 0 )); } else { printValue( "Roboconf version", "Undetermined" ); } this.out.println(); // Show Karaf info this.session.execute( KARAF_INFO ); this.out.println(); return null; }
session.execute(w.toString()); } finally { for (int i = 0; args != null && i < args.size(); i++) {
session.execute(w.toString()); } finally { for (int i = 0; args != null && i < args.size(); i++) {
public String getHelp(Session session, String path) { if (path.indexOf('|') > 0) { if (path.startsWith("command|")) { path = path.substring("command|".length()); } else { return null; } } ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos, true); Session s = session.getFactory().create(bais, ps, ps, session); s.put(Session.SCOPE, session.get(Session.SCOPE)); s.put(Session.SUBSHELL, session.get(Session.SUBSHELL)); try { s.execute(path + " --help"); } catch (Throwable t) { return null; } finally { s.close(); } return baos.toString(); }
public String getHelp(Session session, String path) { if (path.indexOf('|') > 0) { if (path.startsWith("command|")) { path = path.substring("command|".length()); } else { return null; } } ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos, true); Session s = session.getFactory().create(bais, ps, ps, session); s.put(Session.SCOPE, session.get(Session.SCOPE)); s.put(Session.SUBSHELL, session.get(Session.SUBSHELL)); try { s.execute(path + " --help"); } catch (Throwable t) { return null; } finally { s.close(); } return baos.toString(); }
private void run(final SessionFactory sessionFactory, String command, final InputStream in, final PrintStream out, final PrintStream err, ClassLoader cl) throws Exception { try (org.jline.terminal.Terminal jlineTerminal = TerminalBuilder.terminal()) { final Terminal terminal = new JLineTerminal(jlineTerminal); try (Session session = createSession(sessionFactory, command.length() > 0 ? null : in, out, err, terminal)) { session.put("USER", user); session.put("APPLICATION", application); discoverCommands(session, cl, getDiscoveryResource()); if (command.length() > 0) { // Shell is directly executing a sub/command, we don't setup a console // in this case, this avoids us reading from stdin un-necessarily. session.put(NameScoping.MULTI_SCOPE_MODE_KEY, Boolean.toString(isMultiScopeMode())); session.put(Session.PRINT_STACK_TRACES, "execution"); try { session.execute(command); } catch (Throwable t) { ShellUtil.logException(session, t); } } else { // We are going into full blown interactive shell mode. session.run(); } } } }
private void run(final SessionFactory sessionFactory, String command, final InputStream in, final PrintStream out, final PrintStream err, ClassLoader cl) throws Exception { try (org.jline.terminal.Terminal jlineTerminal = TerminalBuilder.terminal()) { final Terminal terminal = new JLineTerminal(jlineTerminal); try (Session session = createSession(sessionFactory, command.length() > 0 ? null : in, out, err, terminal)) { session.put("USER", user); session.put("APPLICATION", application); discoverCommands(session, cl, getDiscoveryResource()); if (command.length() > 0) { // Shell is directly executing a sub/command, we don't setup a console // in this case, this avoids us reading from stdin un-necessarily. session.put(NameScoping.MULTI_SCOPE_MODE_KEY, Boolean.toString(isMultiScopeMode())); session.put(Session.PRINT_STACK_TRACES, "execution"); try { session.execute(command); } catch (Throwable t) { ShellUtil.logException(session, t); } } else { // We are going into full blown interactive shell mode. session.run(); } } } }
protected void doExecute() { if (command == null || timer == null) return; log().i(name,"execute",command); StreamToLogAdapter out = new StreamToLogAdapter(LEVEL.INFO, null); StreamToLogAdapter err = new StreamToLogAdapter(LEVEL.ERROR, null); try { SessionFactory commandProcessor=MOsgi.getService(SessionFactory.class); ByteArrayInputStream in = new ByteArrayInputStream(new byte[0]); Session commandSession=commandProcessor.create(in,out,err); commandSession.put("interactive.mode", false); commandSession.put("APPLICATION",System.getProperty("karaf.name","root")); commandSession.put("USER","karaf"); commandSession.execute(command); } catch (Throwable t) { log().w(name,t); } out.close(); err.close(); }