Package org.codehaus.plexus.util.cli

Examples of org.codehaus.plexus.util.cli.Commandline


    mainParams.add("localeList=" + localeList);
    mainParams.add("internStrings=false");
    mainParams.add("action=release");
    mainParams.add("layerOptimize=" + layerOptimize);
    mainParams.add("profileFile=" + profilePath);
    Commandline commandLine = new Commandline();
    commandLine.setExecutable(javaExec);
    commandLine.setWorkingDirectory(dojoDirectory + "/util/buildscripts");
    List<String> commandArgs = new ArrayList<String>();
    // add the class path
    if (classpathArgs.size() > 0) {
      commandArgs.add("-classpath");
      String classpath = "";
      for (int i = 0; i < classpathArgs.size(); i++) {
        classpath += (i == 0 ? "" : File.pathSeparator);
        classpath += classpathArgs.get(i);
      }
      commandArgs.add(classpath);
    }
    // add the rest...
    commandArgs.add(mainClass);
    commandArgs.add(buildFile);
    for (String param : mainParams) {
      commandArgs.add(param);
    }
    commandLine.addArguments(commandArgs.toArray(new String[commandArgs.size()]));

    try {
      log.info("Executing " + commandLine.toString());
      int resultCode = CommandLineUtils.executeCommandLine(commandLine, new LogStream(), new LogStream());
      if (resultCode > 0) {
        throw new MojoExecutionException("Result of " + commandLine + " execution is: '" + resultCode + "'.");
      }
    } catch (CommandLineException e) {
View Full Code Here


    private static void fixScriptPermissions( File binDirectory )
        throws InterruptedException, CommandLineException
    {
        if ( Os.isFamily( "unix" ) )
        {
            Commandline cli = new Commandline();

            cli.setExecutable( "chmod" );

            cli.createArgument().setValue( "+x" );

            cli.createArgument().setValue( new File( binDirectory, "mvn" ).getAbsolutePath() );

            cli.createArgument().setValue( new File( binDirectory, "m2" ).getAbsolutePath() );

            cli.execute().waitFor();
        }
    }
View Full Code Here

    }

    private void runMaven( File installation, File basedir, String[] args )
        throws Exception, InterruptedException
    {
        Commandline cli = new Commandline();

        cli.setExecutable( new File( installation, "bin/mvn" ).getAbsolutePath() );

        cli.setWorkingDirectory( basedir.getAbsolutePath() );

        cli.createArgument().setValue( "-e" );
        cli.createArgument().setValue( "--batch-mode" );

        if ( offline )
        {
            cli.createArgument().setValue( "-o" );
        }
        if ( updateSnapshots )
        {
            cli.createArgument().setValue( "--update-snapshots" );
        }

        for ( int i = 0; i < args.length; i++ )
        {
            cli.createArgument().setValue( args[i] );
        }

        System.out.println( "Running Maven... " );
        System.out.println( cli.toString() );

        int exitCode = CommandLineUtils.executeCommandLine( cli,
                                                            new WriterStreamConsumer( new PrintWriter( System.out ) ),
                                                            new WriterStreamConsumer( new PrintWriter( System.err ) ) );
View Full Code Here

                // hackhish defaut commandline tools not support ; or && so write a file with the script
                // and "/bin/sh -e " + tmpFile.getPath();
                FileUtils.fileWrite( tmpFile, commandLine );

                Commandline cl = new Commandline();
                cl.setExecutable( "/bin/sh" );
                //cl.createArg().setValue( "-e" );
                //cl.createArg().setValue( tmpFile.getPath() );
                cl.createArg().setFile( tmpFile );

                exitValue = CommandLineUtils.executeCommandLine( cl, stdout, stderr );
                System.out.println( "exit value " + exitValue );
                /*
                if ( exitValue == 0 )
View Full Code Here

        }
        catch ( FileNotFoundException e )
        {
            throw new CommandExecutionException( e.getMessage(), e );
        }
        Commandline cl = createBaseCommandLine( putty, sshExecutable, privateKey );

        int port =
            repository.getPort() == WagonConstants.UNKNOWN_PORT ? ScpHelper.DEFAULT_SSH_PORT : repository.getPort();
        if ( port != ScpHelper.DEFAULT_SSH_PORT )
        {
            if ( putty )
            {
                cl.createArg().setLine( "-P " + port );
            }
            else
            {
                cl.createArg().setLine( "-p " + port );
            }
        }

        if ( sshArgs != null )
        {
            cl.createArg().setLine( sshArgs );
        }

        String remoteHost = this.buildRemoteHost();

        cl.createArg().setValue( remoteHost );

        cl.createArg().setValue( command );

        fireSessionDebug( "Executing command: " + cl.toString() );

        try
        {
            CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
            CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
View Full Code Here

        return sshExecutable.toLowerCase( Locale.ENGLISH ).indexOf( "plink" ) >= 0;
    }

    private Commandline createBaseCommandLine( boolean putty, String executable, File privateKey )
    {
        Commandline cl = new Commandline();

        cl.setExecutable( executable );

        if ( privateKey != null )
        {
            cl.createArg().setValue( "-i" );
            cl.createArg().setFile( privateKey );
        }

        String password = authenticationInfo.getPassword();
        if ( putty && password != null )
        {
            cl.createArg().setValue( "-pw" );
            cl.createArg().setValue( password );
        }

        // should check interactive flag, but scpexe never works in interactive mode right now due to i/o streams
        if ( putty )
        {
            cl.createArg().setValue( "-batch" );
        }
        else
        {
            cl.createArg().setValue( "-o" );
            cl.createArg().setValue( "BatchMode yes" );
        }
        return cl;
    }
View Full Code Here

        {
            fireSessionConnectionRefused();

            throw new AuthorizationException( e.getMessage() );
        }
        Commandline cl = createBaseCommandLine( putty, scpExecutable, privateKey );

        cl.setWorkingDirectory( localFile.getParentFile().getAbsolutePath() );

        int port =
            repository.getPort() == WagonConstants.UNKNOWN_PORT ? ScpHelper.DEFAULT_SSH_PORT : repository.getPort();
        if ( port != ScpHelper.DEFAULT_SSH_PORT )
        {
            cl.createArg().setLine( "-P " + port );
        }

        if ( scpArgs != null )
        {
            cl.createArg().setLine( scpArgs );
        }

        String resourceName = normalizeResource( resource );
        String remoteFile = getRepository().getBasedir() + "/" + resourceName;

        remoteFile = StringUtils.replace( remoteFile, " ", "\\ " );

        String qualifiedRemoteFile = this.buildRemoteHost() + ":" + remoteFile;
        if ( put )
        {
            cl.createArg().setValue( localFile.getName() );
            cl.createArg().setValue( qualifiedRemoteFile );
        }
        else
        {
            cl.createArg().setValue( qualifiedRemoteFile );
            cl.createArg().setValue( localFile.getName() );
        }

        fireSessionDebug( "Executing command: " + cl.toString() );

        try
        {
            CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
            int exitCode = CommandLineUtils.executeCommandLine( cl, null, err );
View Full Code Here

            authInfo.setUserName( "guest" );
            File sshKeysTarget = new File( "target/ssh-keys" );
            FileUtils.copyDirectory( new File( "src/test/ssh-keys" ), sshKeysTarget );
            // ssh keys need to 700 permissions
            // to prevent WARNING: UNPROTECTED PRIVATE KEY FILE!
            Commandline commandline = new Commandline( "chmod" );
            commandline.createArg().setValue( "-R" );
            commandline.createArg().setValue( "700" );
            commandline.createArg().setValue( sshKeysTarget.getCanonicalPath() );
            CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
            CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
            int exitCode = CommandLineUtils.executeCommandLine( commandline, out, err );
            Streams streams = new Streams();
            streams.setOut( out.getOutput() );
View Full Code Here

     *
     * @return The exit status of {@code protoc}.
     * @throws CommandLineException
     */
    public int compile() throws CommandLineException {
        Commandline cl = new Commandline();
        cl.setExecutable(executable);
        cl.addArguments(buildProtocCommand().toArray(new String[]{}));
        return CommandLineUtils.executeCommandLine(cl, null, output, error);
    }
View Full Code Here

    private static void executeLs( File dir, String options, LoggerStreamConsumer loggerConsumer,
                                   StreamConsumer parser, Logger logger )
        throws IOException, CommandLineException
    {
        Commandline numericCli = new Commandline();

        numericCli.getShell().setQuotedArgumentsEnabled( true );
        numericCli.getShell().setQuotedExecutableEnabled( false );

        numericCli.setExecutable( "ls" );

        numericCli.createArg().setLine( options );

        numericCli.createArg().setValue( dir.getAbsolutePath() );

        if ( logger.isDebugEnabled() )
        {
            logger.debug( "Executing:\n\n" + numericCli.toString() + "\n" );
        }

        try
        {
            int result = CommandLineUtils.executeCommandLine( numericCli, parser, loggerConsumer );

            if ( result != 0 )
            {
                throw new IOException( "Failed to retrieve numeric file attributes using: '" + numericCli.toString()
                    + "'" );
            }
        }
        catch ( CommandLineException e )
        {
            IOException error =
                new IOException( "Failed to retrieve numeric file attributes using: '" + numericCli.toString() + "'" );
            error.initCause( e );

            throw error;
        }
    }
View Full Code Here

TOP

Related Classes of org.codehaus.plexus.util.cli.Commandline

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.