Package org.codehaus.plexus.util.cli

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


     * @throws CompilerException
     */
    List compileOutOfProcess( CompilerConfiguration config, String executable, String[] args )
        throws CompilerException
    {
        Commandline cli = new Commandline();

        cli.setWorkingDirectory( config.getWorkingDirectory().getAbsolutePath() );

        cli.setExecutable( executable );

        try
        {
            File argumentsFile = createFileWithArguments( args, config.getOutputLocation() );
            cli.addArguments( new String[] { "@" + argumentsFile.getCanonicalPath().replace( File.separatorChar, '/' ) } );

            if ( !StringUtils.isEmpty( config.getMaxmem() ) )
            {
                cli.addArguments( new String[] { "-J-Xmx" + config.getMaxmem() } );
            }

            if ( !StringUtils.isEmpty( config.getMeminitial() ) )
            {
                cli.addArguments( new String[] { "-J-Xms" + config.getMeminitial() } );
            }
        }
        catch ( IOException e )
        {
            throw new CompilerException( "Error creating file with javac arguments", e );
        }

        CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();

        CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();

        int returnCode;

        List messages;

        if ( ( getLogger() != null ) && getLogger().isDebugEnabled() )
        {
            File commandLineFile =
                new File( config.getOutputLocation(), "javac." + ( Os.isFamily( Os.FAMILY_WINDOWS ) ? "bat" : "sh" ) );
            try
            {
                FileUtils.fileWrite( commandLineFile.getAbsolutePath(),
                                     cli.toString().replaceAll( "'", "" ) );

                if ( !Os.isFamily( Os.FAMILY_WINDOWS ) )
                {
                    Runtime.getRuntime().exec( new String[] { "chmod", "a+x", commandLineFile.getAbsolutePath() } );
                }
            }
            catch ( IOException e )
            {
                if ( ( getLogger() != null ) && getLogger().isWarnEnabled() )
                {
                    getLogger().warn( "Unable to write '" + commandLineFile.getName() + "' debug script file", e );
                }
            }
        }

        try
        {
            returnCode = CommandLineUtils.executeCommandLine( cli, out, err );

            messages = parseModernStream( new BufferedReader( new StringReader( err.getOutput() ) ) );
        }
        catch ( CommandLineException e )
        {
            throw new CompilerException( "Error while executing the external compiler.", e );
        }
        catch ( IOException e )
        {
            throw new CompilerException( "Error while executing the external compiler.", e );
        }

        if ( ( returnCode != 0 ) && messages.isEmpty() )
        {
            if ( err.getOutput().length() == 0 )
            {
                throw new CompilerException( "Unknown error trying to execute the external compiler: " + EOL
                    + cli.toString() );
            }
            else
            {
                messages.add( new CompilerError( "Failure executing javac,  but could not parse the error:" + EOL
                    + err.getOutput(), true ) );
View Full Code Here


     * @throws CompilerException
     */
    List compileOutOfProcess( CompilerConfiguration config, String executable, String[] args )
        throws CompilerException
    {
        Commandline cli = new Commandline();

        cli.setWorkingDirectory( config.getWorkingDirectory().getAbsolutePath() );

        cli.setExecutable( executable );

        try
        {
            File argumentsFile = createFileWithArguments( args, config.getOutputLocation() );
            cli.addArguments( new String[] { "@" + argumentsFile.getCanonicalPath().replace( File.separatorChar, '/' ) } );

            if ( !StringUtils.isEmpty( config.getMaxmem() ) )
            {
                cli.addArguments( new String[] { "-J-Xmx" + config.getMaxmem() } );
            }

            if ( !StringUtils.isEmpty( config.getMeminitial() ) )
            {
                cli.addArguments( new String[] { "-J-Xms" + config.getMeminitial() } );
            }
        }
        catch ( IOException e )
        {
            throw new CompilerException( "Error creating file with javac arguments", e );
        }

        CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();

        CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();

        int returnCode;

        List messages;

        if ( ( getLogger() != null ) && getLogger().isDebugEnabled() )
        {
            File commandLineFile =
                new File( config.getOutputLocation(), "javac." + ( Os.isFamily( Os.FAMILY_WINDOWS ) ? "bat" : "sh" ) );
            try
            {
                FileUtils.fileWrite( commandLineFile.getAbsolutePath(),
                                     cli.toString().replaceAll( "'", "" ) );

                if ( !Os.isFamily( Os.FAMILY_WINDOWS ) )
                {
                    Runtime.getRuntime().exec( new String[] { "chmod", "a+x", commandLineFile.getAbsolutePath() } );
                }
            }
            catch ( IOException e )
            {
                if ( ( getLogger() != null ) && getLogger().isWarnEnabled() )
                {
                    getLogger().warn( "Unable to write '" + commandLineFile.getName() + "' debug script file", e );
                }
            }
        }

        try
        {
            returnCode = CommandLineUtils.executeCommandLine( cli, out, err );

            messages = parseModernStream( returnCode, new BufferedReader( new StringReader( err.getOutput() ) ) );
        }
        catch ( CommandLineException e )
        {
            throw new CompilerException( "Error while executing the external compiler.", e );
        }
        catch ( IOException e )
        {
            throw new CompilerException( "Error while executing the external compiler.", e );
        }

        if ( ( returnCode != 0 ) && messages.isEmpty() )
        {
            if ( err.getOutput().length() == 0 )
            {
                throw new CompilerException( "Unknown error trying to execute the external compiler: " + EOL
                    + cli.toString() );
            }
            else
            {
                messages.add( new CompilerError( "Failure executing javac,  but could not parse the error:" + EOL
                    + err.getOutput(), true ) );
View Full Code Here

                throw new MojoExecutionException(e.getMessage(), e);
            }
        } else {
            getLog().info("Running java2ws in fork mode...");

            Commandline cmd = new Commandline();
            cmd.getShell().setQuotedArgumentsEnabled(false); // for JVM args
            cmd.setWorkingDirectory(project.getBuild().getDirectory());
            try {
                cmd.setExecutable(getJavaExecutable().getAbsolutePath());
            } catch (IOException e) {
                getLog().debug(e);
                throw new MojoExecutionException(e.getMessage(), e);
            }

            cmd.addArguments(args.toArray(new String[args.size()]));

            CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
            CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();

            int exitCode;
            try {
                exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
            } catch (CommandLineException e) {
                getLog().debug(e);
                throw new MojoExecutionException(e.getMessage(), e);
            }

            String output = StringUtils.isEmpty(out.getOutput()) ? null : '\n' + out.getOutput().trim();

            String cmdLine = CommandLineUtils.toString(cmd.getCommandline());

            if (exitCode != 0) {
                if (StringUtils.isNotEmpty(output)) {
                    getLog().info(output);
                }
View Full Code Here

        // ----------------------------------------------------------------------
        // Execute!
        // ----------------------------------------------------------------------

        Commandline cli = new Commandline();

        cli.setWorkingDirectory( workingDirectory.getAbsolutePath() );

        cli.setExecutable( executable );

        cli.createArgument().setValue( "@" + file.getAbsolutePath() );

        Writer stringWriter = new StringWriter();

        StreamConsumer out = new WriterStreamConsumer( stringWriter );
View Full Code Here

  private Thread setupCommandLine(final int monitorPort,
      final String monitorKey, final List<String> args) {
    final String javaExe = System.getProperty("java.home") + File.separator
      + "bin" + File.separator + "java";
    final Commandline commandline = new Commandline(StringUtils.quoteAndEscape(javaExe, '"'));
    final String classPath =
      System.getProperty("java.class.path") + File.pathSeparator + pluginPath;
    commandline.createArg().setValue("-ea");
    commandline.createArg().setValue("-cp");
    commandline.createArg().setValue(classPath);
    commandline.createArg().setValue("-Dmonitor.port=" + monitorPort);
    commandline.createArg().setValue("-Dmonitor.key=" + monitorKey);
    commandline.createArg().setValue("-Dappengine.sdk.root=" + System.getProperty("appengine.sdk.root"));
    commandline.createArg().setValue(AppEnginePluginMonitor.class.getName());
    commandline.addArguments(args.toArray(new String[args.size()]));

    final StreamConsumer outConsumer = new StreamConsumer() {
      public void consumeLine(final String line) {
        consumeOutputLine(line);
      }
    };

    final StreamConsumer errConsumer = new StreamConsumer() {
      public void consumeLine(final String line) {
        consumeErrorLine(line);
      }
    };

    if (log.isDebugEnabled()) {
      log.debug("Forking executable: " + commandline.getExecutable());
      log.debug("Command line: " + commandline.toString());
    }

    return new Thread(new Runnable() {
      public void run() {
        try {
View Full Code Here

        throws ScmException
    {
        PerforceScmProviderRepository prepo = (PerforceScmProviderRepository) repo;
        actualLocation = PerforceScmProvider.getRepoPath( getLogger(), prepo, files.getBasedir() );
        PerforceStatusConsumer consumer = new PerforceStatusConsumer();
        Commandline command = readOpened( prepo, files, consumer );

        if ( consumer.isSuccess() )
        {
            List<ScmFile> scmfiles = createResults( actualLocation, consumer );
            return new StatusScmResult( command.toString(), scmfiles );
        }

        return new StatusScmResult( command.toString(), "Unable to get status", consumer
                .getOutput(), consumer.isSuccess() );
    }
View Full Code Here

    /** {@inheritDoc} */
    protected ScmResult executeAddCommand( ScmProviderRepository repo, ScmFileSet files, String message,
                                           boolean binary )
        throws ScmException
    {
        Commandline cl = createCommandLine( (PerforceScmProviderRepository) repo, files.getBasedir(), files );
        PerforceAddConsumer consumer = new PerforceAddConsumer();
        try
        {
            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 );
            }
        }

        return new AddScmResult( cl.toString(), consumer.getAdditions() );
    }
View Full Code Here

    }

    private Commandline readOpened( PerforceScmProviderRepository prepo, ScmFileSet files,
                                    PerforceStatusConsumer consumer )
    {
        Commandline cl = createOpenedCommandLine( prepo, files.getBasedir(), actualLocation );
        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 );
View Full Code Here

    }

    public static Commandline createCommandLine( PerforceScmProviderRepository repo, File workingDirectory,
                                                 ScmFileSet files )
    {
        Commandline command = PerforceScmProvider.createP4Command( repo, workingDirectory );
        command.createArg().setValue( "add" );

        for ( File file : files.getFileList() )
        {
            command.createArg().setValue( file.getName() );
        }
        return command;
    }
View Full Code Here

        throws Exception
    {
        ScmRepository repository = getScmManager().makeScmRepository( scmUrl );
        PerforceScmProviderRepository svnRepository =
            (PerforceScmProviderRepository) repository.getProviderRepository();
        Commandline cl = PerforceEditCommand.createCommandLine( svnRepository, workingDir, files );

        assertCommandLine( commandLine, null, cl );
    }
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.