Java Code Examples for org.codehaus.plexus.util.cli.Commandline#toString()
The following examples show how to use
org.codehaus.plexus.util.cli.Commandline#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MavenCommandLineMojo.java From dependency-mediator with Apache License 2.0 | 5 votes |
public void copyDependenciesTest(File dependencyFolder) throws MojoFailureException, MojoExecutionException { getLog().info("Start to copy dependencies"); Commandline cl = new Commandline(); cl.setExecutable("mvn"); cl.createArg().setValue("clean"); cl.createArg().setValue("dependency:copy-dependencies"); cl.createArg().setValue("-DoutputDirectory=" + dependencyFolder.getAbsolutePath()); cl.createArg().setValue("-Dsilent=true"); String excludedArtifactIds = this.getTestDependencyArtifactIds(); if (!excludedArtifactIds.isEmpty()) { cl.createArg().setValue("-DexcludeArtifactIds=" + excludedArtifactIds); getLog().info("====Excluded artifact ids: " + excludedArtifactIds); } else { getLog().info("====No excluded artifact ids"); } WriterStreamConsumer systemOut = new WriterStreamConsumer( new OutputStreamWriter(System.out)); int result = -1; try { result = CommandLineUtils.executeCommandLine(cl, systemOut, systemOut); } catch (CommandLineException e) { String message = "Failed to execute command: " + cl.toString(); throw new MojoFailureException(message); } if (result != 0) { getLog().error("Failed to copy dependencies"); System.exit(result); } }
Example 2
Source File: CommandExecutor.java From atlas with Apache License 2.0 | 4 votes |
@Override public void executeCommand(String executable, List<String> commands, File workingDirectory, boolean failsOnErrorOutput) throws ExecutionException { if (commands == null) { commands = new ArrayList<String>(); } stdOut = new StreamConsumerImpl(logger, captureStdOut); stdErr = new ErrorStreamConsumer(logger, errorListener, captureStdErr); commandline = new Commandline(); if (customShell != null) { commandline.setShell(customShell); } commandline.setExecutable(executable); // Add the environment variables as needed if (environment != null) { for (Map.Entry<String, String> entry : environment.entrySet()) { commandline.addEnvironment(entry.getKey(), entry.getValue()); } } commandline.addArguments(commands.toArray(new String[commands.size()])); if (workingDirectory != null && workingDirectory.exists()) { commandline.setWorkingDirectory(workingDirectory.getAbsolutePath()); } try { logger.debug("ANDROID-040-000: Executing command: Commandline = " + commandline); result = CommandLineUtils.executeCommandLine(commandline, stdOut, stdErr); if (logger != null) { logger.debug("ANDROID-040-000: Executed command: Commandline = " + commandline + ", Result = " + result); } else { System.out.println("ANDROID-040-000: Executed command: Commandline = " + commandline + ", Result = " + result); } if (failsOnErrorOutput && stdErr.hasError() || result != 0) { throw new ExecutionException("ANDROID-040-001: Could not execute: Command = " + commandline.toString() + ", Result = " + result); } } catch (CommandLineException e) { throw new ExecutionException("ANDROID-040-002: Could not execute: Command = " + commandline.toString() + ", Error message = " + e.getMessage()); } setPid(commandline.getPid()); }