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


Java CommandLineUtils.StringStreamConsumer方法代码示例

本文整理汇总了Java中org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer方法的典型用法代码示例。如果您正苦于以下问题:Java CommandLineUtils.StringStreamConsumer方法的具体用法?Java CommandLineUtils.StringStreamConsumer怎么用?Java CommandLineUtils.StringStreamConsumer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.plexus.util.cli.CommandLineUtils的用法示例。


在下文中一共展示了CommandLineUtils.StringStreamConsumer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDotExecutable

import org.codehaus.plexus.util.cli.CommandLineUtils; //导入方法依赖的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: getValue

import org.codehaus.plexus.util.cli.CommandLineUtils; //导入方法依赖的package包/类
public static String getValue( String valueType, String folderName, String folderKey )
    throws NativeBuildException
{
    Commandline cl = new Commandline();
    cl.setExecutable( "reg" );
    cl.createArg().setValue( "query" );
    cl.createArg().setValue( folderName );
    cl.createArg().setValue( "/v" );
    cl.createArg().setValue( folderKey );

    CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();

    try
    {
        int ok = CommandLineUtils.executeCommandLine( cl, stdout, stderr );

        if ( ok != 0 )
        {
            return null;
        }
    }
    catch ( CommandLineException e )
    {
        throw new NativeBuildException( e.getMessage(), e );
    }

    String result = stdout.getOutput();

    int p = result.indexOf( valueType );

    if ( p == -1 )
    {
        return null;
    }

    return result.substring( p + valueType.length() ).trim();
}
 
开发者ID:mojohaus,项目名称:maven-native,代码行数:39,代码来源:RegQuery.java

示例3: getScmUrl

import org.codehaus.plexus.util.cli.CommandLineUtils; //导入方法依赖的package包/类
public static String getScmUrl( File repositoryRootFile )
    throws CommandLineException
{
    String repositoryRoot = repositoryRootFile.getAbsolutePath();

    // TODO: it'd be great to build this into CommandLineUtils somehow
    // TODO: some way without a custom cygwin sys property?
    if ( "true".equals( System.getProperty( "cygwin" ) ) )
    {
        Commandline cl = new Commandline();

        cl.setExecutable( "cygpath" );

        cl.createArg().setValue( "--unix" );

        cl.createArg().setValue( repositoryRoot );

        CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
        
        int exitValue = CommandLineUtils.executeCommandLine( cl, stdout, null );

        if ( exitValue != 0 )
        {
            throw new CommandLineException( "Unable to convert cygwin path, exit code = " + exitValue );
        }

        repositoryRoot = stdout.getOutput().trim();
    }
    else if ( Os.isFamily( "windows" ) )
    {
        repositoryRoot = "/" + StringUtils.replace( repositoryRoot, "\\", "/" );
    }

    return "scm:javasvn:file://" + repositoryRoot;
}
 
开发者ID:olamy,项目名称:maven-scm-provider-svnjava,代码行数:36,代码来源:SvnJavaScmTestUtils.java

示例4: executeCommandLine

import org.codehaus.plexus.util.cli.CommandLineUtils; //导入方法依赖的package包/类
/**
 * @inheritDoc
 */
public void executeCommandLine(final Commandline cl, final Log log, final boolean failOnError)
        throws MojoExecutionException, MojoFailureException {
    CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();

    log.debug("command line: " + Arrays.toString(cl.getCommandline()));

    // Executing the command
    final int exitCode;
    try {
        exitCode = CommandLineUtils.executeCommandLine(cl, out, out);
    } catch (CommandLineException e) {
        throw new MojoExecutionException("Unable to execute the Checker Framework, executable: " + pathToExecutable +
                ", command line: " + Arrays.toString(cl.getCommandline()), e);
    }

    final String javacOutput = out.getOutput();

    // Sanity check - if the exit code is non-zero, there should be some messages
    if (exitCode != 0 && javacOutput.isEmpty()) {
        throw new MojoExecutionException("Exit code from the compiler was not zero (" + exitCode +
                "), but no output was reported");
    }

    if (exitCode == 0) {
        log.info(javacOutput);
    } else {
        if (failOnError) {
            log.error(javacOutput);
            throw new MojoFailureException(null, "Errors found by the Checker(s)", javacOutput);
        } else {
            log.warn("Errors found by the Checker(s)");
            log.warn(javacOutput);
        }
    }
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:39,代码来源:JavacIOExecutor.java

示例5: detectJavaClasspath

import org.codehaus.plexus.util.cli.CommandLineUtils; //导入方法依赖的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

示例6: executeCommandLine

import org.codehaus.plexus.util.cli.CommandLineUtils; //导入方法依赖的package包/类
/**
 * Method to execute a command line.
 * @param cl CommandLine
 * @throws CommandLineException Thrown if an error occurs invoking the command line
 * @throws MojoExecutionException Thrown if the command line executes but with error return code
 */
protected void executeCommandLine(Commandline cl)
throws CommandLineException, MojoExecutionException
{
    CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    getLog().debug("Executing command line:");
    getLog().debug(cl.toString());
    int exitCode = CommandLineUtils.executeCommandLine(cl, stdout, stderr);

    getLog().debug("Exit code: " + exitCode);
    getLog().debug("--------------------");
    getLog().debug(" Standard output from the DataNucleus tool " + getToolName() + " :");
    getLog().debug("--------------------");
    getLog().info(stdout.getOutput());
    getLog().debug("--------------------");
    String stream = stderr.getOutput();
    if (stream.trim().length() > 0)
    {
        getLog().error("--------------------");
        getLog().error(" Standard error from the DataNucleus tool + " + getToolName() + " :");
        getLog().error("--------------------");
        getLog().error(stderr.getOutput());
        getLog().error("--------------------");
    }

    if (exitCode != 0)
    {
        throw new MojoExecutionException("The DataNucleus tool " + getToolName() + " exited with a non-null exit code.");
    }
}
 
开发者ID:datanucleus,项目名称:datanucleus-maven-plugin,代码行数:37,代码来源:AbstractDataNucleusMojo.java

示例7: executeCommand

import org.codehaus.plexus.util.cli.CommandLineUtils; //导入方法依赖的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.CommandLineUtils.StringStreamConsumer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。