当前位置: 首页>>代码示例>>Java>>正文


Java Commandline.addArguments方法代码示例

本文整理汇总了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();
}
 
开发者ID:ferstl,项目名称:depgraph-maven-plugin,代码行数:22,代码来源:DocumentationIntegrationTest.java

示例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;
}
 
开发者ID:klieber,项目名称:phantomjs-maven-plugin,代码行数:21,代码来源:PhantomJsProcessBuilder.java

示例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;
}
 
开发者ID:phax,项目名称:ph-javacc-maven-plugin,代码行数:40,代码来源:ForkedJvm.java

示例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;
}
 
开发者ID:gems-uff,项目名称:oceano,代码行数:35,代码来源:BuildSignaturesMojo.java

示例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());
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:46,代码来源:CommandExecutor.java

示例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;
}
 
开发者ID:mojohaus,项目名称:maven-native,代码行数:63,代码来源:JavahExecutable.java

示例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;
}
 
开发者ID:mojohaus,项目名称:maven-native,代码行数:43,代码来源:MSVCMessageCompiler.java

示例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());
}
 
开发者ID:ferstl,项目名称:depgraph-maven-plugin,代码行数:42,代码来源:AbstractGraphMojo.java

示例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() );
}
 
开发者ID:simpligility,项目名称:android-ndk-maven-plugin,代码行数:59,代码来源:CommandExecutor.java

示例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);
}
 
开发者ID:aleksandr-m,项目名称:gitflow-maven-plugin,代码行数:61,代码来源:AbstractGitFlowMojo.java


注:本文中的org.codehaus.plexus.util.cli.Commandline.addArguments方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。