本文整理汇总了Java中org.codehaus.plexus.util.cli.Commandline.addArguments方法的典型用法代码示例。如果您正苦于以下问题:Java Commandline.addArguments方法的具体用法?Java Commandline.addArguments怎么用?Java Commandline.addArguments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.plexus.util.cli.Commandline
的用法示例。
在下文中一共展示了Commandline.addArguments方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDotExecutable
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
private static String getDotExecutable() {
Commandline cmd = new Commandline();
String finderExecutable = isWindows() ? "where.exe" : "which";
cmd.setExecutable(finderExecutable);
cmd.addArguments(new String[]{"dot"});
CommandLineUtils.StringStreamConsumer systemOut = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer systemErr = new CommandLineUtils.StringStreamConsumer();
try {
int exitCode = CommandLineUtils.executeCommandLine(cmd, systemOut, systemErr);
if (exitCode != 0) {
return null;
}
} catch (CommandLineException e) {
return null;
}
return systemOut.getOutput();
}
示例2: getCommandLine
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
private Commandline getCommandLine() throws ExecutionException {
Commandline commandline = new Commandline(this.phantomJsBinary);
if (configFile != null && configFile.exists()) {
commandline.createArg().setValue("--config=" + configFile.getAbsolutePath());
} else {
commandline.addArguments(this.getCommandLineOptions(commandLineOptions));
}
if (script != null) {
commandline.createArg().setValue(script);
}
if (arguments != null) {
commandline.addArguments(arguments.toArray(new String[arguments.size()]));
}
if (workingDirectory != null) {
commandline.setWorkingDirectory(workingDirectory);
}
return commandline;
}
示例3: _createCommandLine
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
/**
* Creates the command line for the new JVM based on the current
* configuration.
*
* @return The command line used to fork the JVM, never <code>null</code>.
*/
private Commandline _createCommandLine ()
{
/*
* NOTE: This method is designed to work with plexus-utils:1.1 which is used
* by all Maven versions before 2.0.6 regardless of our plugin dependency.
* Therefore, we use setWorkingDirectory(String) rather than
* setWorkingDirectory(File) and addArguments() rather than createArg().
*/
final Commandline cli = new Commandline ();
cli.setExecutable (this.executable);
if (this.workingDirectory != null)
{
cli.setWorkingDirectory (this.workingDirectory.getAbsolutePath ());
}
final String classPath = _getClassPath ();
if (classPath != null && classPath.length () > 0)
{
cli.addArguments (new String [] { "-cp", classPath });
}
if (this.mainClass != null && this.mainClass.length () > 0)
{
cli.addArguments (new String [] { this.mainClass });
}
cli.addArguments (_getArguments ());
return cli;
}
示例4: detectJavaClasspath
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
private boolean detectJavaClasspath( Artifact javaBootClasspathDetector, String javaExecutable )
throws CommandLineException, MojoFailureException
{
final Commandline cli = new Commandline();
cli.setWorkingDirectory( project.getBasedir().getAbsolutePath() );
cli.setExecutable( javaExecutable );
cli.addEnvironment( "CLASSPATH", "" );
cli.addEnvironment( "JAVA_HOME", "" );
cli.addArguments( new String[]{ "-jar", javaBootClasspathDetector.getFile().getAbsolutePath() } );
final CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
final CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
int exitCode = CommandLineUtils.executeCommandLine( cli, stdout, stderr );
if ( exitCode != 0 )
{
getLog().debug( "Stdout: " + stdout.getOutput() );
getLog().debug( "Stderr: " + stderr.getOutput() );
getLog().debug( "Exit code = " + exitCode );
if ( skipIfNoJavaHome )
{
getLog().warn( "Skipping signature generation as could not auto-detect java boot classpath for "
+ javaExecutable );
return false;
}
throw new MojoFailureException( "Could not auto-detect java boot classpath for " + javaExecutable );
}
String[] classpath = StringUtils.split( stdout.getOutput(), File.pathSeparator );
javaHomeClassPath = new File[classpath.length];
for ( int j = 0; j < classpath.length; j++ )
{
javaHomeClassPath[j] = new File( classpath[j] );
}
return true;
}
示例5: executeCommand
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
@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());
}
示例6: createJavahCommand
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
protected Commandline createJavahCommand( JavahConfiguration config )
throws NativeBuildException
{
this.validateConfiguration( config );
Commandline cl = new Commandline();
if ( config.getWorkingDirectory() != null )
{
cl.setWorkingDirectory( config.getWorkingDirectory().getPath() );
}
cl.setExecutable( this.getJavaHExecutable( config ) );
if ( config.getFileName() != null && config.getFileName().length() > 0 )
{
File outputFile = new File( config.getOutputDirectory(), config.getFileName() );
cl.createArg().setValue( "-o" );
cl.createArg().setFile( outputFile );
}
else
{
if ( config.getOutputDirectory() != null )
{
cl.createArg().setValue( "-d" );
cl.createArg().setFile( config.getOutputDirectory() );
}
}
String[] classPaths = config.getClassPaths();
StringBuffer classPathBuffer = new StringBuffer();
for ( int i = 0; i < classPaths.length; ++i )
{
classPathBuffer.append( classPaths[i] );
if ( i != classPaths.length - 1 )
{
classPathBuffer.append( File.pathSeparatorChar );
}
}
if ( config.getUseEnvClasspath() )
{
cl.addEnvironment( "CLASSPATH", classPathBuffer.toString() );
}
else
{
cl.createArg().setValue( "-classpath" );
cl.createArg().setValue( classPathBuffer.toString() );
}
if ( config.getVerbose() )
{
cl.createArg().setValue( "-verbose" );
}
cl.addArguments( config.getClassNames() );
return cl;
}
示例7: getCommandLine
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
protected Commandline getCommandLine( MessageCompilerConfiguration config, File source )
throws NativeBuildException
{
Commandline cl = new Commandline();
EnvUtil.setupCommandlineEnv( cl, config.getEnvFactory() );
if ( config.getWorkingDirectory() != null )
{
cl.setWorkingDirectory( config.getWorkingDirectory().getPath() );
}
if ( config.getExecutable() == null || config.getExecutable().trim().length() == 0 )
{
config.setExecutable( "mc.exe" );
}
cl.setExecutable( config.getExecutable().trim() );
cl.addArguments( config.getOptions() );
if ( config.getOutputDirectory() != null && config.getOutputDirectory().getPath().trim().length() != 0 )
{
cl.createArg().setValue( "-r" );
cl.createArg().setValue( config.getOutputDirectory().getPath() );
cl.createArg().setValue( "-h" );
cl.createArg().setValue( config.getOutputDirectory().getPath() );
}
if ( config.getDebugOutputDirectory() != null
&& config.getDebugOutputDirectory().getPath().trim().length() != 0 )
{
cl.createArg().setValue( "-x" );
cl.createArg().setValue( config.getDebugOutputDirectory().getPath() );
}
cl.createArg().setValue( source.getPath() );
return cl;
}
示例8: createDotGraphImage
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
private void createDotGraphImage(Path graphFilePath) throws IOException {
String graphFileName = createDotImageFileName(graphFilePath);
Path graphFile = graphFilePath.resolveSibling(graphFileName);
String dotExecutable = determineDotExecutable();
String[] arguments = new String[]{
"-T", this.imageFormat,
"-o", graphFile.toAbsolutePath().toString(),
graphFilePath.toAbsolutePath().toString()};
Commandline cmd = new Commandline();
cmd.setExecutable(dotExecutable);
cmd.addArguments(arguments);
getLog().info("Running Graphviz: " + dotExecutable + " " + Joiner.on(" ").join(arguments));
StringStreamConsumer systemOut = new StringStreamConsumer();
StringStreamConsumer systemErr = new StringStreamConsumer();
int exitCode;
try {
exitCode = CommandLineUtils.executeCommandLine(cmd, systemOut, systemErr);
} catch (CommandLineException e) {
throw new IOException("Unable to execute Graphviz", e);
}
Splitter lineSplitter = Splitter.on(LINE_SEPARATOR_PATTERN).omitEmptyStrings().trimResults();
Iterable<String> output = Iterables.concat(
lineSplitter.split(systemOut.getOutput()),
lineSplitter.split(systemErr.getOutput()));
for (String line : output) {
getLog().info(" dot> " + line);
}
if (exitCode != 0) {
throw new IOException("Graphviz terminated abnormally. Exit code: " + exitCode);
}
getLog().info("Graph image created on " + graphFile.toAbsolutePath());
}
示例9: executeCommand
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
@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() );
}
示例10: executeCommand
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
/**
* Executes command line.
*
* @param cmd
* Command line.
* @param failOnError
* Whether to throw exception on NOT success exit code.
* @param argStr
* Command line arguments as a string.
* @param args
* Command line arguments.
* @return {@link CommandResult} instance holding command exit code, output
* and error if any.
* @throws CommandLineException
* @throws MojoFailureException
* If <code>failOnError</code> is <code>true</code> and command
* exit code is NOT equals to 0.
*/
private CommandResult executeCommand(final Commandline cmd,
final boolean failOnError, final String argStr,
final String... args) throws CommandLineException,
MojoFailureException {
// initialize executables
initExecutables();
if (getLog().isDebugEnabled()) {
getLog().debug(
cmd.getExecutable() + " " + StringUtils.join(args, " ")
+ (argStr == null ? "" : " " + argStr));
}
cmd.clearArgs();
cmd.addArguments(args);
if (StringUtils.isNotBlank(argStr)) {
cmd.createArg().setLine(argStr);
}
final StringBufferStreamConsumer out = new StringBufferStreamConsumer(
verbose);
final CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
// execute
final int exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
String errorStr = err.getOutput();
String outStr = out.getOutput();
if (failOnError && exitCode != SUCCESS_EXIT_CODE) {
// not all commands print errors to error stream
if (StringUtils.isBlank(errorStr) && StringUtils.isNotBlank(outStr)) {
errorStr = outStr;
}
throw new MojoFailureException(errorStr);
}
return new CommandResult(exitCode, outStr, errorStr);
}