List of usage examples for org.apache.commons.exec Executor getWorkingDirectory
File getWorkingDirectory();
From source file:org.apache.maven.plugin.cxx.VeraxxMojo.java
@Override protected void preExecute(Executor exec, CommandLine commandLine, Properties enviro) throws MojoExecutionException { OutputStream outStream = /*System.out;*/new ByteArrayOutputStream(); OutputStream errStream = new ByteArrayOutputStream(); CommandLine commandLineCheck = new CommandLine(getExecutable()); Executor execCheck = new DefaultExecutor(); String[] args = parseCommandlineArgs("--version"); commandLineCheck.addArguments(args, false); execCheck.setWorkingDirectory(exec.getWorkingDirectory()); getLog().info("Executing command line: " + commandLineCheck); int res = 0;//from ww w . j a v a 2 s . co m try { res = ExecutorService.executeCommandLine(execCheck, commandLineCheck, enviro, outStream/*getOutputStreamOut()*/, errStream/*getOutputStreamErr()*/, getInputStream()); } catch (ExecuteException e) { getLog().info("Exec Exception while detecting Vera++ version." + " Assume old Vera++ v1.1.x (and less) output parsing style"); getLog().info("Vera++ err output is : " + errStream.toString()); veraxxVersion = 0; /*throw new MojoExecutionException( "preExecute Command execution failed.", e );*/ return; } catch (IOException e) { getLog().info("Vera++ detected version is : " + outStream.toString()); getLog().info("Vera++ err output is : " + errStream.toString()); // due to jdk8 bug :: https://bugs.openjdk.java.net/browse/JDK-8054565 // we use this dirty try/catch ... // because this quick command line call can close the output stream before jvm does getLog().info("jvm " + System.getProperty("java.version") + " (8u11 - 9) workaround, ignoring a " + e.toString() + " during vera++ test command line."); //throw new MojoExecutionException( "preExecute Command execution failed.", e ); } if (isResultCodeAFailure(res)) { getLog().info("Vera++ returned a failure result code : " + res); //throw new MojoExecutionException( "preExecute Result of " + commandLineCheck // + " execution is: '" + res + "'." ); } DefaultArtifactVersion newFormatMinVersion = new DefaultArtifactVersion("1.2.0"); DefaultArtifactVersion currentVeraVersion = new DefaultArtifactVersion(outStream.toString()); getLog().debug("Vera++ detected version is : " + outStream.toString()); getLog().debug("Vera++ version as ArtefactVersion is : " + currentVeraVersion.toString()); if (currentVeraVersion.compareTo(newFormatMinVersion) < 0) { getLog().info("Use old Vera++ v1.1.x (and less) output parsing style"); veraxxVersion = 0; } else { getLog().info("Use Vera++ v1.2.0 (and more) output parsing style"); veraxxVersion = 1; } }
From source file:org.apache.stratos.python.cartridge.agent.test.PythonCartridgeAgentTest.java
/** * TearDown method for test method testPythonCartridgeAgent *//*from w w w.java 2 s . c o m*/ @After public void tearDown() { for (Map.Entry<String, Executor> entry : executorList.entrySet()) { try { String commandText = entry.getKey(); Executor executor = entry.getValue(); ExecuteWatchdog watchdog = executor.getWatchdog(); if (watchdog != null) { log.info("Terminating process: " + commandText); watchdog.destroyProcess(); } File workingDirectory = executor.getWorkingDirectory(); if (workingDirectory != null) { log.info("Cleaning working directory: " + workingDirectory.getAbsolutePath()); FileUtils.deleteDirectory(workingDirectory); } } catch (Exception ignore) { } } for (ServerSocket serverSocket : serverSocketList) { try { log.info("Stopping socket server: " + serverSocket.getLocalSocketAddress()); serverSocket.close(); } catch (IOException ignore) { } } try { log.info("Deleting source checkout folder..."); FileUtils.deleteDirectory(new File(SOURCE_PATH)); } catch (Exception ignore) { } this.instanceStatusEventReceiver.terminate(); this.topologyEventReceiver.terminate(); this.instanceActivated = false; this.instanceStarted = false; }
From source file:org.codehaus.mojo.VeraxxMojo.java
protected void preExecute(Executor exec, CommandLine commandLine, Map enviro) throws MojoExecutionException { OutputStream outStream = /*System.out;*/new ByteArrayOutputStream(); OutputStream errStream = new ByteArrayOutputStream(); CommandLine commandLineCheck = new CommandLine(getExecutable()); Executor execCheck = new DefaultExecutor(); String[] args = parseCommandlineArgs("--version"); commandLineCheck.addArguments(args, false); execCheck.setWorkingDirectory(exec.getWorkingDirectory()); getLog().info("Executing command line: " + commandLineCheck); int res = 0;//w w w . ja va 2 s.com try { res = executeCommandLine(execCheck, commandLineCheck, enviro, outStream/*getOutputStreamOut()*/, errStream/*getOutputStreamErr()*/, getInputStream()); } catch (ExecuteException e) { getLog().info( "Exec Exception while detecting Vera++ version. Assume old Vera++ v1.1.x (and less) output parsing style"); getLog().info("Vera++ err output is : " + errStream.toString()); veraxx_version = 0; /*throw new MojoExecutionException( "preExecute Command execution failed.", e );*/ return; } catch (IOException e) { getLog().info("Vera++ detected version is : " + outStream.toString()); getLog().info("Vera++ err output is : " + errStream.toString()); // due to jdk8 bug :: https://bugs.openjdk.java.net/browse/JDK-8054565 // we use this dirty try/catch ... // because this quick command line call can close the output stream before jvm does getLog().info("jvm " + System.getProperty("java.version") + " (8u11 - 9) workaround, ignoring a " + e.toString() + " during vera++ test command line."); //throw new MojoExecutionException( "preExecute Command execution failed.", e ); } if (isResultCodeAFailure(res)) { getLog().info("Vera++ returned a failure result code : " + res); //throw new MojoExecutionException( "preExecute Result of " + commandLineCheck + " execution is: '" + res + "'." ); } DefaultArtifactVersion newFormatMinVersion = new DefaultArtifactVersion("1.2.0"); DefaultArtifactVersion currentVeraVersion = new DefaultArtifactVersion(outStream.toString()); getLog().debug("Vera++ detected version is : " + outStream.toString()); getLog().debug("Vera++ version as ArtefactVersion is : " + currentVeraVersion.toString()); if (currentVeraVersion.compareTo(newFormatMinVersion) < 0) { getLog().info("Use old Vera++ v1.1.x (and less) output parsing style"); veraxx_version = 0; } else { getLog().info("Use Vera++ v1.2.0 (and more) output parsing style"); veraxx_version = 1; } }