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


Java CommandLineUtils.executeCommandLine方法代码示例

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


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

示例1: execute

import org.codehaus.plexus.util.cli.CommandLineUtils; //导入方法依赖的package包/类
public static void execute( Commandline cl, Logger logger )
    throws NativeBuildException
{
    int ok;

    try
    {
        DefaultConsumer stdout = new DefaultConsumer();

        DefaultConsumer stderr = stdout;

        logger.info( cl.toString() );

        ok = CommandLineUtils.executeCommandLine( cl, stdout, stderr );
    }
    catch ( CommandLineException ecx )
    {
        throw new NativeBuildException( "Error executing command line", ecx );
    }

    if ( ok != 0 )
    {
        throw new NativeBuildException( "Error executing command line. Exit code:" + ok );
    }
}
 
开发者ID:mojohaus,项目名称:maven-native,代码行数:26,代码来源:CommandLineUtil.java

示例2: execute

import org.codehaus.plexus.util.cli.CommandLineUtils; //导入方法依赖的package包/类
private void execute(Commandline jDepsCommand) throws CommandLineException {
	StringStreamConsumer errorConsoleConsumer = new StringStreamConsumer();

	MojoLogging.logger().debug(format("Running JDeps: %s", jDepsCommand));
	MojoLogging.logger().debug(String.format(
			"(JDeps output is forwarded here. "
					+ "Lines are marked: %s = recognized as dependency; %s = not recognized.)",
			ViolationParser.MESSAGE_MARKER_JDEPS_LINE,
			ViolationParser.MESSAGE_MARKER_UNKNOWN_LINE));

	int exitCode = CommandLineUtils.executeCommandLine(
			jDepsCommand, jDepsOutputConsumer::accept, errorConsoleConsumer);

	MojoLogging.logger().debug(format("JDeps completed with exit code %d.", exitCode));

	if (exitCode != 0)
		throwCommandLineException(jDepsCommand, exitCode, errorConsoleConsumer.getOutput());
}
 
开发者ID:CodeFX-org,项目名称:JDeps-Maven-Plugin,代码行数:19,代码来源:JdkInternalsExecutor.java

示例3: isSvn18

import org.codehaus.plexus.util.cli.CommandLineUtils; //导入方法依赖的package包/类
private static boolean isSvn18()
{
    Commandline cl = new Commandline();
    cl.setExecutable( "svn" );

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

    try
    {
        CommandLineUtils.executeCommandLine( cl, stdout, stderr );
        return stdout.getOutput().contains( "svn, version 1.8." );
    }
    catch ( CommandLineException e )
    {
    }

    return false;
}
 
开发者ID:mojohaus,项目名称:buildnumber-maven-plugin,代码行数:20,代码来源:BuildNumberMojoTest.java

示例4: 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

示例5: execute

import org.codehaus.plexus.util.cli.CommandLineUtils; //导入方法依赖的package包/类
private void execute(Commandline jDepsCommand) throws CommandLineException {
	StringStreamConsumer errorConsoleConsumer = new StringStreamConsumer();
	int exitCode = CommandLineUtils.executeCommandLine(
			jDepsCommand, jDepsOutputConsumer::accept, errorConsoleConsumer);
	if (exitCode != 0)
		throwCommandLineException(jDepsCommand, exitCode, errorConsoleConsumer.getOutput());
}
 
开发者ID:CodeFX-org,项目名称:jdeps-wall-of-shame,代码行数:8,代码来源:JdkInternalsExecutor.java

示例6: 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

示例7: 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

示例8: executeCommandLine

import org.codehaus.plexus.util.cli.CommandLineUtils; //导入方法依赖的package包/类
private int executeCommandLine(Commandline cli, InvocationRequest request)
        throws CommandLineException {
    int result = Integer.MIN_VALUE;


    InputStream inputStream = request.getInputStream(this.inputStream);
    InvocationOutputHandler outputHandler = request.getOutputHandler(this.outputHandler);
    InvocationOutputHandler errorHandler = request.getErrorHandler(this.errorHandler);

    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Executing: " + cli);
    }
    if (request.isInteractive()) {
        if (inputStream == null) {
            getLogger().warn(
                    "Maven will be executed in interactive mode"
                            + ", but no input stream has been configured for this MavenInvoker instance.");

            result = CommandLineUtils.executeCommandLine(cli, outputHandler, errorHandler);
        } else {
            result = CommandLineUtils.executeCommandLine(cli, inputStream, outputHandler, errorHandler, timeOut);
        }
    } else {
        if (inputStream != null) {
            getLogger().info("Executing in batch mode. The configured input stream will be ignored.");
        }

        result = CommandLineUtils.executeCommandLine(cli, outputHandler, errorHandler, timeOut);
    }

    return result;
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:33,代码来源:MavenInvoker.java

示例9: 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

示例10: copyDependenciesTest

import org.codehaus.plexus.util.cli.CommandLineUtils; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:vongosling,项目名称:dependency-mediator,代码行数:31,代码来源:MavenCommandLineMojo.java

示例11: execute

import org.codehaus.plexus.util.cli.CommandLineUtils; //导入方法依赖的package包/类
private boolean execute(String command, String... args) throws GitException {
	Commandline cl = new Commandline();
	cl.setExecutable("git");
	cl.createArg().setValue(command);
	cl.setWorkingDirectory(workingDirectory.getAbsolutePath());
	
	//args
	for (int i = 0; i < args.length; i++){
		cl.createArg().setValue(args[i]);
	}
	
	if (log.isInfoEnabled()) {
		log.info("[" + cl.getWorkingDirectory().getAbsolutePath() + "] Executing: " + cl);
	}
	
	int exitCode;
	try {
		exitCode = CommandLineUtils.executeCommandLine(cl, stdout, stderr);
	} catch (CommandLineException e) {
		throw new GitException("Error while executing command.", e);
	}

	if(log.isDebugEnabled()){
		log.debug("Run: " + cl + " / $? = " + exitCode);
	}
	
	return exitCode == 0;
}
 
开发者ID:opoo,项目名称:opoopress,代码行数:29,代码来源:Git.java

示例12: 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

示例13: 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

示例14: executeCommand

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

示例15: createEnvs

import org.codehaus.plexus.util.cli.CommandLineUtils; //导入方法依赖的package包/类
protected Map createEnvs( String commonToolEnvKey, String platform )
    throws NativeBuildException
{

    File tmpEnvExecFile = null;
    try
    {
        File vsCommonToolDir = this.getCommonToolDirectory( commonToolEnvKey );

        File vsInstallDir = this.getVisualStudioInstallDirectory( vsCommonToolDir );

        if ( !vsInstallDir.isDirectory() )
        {
            throw new NativeBuildException( vsInstallDir.getPath() + " is not a directory." );
        }

        tmpEnvExecFile = this.createEnvWrapperFile( vsInstallDir, platform );

        Commandline cl = new Commandline();
        cl.setExecutable( tmpEnvExecFile.getAbsolutePath() );

        EnvStreamConsumer stdout = new EnvStreamConsumer();
        StreamConsumer stderr = new DefaultConsumer();

        CommandLineUtils.executeCommandLine( cl, stdout, stderr );

        return stdout.getParsedEnv();
    }
    catch ( Exception e )
    {
        throw new NativeBuildException( "Unable to retrieve env", e );
    }
    finally
    {
        if ( tmpEnvExecFile != null )
        {
            tmpEnvExecFile.delete();
        }
    }

}
 
开发者ID:mojohaus,项目名称:maven-native,代码行数:42,代码来源:AbstractMSVCEnvFactory.java


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