List of usage examples for org.apache.commons.exec CommandLine parse
public static CommandLine parse(final String line)
From source file:de.akquinet.innovation.play.maven.Play2CompilationMojo.java
public void execute() throws MojoExecutionException { String line = getPlay2().getAbsolutePath(); CommandLine cmdLine = CommandLine.parse(line); cmdLine.addArgument("compile"); DefaultExecutor executor = new DefaultExecutor(); if (timeout > 0) { ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog);/*from w ww.j ava 2 s .c o m*/ } executor.setExitValue(0); executor.setWorkingDirectory(project.getBasedir()); try { executor.execute(cmdLine, getEnvironment()); } catch (IOException e) { throw new MojoExecutionException("Error during compilation", e); } }
From source file:de.akquinet.innovation.play.maven.Play2CleanMojo.java
public void execute() throws MojoExecutionException { String line = getPlay2().getAbsolutePath(); CommandLine cmdLine = CommandLine.parse(line); cmdLine.addArgument("clean"); DefaultExecutor executor = new DefaultExecutor(); if (timeout > 0) { ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog);/* w w w . j a va2 s. c o m*/ } executor.setWorkingDirectory(project.getBasedir()); executor.setExitValue(0); try { executor.execute(cmdLine, getEnvironment()); } catch (IOException e) { throw new MojoExecutionException("Error during cleanup", e); } // Also delete the dist directory File dist = new File(project.getBasedir(), "dist"); if (dist.exists()) { getLog().debug("Deleting " + dist.getAbsolutePath()); try { FileUtils.deleteDirectory(dist); } catch (IOException e) { throw new MojoExecutionException("Can't delete the dist folder", e); } } else { getLog().debug("'dist' directory not found"); } // Delete the log folder File logs = new File(project.getBasedir(), "logs"); if (logs.exists()) { getLog().debug("Deleting " + logs.getAbsolutePath()); try { FileUtils.deleteDirectory(logs); } catch (IOException e) { throw new MojoExecutionException("Can't delete the logs folder", e); } } else { getLog().debug("'logs' directory not found"); } // Also delete the lib directory if set if (cleanLibFolder) { File lib = new File(project.getBasedir(), "lib"); if (lib.exists()) { getLog().debug("Deleting " + lib.getAbsolutePath()); try { FileUtils.deleteDirectory(lib); } catch (IOException e) { throw new MojoExecutionException("Can't delete the " + lib + " folder", e); } } else { getLog().debug("'" + lib + "' directory not found"); } } }
From source file:com.kotcrab.vis.editor.util.ApplicationUtils.java
public static void startNewInstance() { try {/*from w w w . ja v a 2s .co m*/ CommandLine cmdLine = CommandLine.parse(getRestartCommand()); DefaultExecutor executor = new DefaultExecutor(); executor.setStreamHandler(new PumpStreamHandler(null, null, null)); executor.execute(cmdLine, new DefaultExecuteResultHandler()); } catch (Exception e) { Log.exception(e); } }
From source file:com.mobilecashout.osprey.plugin.plugins.LocalShellPlugin.java
@Override public DeploymentAction[] actionFromCommand(String command, DeploymentPlan deploymentPlan, DeploymentContext deploymentContext) { return new DeploymentAction[] { new LocalShellAction(CommandLine.parse(command), logOutputStream) }; }
From source file:net.minecraft.client.MineExec.java
@Override protected Integer doInBackground() throws IOException, InterruptedException { Executor exe = new DefaultExecutor(); CommandLine mineExec = CommandLine.parse(mineCmd); PipedOutputStream stdout = new PipedOutputStream(); PipedOutputStream stderr = new PipedOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(stdout, stderr); exe.setStreamHandler(streamHandler); MinecraftApplet configCrusher = new MinecraftApplet(); try {/*ww w.j av a 2 s .c om*/ File target = new File(VersionInfo.getTechnicFolder()); BufferedInputStream biserr = new BufferedInputStream(new PipedInputStream(stderr)); ExecuteResultHandler rh = new DefaultExecuteResultHandler(); exe.execute(mineExec, rh); BufferedReader reader = new BufferedReader(new InputStreamReader(biserr)); configCrusher.minecraftLoaded(); String line = reader.readLine(); logWindow.append(line + "\n"); int dupLen = 0; int dupMax = 25; while (line != null) { String line2 = reader.readLine(); if ((line2.contains("Aether") || line2.contains("aether") && watchCfg && new File(target + File.separator + VersionInfo.getModpackName(), "MenuAPI.properties") .exists())) { configCrusher.prepareConfigs(); } if ((Boolean) nbDebug[2]) { if (!line.equals(line2) || dupLen >= dupMax) { if (dupLen > 0) { logWindow.append(line + "(" + dupLen + ")\n"); } else { if (!line.equals(line2)) { logWindow.append(line2 + "\n"); } } dupLen = 0; } else { dupLen++; } line = line2; } else { logWindow.append(line2 + "\n"); line = line2; } } } catch (IOException e) { e.printStackTrace(); } if ((Integer) (nbDebug[1]) <= 1) { configCrusher.remExtras(); configCrusher.minecraftClosed(password); } return 1; }
From source file:com.mobilecashout.osprey.plugin.plugins.CommonCleanupPlugin.java
@Override public DeploymentAction[] actionFromCommand(String command, DeploymentPlan deploymentPlan, DeploymentContext deploymentContext) { return new DeploymentAction[] { new LocalShellAction(CommandLine.parse("rm -rf .git/ .svn/ .hg/ .gitignore"), logOutputStream) }; }
From source file:io.manasobi.utils.CmdUtils.java
/** * ? ?? ? ? ?/* w w w . j a va 2s. c om*/ * * @param line * @param arguments ? * @return int ? */ public static int execute(String line, String[] arguments) { CommandLine commandLine = CommandLine.parse(line); for (String argument : arguments) { commandLine.addArgument(argument, false); } return execute(commandLine, null); }
From source file:com.rest4j.generator.JavaGeneratorTest.java
@Test public void testJavaClient() throws Exception { gen.setStylesheet("com/rest4j/client/java.xslt"); new File("target/java").mkdir(); gen.setApiXmlUrl(getClass().getResource("doc-generator-graph.xml")); gen.setOutputDir("target/java"); gen.addParam(new TemplateParam("common-params", "access-token")); gen.addParam(new TemplateParam("additional-client-code", "// ADDITIONAL CODE")); gen.generate();/*w w w. j a v a 2 s . c o m*/ // let's try compiling the damn thing CommandLine cmdLine = CommandLine.parse("mvn package"); DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(new File("target/java")); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); int exitValue = executor.execute(cmdLine); assertFalse(executor.isFailure(exitValue)); // check doc comments in the file A.java String a = IOUtils.toString(new File("target/java/src/main/java/api/model/A.java").toURI()); assertTrue(a, a.contains("Some additional client info")); assertFalse(a, a.contains("Some additional python client info")); // check existence of Parameter Object class a = IOUtils.toString(new File("target/java/src/main/java/api/model/PatchBRequest.java").toURI()); assertTrue(a, a.contains("class PatchBRequest")); // check some file paths assertTrue(new File("target/java/src/main/java/api/util/JsonUtil.java").canRead()); assertTrue(new File("target/java/src/main/java/api/Request.java").canRead()); String client = IOUtils.toString(new File("target/java/src/main/java/api/Client.java").toURI()); assertTrue(client.contains("ADDITIONAL CODE")); }
From source file:com.rest4j.generator.PHPGeneratorTest.java
@Test public void testPHPClient() throws Exception { gen.setStylesheet("com/rest4j/client/php.xslt"); new File("target/php").mkdir(); gen.setApiXmlUrl(getClass().getResource("doc-generator-graph.xml")); gen.setOutputDir("target/php"); gen.addParam(new TemplateParam("common-params", "access-token")); gen.addParam(new TemplateParam("prefix", "Test")); gen.addParam(new TemplateParam("additional-client-code", "// ADDITIONAL CODE")); gen.generate();//ww w . ja v a 2 s. co m // check the syntax CommandLine cmdLine = CommandLine.parse("php apiclient.php"); DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(new File("target/php")); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); int exitValue = executor.execute(cmdLine); assertFalse(executor.isFailure(exitValue)); // check existence of Parameter Object class String client = IOUtils.toString(new File("target/php/apiclient.php").toURI()); assertTrue(client, client.contains("class TestPatchBRequest")); assertTrue(client.contains("ADDITIONAL CODE")); }
From source file:com.rest4j.generator.PythonGeneratorTest.java
@Test public void testPythonClient() throws Exception { gen.setStylesheet("com/rest4j/client/python.xslt"); new File("target/python").mkdir(); gen.setApiXmlUrl(getClass().getResource("doc-generator-graph.xml")); gen.setOutputDir("target/python"); gen.addParam(new TemplateParam("common-params", "access-token")); gen.addParam(new TemplateParam("additional-client-code", "\t# ADDITIONAL CODE")); gen.generate();//ww w .ja va 2 s. c o m // let's try compiling the damn thing CommandLine cmdLine = CommandLine.parse("python apiclient.py"); DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(new File("target/python")); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); int exitValue = executor.execute(cmdLine); assertFalse(executor.isFailure(exitValue)); String a = IOUtils.toString(new File("target/python/apiclient.py").toURI()); // check doc comments assertTrue(a, a.contains("Some additional client info")); assertTrue(a, a.contains("Some additional python client info")); // check existence of Parameter Object class assertTrue(a, a.contains("class PatchBRequest")); // check additional-client-code assertTrue(a, a.contains("\t# ADDITIONAL CODE")); }