Package org.codehaus.plexus.util.cli

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


            log.warn("Parameter <executable/> was not set in the pom.xml.  Skipping conversion.");
            return null;
        }

        String generatedFileName = removeFileExtension(file.getAbsolutePath()) + "." + format;
        Commandline cl = new Commandline();
        cl.setExecutable(executable);
        cl.createArgument().setValue("-T" + format);
        cl.createArgument().setValue("-o");
        cl.createArgument().setValue(generatedFileName);
        cl.createArgument().setValue(file.getAbsolutePath());

        log.debug("executing: " + cl.toString());

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

        int exitCode = CommandLineUtils.executeCommandLine(cl, stdout, stderr);
View Full Code Here


{
    /** {@inheritDoc} */
    protected ScmResult executeEditCommand( ScmProviderRepository repo, ScmFileSet files )
        throws ScmException
    {
        Commandline cl = createCommandLine( (PerforceScmProviderRepository) repo, files.getBasedir(), files );
        PerforceEditConsumer consumer = new PerforceEditConsumer();
        try
        {
            if ( getLogger().isDebugEnabled() )
            {
                getLogger().debug( PerforceScmProvider.clean( "Executing " + cl.toString() ) );
            }

            CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
            int exitCode = CommandLineUtils.executeCommandLine( cl, consumer, err );

            if ( exitCode != 0 )
            {
                String cmdLine = CommandLineUtils.toString( cl.getCommandline() );

                StringBuilder msg = new StringBuilder( "Exit code: " + exitCode + " - " + err.getOutput() );
                msg.append( '\n' );
                msg.append( "Command line was:" + cmdLine );

                throw new CommandLineException( msg.toString() );
            }
        }
        catch ( CommandLineException e )
        {
            if ( getLogger().isErrorEnabled() )
            {
                getLogger().error( "CommandLineException " + e.getMessage(), e );
            }
        }

        if ( consumer.isSuccess() )
        {
            return new EditScmResult( cl.toString(), consumer.getEdits() );
        }

        return new EditScmResult( cl.toString(), "Unable to edit file(s)", consumer.getErrorMessage(), false );
    }
View Full Code Here

        throws ScmException
    {
        try
        {
            //Build commandline
            Commandline cmd = buildCmd( workingDir, cmdAndArgs );
            if ( logger.isInfoEnabled() )
            {
                logger.info( "EXECUTING: " + cmd );
            }

            //Execute command
            int exitCode = executeCmd( consumer, cmd );

            //Return result
            List<Integer> exitCodes = DEFAULT_EXIT_CODES;
            if ( EXIT_CODE_MAP.containsKey( cmdAndArgs[0] ) )
            {
                exitCodes = EXIT_CODE_MAP.get( cmdAndArgs[0] );
            }
            boolean success = exitCodes.contains( Integer.valueOf( exitCode ) );

            //On failure (and not due to exceptions) - run diagnostics
            String providerMsg = "Execution of hg command succeded";
            if ( !success )
            {
                HgConfig config = new HgConfig( workingDir );
                providerMsg =
                    "\nEXECUTION FAILED" + "\n  Execution of cmd : " + cmdAndArgs[0] + " failed with exit code: " +
                        exitCode + "." + "\n  Working directory was: " + "\n    " + workingDir.getAbsolutePath() +
                        config.toString( workingDir ) + "\n";
                if ( logger.isErrorEnabled() )
                {
                    logger.error( providerMsg );
                }
            }

            return new ScmResult( cmd.toString(), providerMsg, consumer.getStdErr(), success );
        }
        catch ( ScmException se )
        {
            String msg =
                "EXECUTION FAILED" + "\n  Execution failed before invoking the Hg command. Last exception:" + "\n    " +
View Full Code Here

    }

    static Commandline buildCmd( File workingDir, String[] cmdAndArgs )
        throws ScmException
    {
        Commandline cmd = new Commandline();
        cmd.setExecutable( HgCommandConstants.EXEC );
        cmd.addArguments( cmdAndArgs );
        if ( workingDir != null )
        {
            cmd.setWorkingDirectory( workingDir.getAbsolutePath() );

            if ( !workingDir.exists() )
            {
                boolean success = workingDir.mkdirs();
                if ( !success )
View Full Code Here

        }
        LoggerStreamConsumer loggerConsumer = new LoggerStreamConsumer( logger, logLevel );

        AttributeParser.NumericUserIDAttributeParser numericIdParser = null;
        FutureTask<Integer> integerFutureTask = null;
        Commandline numericCli = null;
        if ( includeNumericUserId )
        {
            numericIdParser = new AttributeParser.NumericUserIDAttributeParser( loggerConsumer, logger );

            String lsOptions1 = "-1nla" + ( recursive ? "R" : "d" );
            try
            {
                numericCli = setupCommandLine( dir, lsOptions1, logger );

                CommandLineCallable commandLineCallable =
                    CommandLineUtils.executeCommandLineAsCallable( numericCli, null, numericIdParser, loggerConsumer,
                                                                   0 );

                integerFutureTask = new FutureTask<Integer>( commandLineCallable );
                new Thread( integerFutureTask ).start();
            }
            catch ( CommandLineException e )
            {
                IOException error = new IOException( "Failed to quote directory: '" + dir + "'" );
                error.initCause( e );
                throw error;
            }
        }

        AttributeParser.SymbolicUserIDAttributeParser userId =
            getNameBasedParser( dir, logger, recursive, loggerConsumer );

        if ( includeNumericUserId )
        {
            final Integer result;
            try
            {
                result = integerFutureTask.get();
            }
            catch ( InterruptedException e )
            {
                throw new RuntimeException( e );
            }
            catch ( ExecutionException e )
            {
                throw new RuntimeException( e );
            }

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

        return userId.merge( numericIdParser );
    }
View Full Code Here

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

        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

        }
    }

    private static Commandline setupCommandLine( File dir, String options, Logger logger )
    {
        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" );
        }
        return numericCli;
    }
View Full Code Here

            return;
        }

        try
        {
            final Commandline commandline = new Commandline();

            commandline.setWorkingDirectory( file.getParentFile().getAbsolutePath() );

            if ( logger.isDebugEnabled() )
            {
                logger.debug( file + ": mode " + Integer.toOctalString( mode ) + ", chmod " + m );
            }

            commandline.setExecutable( "chmod" );

            commandline.createArg().setValue( m );

            final String path = file.getAbsolutePath();

            commandline.createArg().setValue( path );

            // commenting this debug statement, since it can produce VERY verbose output...
            // this method is called often during archive creation.
            // logger.debug( "Executing:\n\n" + commandline.toString() + "\n\n" );
View Full Code Here

    protected Map<String, ClassDescription> runJavadoc() throws MavenReportException
    {
        getLog().info("Running JavaDoc to collect component parameter data ...");

        Commandline command = new Commandline();

        try
        {
            command.setExecutable(pathToJavadoc());
        }
        catch (IOException ex)
        {
            throw new MavenReportException("Unable to locate javadoc command: " + ex.getMessage(), ex);
        }

        String parametersPath = workDirectory + File.separator + "component-parameters.xml";

        String[] arguments = {"-private", "-o", parametersPath,

                "-subpackages", rootPackage,

                "-doclet", ParametersDoclet.class.getName(),

                "-docletpath", docletPath(),

                "-sourcepath", sourcePath(),

                "-classpath", classPath()};

        String argumentsFile = writeArgumentsFile(arguments);

        command.addArguments(new String[] {"@" + argumentsFile});

        executeCommand(command);

        return readXML(parametersPath);
    }
View Full Code Here

     * @throws CommandLineException
     */
    private List<String> getJavaHomeInformations( String javaHome )
        throws CommandLineException
    {
        Commandline commandline = new Commandline();

        String executable = javaHome + File.separator + "bin" + File.separator + "java";

        commandline.setExecutable( executable );
        commandline.addArguments( new String[]{"-version"} );
        final List<String> cliOutput = new ArrayList<String>();
        //TODO ShellCommandHelper ?
        int result = CommandLineUtils.executeCommandLine( commandline, new StreamConsumer()
        {
            public void consumeLine( String line )
View Full Code Here

TOP

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

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.