List of usage examples for org.apache.commons.exec CommandLine addArguments
public CommandLine addArguments(final String addArguments)
From source file:org.apache.zeppelin.interpreter.launcher.Kubectl.java
public ExecuteWatchdog portForward(String resource, String[] ports) throws IOException { DefaultExecutor executor = new DefaultExecutor(); CommandLine cmd = new CommandLine(kubectlCmd); cmd.addArguments("port-forward"); cmd.addArguments(resource);//from ww w . j av a 2s. c om cmd.addArguments(ports); ExecuteWatchdog watchdog = new ExecuteWatchdog(-1); executor.setWatchdog(watchdog); executor.execute(cmd, new ExecuteResultHandler() { @Override public void onProcessComplete(int i) { LOGGER.info("Port-forward stopped"); } @Override public void onProcessFailed(ExecuteException e) { LOGGER.debug("port-forward process exit", e); } }); return watchdog; }
From source file:org.apache.zeppelin.interpreter.launcher.Kubectl.java
public int execute(String[] args, InputStream stdin, OutputStream stdout, OutputStream stderr) throws IOException { DefaultExecutor executor = new DefaultExecutor(); CommandLine cmd = new CommandLine(kubectlCmd); cmd.addArguments(args); ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 1000); executor.setWatchdog(watchdog);//w w w. jav a 2 s. c om PumpStreamHandler streamHandler = new PumpStreamHandler(stdout, stderr, stdin); executor.setStreamHandler(streamHandler); return executor.execute(cmd); }
From source file:org.bonitasoft.platform.setup.PlatformSetupDistributionIT.java
@Test public void setupSh_should_work_with_init_on_h2_with_overridden_system_property() throws Exception { //given/*from w w w. j av a 2 s . c o m*/ CommandLine oCmdLine = PlatformSetupTestUtils.createCommandLine(); oCmdLine.addArguments("init -Ddb.user=myUser"); DefaultExecutor executor = PlatformSetupTestUtils.createExecutor(distFolder); executor.setStreamHandler(PlatformSetupTestUtils.getExecuteStreamHandler("Y")); //when int iExitValue = executor.execute(oCmdLine); //then assertThat(iExitValue).isEqualTo(0); Connection jdbcConnection = PlatformSetupTestUtils.getJdbcConnection(distFolder, "myUser"); Statement statement = jdbcConnection.createStatement(); ResultSet resultSet = statement.executeQuery("SELECT COUNT(*) AS nb FROM CONFIGURATION"); resultSet.next(); assertThat(resultSet.getInt("nb")).isGreaterThan(0); }
From source file:org.bonitasoft.platform.setup.PlatformSetupDistributionIT.java
@Test public void setupSh_should_work_on_postgres_database() throws Exception { //given/* ww w. j a v a2 s . co m*/ File dbFolder = temporaryFolder.newFolder(); Server pgServer = Server.createPgServer("-baseDir", dbFolder.getAbsolutePath()); CommandLine oCmdLine = PlatformSetupTestUtils.createCommandLine(); oCmdLine.addArguments("init"); try { //server must be started to have a valid port pgServer.start(); DefaultExecutor executor = PlatformSetupTestUtils.createExecutor(distFolder); //when Path databaseProperties = distFolder.toPath().resolve("database.properties"); Properties properties = new Properties(); properties.load(new ByteArrayInputStream(Files.readAllBytes(databaseProperties))); properties.setProperty("db.vendor", "postgres"); properties.setProperty("db.server.name", "localhost"); properties.setProperty("db.server.port", String.valueOf(pgServer.getPort())); properties.setProperty("db.database.name", "bonita"); ByteArrayOutputStream out = new ByteArrayOutputStream(); properties.store(out, ""); Files.write(databaseProperties, out.toByteArray()); int iExitValue = executor.execute(oCmdLine); //then assertThat(iExitValue).isEqualTo(0); } finally { pgServer.shutdown(); } }
From source file:org.codehaus.mojo.cassandra.AbstractCassandraMojo.java
/** * Creates the command line to launch the {@code nodetool} utility. * * @param args the command line arguments to pass to the {@code nodetool} utility. * @return the {@link CommandLine} to launch {@code nodetool} with the supplied arguments. * @throws IOException if there are issues creating the cassandra home directory. *//* ww w .j a va 2 s. co m*/ protected CommandLine newNodetoolCommandLine(String... args) throws IOException { createCassandraHome(); CommandLine commandLine = newJavaCommandLine(); commandLine.addArgument("-jar"); // It seems that java cannot handle quoted jar file names... commandLine.addArgument(new File(new File(cassandraDir, "bin"), "nodetool.jar").getAbsolutePath(), false); commandLine.addArgument("--host"); commandLine.addArgument("127.0.0.1"); commandLine.addArgument("--port"); commandLine.addArgument(Integer.toString(jmxPort)); commandLine.addArguments(args); return commandLine; }
From source file:org.eclipse.ecf.python.AbstractPythonLauncher.java
@Override public void launch(String[] args, OutputStream output) throws Exception { synchronized (this.launchLock) { if (isLaunched()) throw new IllegalStateException("Already started"); this.shuttingDown = false; if (enabled) { String pythonLaunchCommand = createPythonLaunchCommand(); if (pythonLaunchCommand == null) throw new NullPointerException("pythonLaunchCommand must not be null"); logger.debug("pythonLaunchCommand=" + pythonLaunchCommand); this.executor = createExecutor(); if (this.pythonWorkingDirectory != null) this.executor.setWorkingDirectory(pythonWorkingDirectory); if (output == null) { output = new LogOutputStream() { @Override//from w ww . ja v a 2s .co m protected void processLine(String line, int level) { logger.debug("PYTHON: " + line); } }; } executor.setStreamHandler(new PumpStreamHandler(output)); this.executor.setProcessDestroyer(new PythonProcessDestroyer()); ExecuteResultHandler executeHandler = new DefaultExecuteResultHandler() { @Override public void onProcessComplete(int exitValue) { logger.debug("PYTHON EXIT=" + exitValue); } @Override public void onProcessFailed(ExecuteException e) { if (!shuttingDown) logger.debug("PYTHON EXCEPTION", e); } }; CommandLine commandLine = new CommandLine(pythonExec).addArgument(PYTHON_LAUNCH_COMMAND_OPTION); commandLine.addArgument(pythonLaunchCommand, true); List<String> argsList = (args == null) ? Collections.emptyList() : Arrays.asList(args); if (this.javaPort != null && !argsList.contains(JAVA_PORT_OPTION)) { commandLine.addArgument(JAVA_PORT_OPTION); commandLine.addArgument(String.valueOf(this.javaPort)); } if (this.pythonPort != null && !argsList.contains(PYTHON_PORT_OPTION)) { commandLine.addArgument(PYTHON_PORT_OPTION); commandLine.addArgument(String.valueOf(this.pythonPort)); } if (args != null) commandLine.addArguments(args); logger.debug("PythonLauncher.launch: " + commandLine); try { executor.execute(commandLine, executeHandler); } catch (Exception e) { this.executor = null; throw e; } } else logger.debug("PythonLauncher DISABLED. Python process must be started manually"); } }
From source file:org.eclipse.php.composer.core.launch.ScriptLauncher.java
public void launch(String argument, String[] params) throws ExecuteException, IOException, InterruptedException { CommandLine cmd = environment.getCommand(); cmd.addArgument(argument);//from w w w .j a va2s . c om cmd.addArguments(params); executor = new ScriptExecutor(); if (timeout != null) { executor.setTimeout(timeout); } Logger.debug("Setting executor working directory to " + project.getLocation().toOSString()); //$NON-NLS-1$ executor.setWorkingDirectory(project.getLocation().toFile()); for (ExecutionResponseListener listener : listeners) { executor.addResponseListener(listener); } Map<String, String> env = new HashMap<String, String>(System.getenv()); PHPLaunchUtilities.appendExecutableToPathEnv(env, new File(cmd.getExecutable()).getParentFile()); PHPLaunchUtilities.appendLibrarySearchPathEnv(env, new File(cmd.getExecutable()).getParentFile()); executor.execute(cmd, env); }
From source file:org.eclipse.php.composer.ui.terminal.ComposerLauncher.java
@Override public void launch(String argument, String... params) throws ExecuteException, IOException, InterruptedException { CommandLine cmd = environment.getCommand(); cmd.addArgument(argument);/*from w ww.j av a 2 s. co m*/ cmd.addArguments(params); Map<String, String> env = new HashMap<String, String>(System.getenv()); PHPLaunchUtilities.appendExecutableToPathEnv(env, new File(cmd.getExecutable()).getParentFile()); PHPLaunchUtilities.appendLibrarySearchPathEnv(env, new File(cmd.getExecutable()).getParentFile()); Map<String, Object> properties = new HashMap<String, Object>(); List<String> envs = new ArrayList<>(env.size()); for (String key : env.keySet()) { envs.add(key + '=' + env.get(key)); } properties.put(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT, envs.toArray(new String[envs.size()])); properties.put(ITerminalsConnectorConstants.PROP_PROCESS_MERGE_ENVIRONMENT, true); ITerminalServiceOutputStreamMonitorListener[] outListeners = new ITerminalServiceOutputStreamMonitorListener[] { new ITerminalServiceOutputStreamMonitorListener() { @Override public void onContentReadFromStream(byte[] byteBuffer, int bytesRead) { for (ExecutionResponseListener handler : getListeners()) { handler.executionMessage(new String(byteBuffer, 0, bytesRead)); } } } }; properties.put(ITerminalsConnectorConstants.PROP_STDOUT_LISTENERS, outListeners); // workaround for colored output on Windows if (Platform.OS_WIN32.equals(Platform.getOS())) { StringBuilder builder = new StringBuilder(); builder.append("@echo off").append(WINDOWS_END_OF_LINE); // $NON-NLS-1$ // 65001 - UTF-8 builder.append("chcp 65001").append(WINDOWS_END_OF_LINE); // $NON-NLS-1$ builder.append("cls").append(WINDOWS_END_OF_LINE); //$NON-NLS-1$ builder.append(escapePath(cmd.getExecutable())).append(' '); for (String arg : cmd.getArguments()) { builder.append(arg).append(' '); } File file = File.createTempFile("composer_windows_", ".bat"); // $NON-NLS-1$ //$NON-NLS-2$ file.deleteOnExit(); try (BufferedWriter writer = new BufferedWriter(new FileWriter(file));) { writer.write(builder.toString()); } catch (FileNotFoundException ex) { ComposerPlugin.logException(ex); } properties.put(ITerminalsConnectorConstants.PROP_PROCESS_PATH, "cmd"); //$NON-NLS-1$ String args = "/C " + file.getAbsolutePath(); //$NON-NLS-1$ properties.put(ITerminalsConnectorConstants.PROP_PROCESS_ARGS, args); } else { properties.put(ITerminalsConnectorConstants.PROP_PROCESS_PATH, escapePath(cmd.getExecutable())); StringBuilder builder = new StringBuilder(); for (String arg : cmd.getArguments()) { builder.append(arg + ' '); } properties.put(ITerminalsConnectorConstants.PROP_PROCESS_ARGS, builder.toString()); } Logger.debug("Setting executor working directory to " + project.getLocation().toOSString()); //$NON-NLS-1$ properties.put(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR, project.getLocation().toOSString()); String title = MessageFormat.format(Messages.ComposerConsoleManager_ConsoleLabel, Messages.ComposerConsoleManager_ConsoleName, project.getName()); IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager(); final CountDownLatch latch = new CountDownLatch(1); terminalConsole = new TerminalConsole(title, 0, properties, new Done() { @Override public void done(IStatus status) { latch.countDown(); } }); for (ExecutionResponseListener handler : getListeners()) { handler.executionStarted(); } consoleManager.addConsoles(new IConsole[] { terminalConsole }); consoleManager.showConsoleView(terminalConsole); latch.await(); for (ExecutionResponseListener handler : getListeners()) { handler.executionFinished("", 0); //$NON-NLS-1$ } }
From source file:org.excalibur.service.aws.CmsearchCommand.java
public void execute() throws ShellException, IOException { CommandLine command = new CommandLine("cmsearch"); if (output_ != null) { command.addArguments("-o " + output_.getAbsolutePath()); }//w w w. j a v a 2 s . c o m if (tblout_ != null) { command.addArgument(" --tblout " + tblout_.getAbsolutePath()); } command.addArgument(cmfile_.getAbsolutePath()); command.addArgument(seqdb_.getAbsolutePath()); getShell().execute(command); }
From source file:org.fornax.toolsupport.sculptor.maven.plugin.GeneratorMojo.java
/** * Builds command line for starting the Eclipse MWE2 launcher in a JVM. * //from w w w.j a v a2 s.c o m * @param changedFiles * list of files from <code>checkFileSets</code> which are * modified since last generator execution or <code>null</code> * if code generation is enforced */ protected CommandLine getGeneratorCommandLine(Set<String> changedFiles) throws MojoExecutionException { CommandLine cl = new CommandLine(getJavaExecutable()); cl.addArguments(jvmArguments); if (changedFiles != null) { cl.addArgument("-D" + CHANGED_FILES_PROPERTY + "=" + toCommaSeparatedString(changedFiles)); } cl.addArgument("-D" + GeneratorMojo.LOGBACK_CONFIGURATION_FILE_PROPERTY + "=" + this.getClass().getResource("/" + (isVerbose() ? LOGBACK_VERBOSE_CONFIGURATION_FILE_NAME : LOGBACK_NORMAL_CONFIGURATION_FILE_NAME))); cl.addArguments("-classpath " + getGeneratorClasspath()); cl.addArgument(MWE2_WORKFLOW_LAUNCHER); cl.addArgument(workflowDescriptor); if (isVerbose() || getLog().isDebugEnabled()) { getLog().info("Commandline: " + cl); } return cl; }