commandline = new Commandline(); if ( customShell != null ) commandline.setShell( customShell ); commandline.setExecutable( executable ); commandline.addEnvironment( entry.getKey(), entry.getValue() ); commandline.addArguments( commands.toArray( new String[ commands.size() ] ) ); if ( workingDirectory != null && workingDirectory.exists() ) commandline.setWorkingDirectory( workingDirectory.getAbsolutePath() ); result = CommandLineUtils.executeCommandLine( commandline, stdOut, stdErr ); if ( logger != null ) + commandline.toString() + ", Result = " + result ); + commandline.toString() + ", Error message = " + e.getMessage() ); setPid( commandline.getPid() );
/** * <p>Creates an argument object.</p> * * <p>Each commandline object has at most one instance of the argument class. This method calls * <code>this.createArgument(false)</code>.</p> * * @return the argument object. * @see #createArgument(boolean) */ public Arg createArg() { return this.createArg( false ); }
public Object clone() { Commandline c = new Commandline( (Shell) shell.clone() ); c.executable = executable; c.workingDir = workingDir; c.addArguments( getArguments() ); return c; }
/** * Create a new command line object, given a command following POSIX sh quoting rules * * @param toProcess */ public Commandline( String toProcess ) { setDefaultShell(); String[] tmp = new String[0]; try { tmp = CommandLineUtils.translateCommandline( toProcess ); } catch ( Exception e ) { System.err.println( "Error translating Commandline." ); } if ( ( tmp != null ) && ( tmp.length > 0 ) ) { setExecutable( tmp[0] ); for ( int i = 1; i < tmp.length; i++ ) { createArgument().setValue( tmp[i] ); } } }
/** * Create a new command line object. Shell is autodetected from operating system Shell usage is only desirable when * generating code for remote execution. * * @param toProcess */ public Commandline( String toProcess, Shell shell ) { this.shell = shell; String[] tmp = new String[0]; try { tmp = CommandLineUtils.translateCommandline( toProcess ); } catch ( Exception e ) { System.err.println( "Error translating Commandline." ); } if ( ( tmp != null ) && ( tmp.length > 0 ) ) { setExecutable( tmp[0] ); for ( int i = 1; i < tmp.length; i++ ) { createArgument().setValue( tmp[i] ); } } }
public static Commandline createCommandLine( File workingDirectory, String filename ) { Commandline command = new Commandline(); command.setWorkingDirectory( workingDirectory ); command.setExecutable( "tfpt" ); command.createArg().setValue( "annotate" ); command.createArg().setValue( "/noprompt" ); command.createArg().setValue( filename ); return command; } }
public Commandline buildCmdLine( VssScmProviderRepository repo, ScmFileSet fileSet, String tagName, String message ) throws ScmException { Commandline command = new Commandline(); command.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() ); try { command.addSystemEnvironment(); } catch ( Exception e ) { throw new ScmException( "Can't add system environment.", e ); } command.addEnvironment( "SSDIR", repo.getVssdir() ); String ssDir = VssCommandLineUtils.getSsDir(); command.setExecutable( ssDir + VssConstants.SS_EXE ); command.createArg().setValue( VssConstants.COMMAND_LABEL ); command.createArg().setValue( VssConstants.PROJECT_PREFIX + repo.getProject() ); // User identification to get access to vss repository if ( repo.getUserPassword() != null ) { command.createArg().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() ); } // Ignore: Do not ask for input under any circumstances. command.createArg().setValue( VssConstants.FLAG_AUTORESPONSE_DEF ); command.createArg().setValue( VssConstants.FLAG_LABEL + tagName ); return command; }
public static Commandline createCommandLine( ScmLogger logger, ScmFileSet scmFileSet ) { Commandline command = new Commandline(); File workingDirectory = scmFileSet.getBasedir(); command.setWorkingDirectory( workingDirectory.getAbsolutePath() ); command.setExecutable( "cleartool" ); command.createArg().setValue( "co" ); command.createArg().setValue( "-nc" ); List<File> files = scmFileSet.getFileList(); for ( File file : files ) { if ( logger.isInfoEnabled() ) { logger.info( "edit file: " + file.getAbsolutePath() ); } command.createArg().setValue( file.getAbsolutePath() ); } return command; }
throws ScmException Commandline shell = new Commandline(); shell.setWorkingDirectory( workingDirectory.getBasedir() ); shell.setExecutable( "si" ); shell.createArg().setValue( "connect" ); shell.createArg().setValue( "--hostname=" + iRepo.getHost() ); shell.createArg().setValue( "--port=" + iRepo.getPort() ); shell.createArg().setValue( "--user=" + iRepo.getUser() ); shell.createArg().setValue( "--batch" ); shell.createArg().setValue( "--password=" + iRepo.getPassword() ); CommandLineUtils.StringStreamConsumer shellConsumer = new CommandLineUtils.StringStreamConsumer(); getLogger().debug( "Executing: " + CommandLineUtils.toString( shell.getCommandline() ) ); int exitCode = CommandLineUtils.executeCommandLine( shell, shellConsumer, shellConsumer ); if ( exitCode != 0 ) throw new ScmException( "Can't login to integrity. Message : " + shellConsumer.toString() ); getLogger().error( "Command Line Connect Exception: " + cle.getMessage() ); throw new ScmException( "Can't login to integrity. Message : " + cle.getMessage() );
Commandline cl = new Commandline(); cl.setExecutable( "cvs" ); cl.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() ); cl.createArgument().setValue( "-f" ); // don't use ~/.cvsrc cl.createArgument().setValue( "-q" ); cl.createArgument().setValue( "update" ); cl.createArgument().setValue( "-d" ); cl.createArgument().setValue( "-r" + tag ); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); getLogger().info( "Executing: " + cl ); getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() ); exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr ); throw new ScmException( "Error while executing command.", ex ); return new UpdateScmResult( cl.toString(), "The cvs command failed.", stderr.getOutput(), false ); return new UpdateScmResult( cl.toString(), consumer.getUpdatedFiles() );
public static Commandline getBaseCommand( String commandName, GitScmProviderRepository repo, ScmFileSet fileSet, String options ) { Settings settings = GitUtil.getSettings(); Commandline cl = new Commandline(); cl.setExecutable( settings.getGitCommand() ); cl.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() ); if ( settings.getTraceGitCommand() != null ) { cl.addEnvironment( "GIT_TRACE", settings.getTraceGitCommand() ); } cl.createArg().setLine( options ); cl.createArg().setValue( commandName ); return cl; }
public static boolean isCvsNT() throws ScmException { Commandline cl = new Commandline(); cl.setExecutable( "cvs" ); cl.createArg().setValue( "-v" ); CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer(); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); try { CommandLineUtils.executeCommandLine( cl, stdout, stderr ); } catch ( CommandLineException e ) { throw new ScmException( "Error while executing command.", e ); } return stdout.getOutput().indexOf( "CVSNT" ) >= 0; }
Commandline cli = new Commandline(); cli.setWorkingDirectory( workingDirectory.getAbsolutePath() ); cli.setExecutable( executable ); cli.addArguments( args ); returnCode = CommandLineUtils.executeCommandLine( cli, out, err );
public static Commandline createSpecificPushCommandLine(ScmLogger logger, GitScmProviderRepository repository, ScmFileSet fileSet, ScmVersion version) throws ScmException { Commandline cl = GitCommandLineUtils.getBaseGitCommandLine(fileSet.getBasedir(), "push"); String branch = GitBranchCommand.getCurrentBranch(logger, repository, fileSet); if (branch == null || branch.length() == 0) { throw new ScmException("Could not detect the current branch. Don't know where I should push to!"); } // Overloaded branch name here : if repository.getUrl() is kept, during checkin(), current *local* branch // reference is not updated, whereas by using origin, it will be done ! cl.createArg().setValue("origin"); cl.createArg().setValue(branch + ":" + branch); return cl; }
/** {@inheritDoc} */ protected StatusScmResult executeStatusCommand( ScmProviderRepository repo, ScmFileSet fileSet ) throws ScmException { if ( getLogger().isInfoEnabled() ) { getLogger().info( "Working directory: " + fileSet.getBasedir().getAbsolutePath() ); } if ( fileSet.getFileList().size() != 0 ) { throw new ScmException( "This provider doesn't support checking status of a subsets of a directory" ); } StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo; StarteamStatusConsumer consumer = new StarteamStatusConsumer( getLogger(), fileSet.getBasedir() ); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); Commandline cl = createCommandLine( repository, fileSet ); int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); if ( exitCode != 0 ) { return new StatusScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(), false ); } return new StatusScmResult( cl.toString(), consumer.getChangedFiles() ); }
protected StatusScmResult executeStatusCommand( ScmProviderRepository repo, ScmFileSet fileSet ) throws ScmException { Commandline cl = createCommandLine( fileSet ); CvsStatusConsumer consumer = new CvsStatusConsumer( getLogger(), fileSet.getBasedir() ); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); getLogger().info( "Executing: " + cl ); getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() ); int exitCode; getLogger().debug( "Working directory: " + fileSet.getBasedir().getAbsolutePath() ); getLogger().debug( "Command line: " + cl ); try { exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr ); } catch ( CommandLineException ex ) { throw new ScmException( "Error while executing command.", ex ); } if ( exitCode != 0 ) { return new StatusScmResult( cl.toString(), "The cvs command failed.", stderr.getOutput(), false ); } return new StatusScmResult( cl.toString(), consumer.getChangedFiles() ); }
private Commandline getCommandLine(ExecRequest request) { Commandline cl = new Commandline(); if (request.getShell().isPresent()) { cl.getShell().setShellCommand(request.getShell().get()); } cl.setExecutable(request.getExecutable()); cl.addArguments(request.getArgs().toArray(EMPTY_STRING_ARRAY)); if (request.getWorkingDirectory().isPresent()) { cl.setWorkingDirectory(request.getWorkingDirectory().get()); } addSystemEnvironmentVariables(cl, request.isAddSystemEnvironmentVariables()); // Explicit environment variables "win" over system environment variables for (Map.Entry<String, String> pair : request.getEnvironmentVariables().entrySet()) { cl.addEnvironment(pair.getKey(), pair.getValue()); } return cl; }
private static Commandline buildPythonCmd( File workingDir, String[] cmdAndArgs ) throws ScmException { Commandline cmd = new Commandline(); cmd.setExecutable( PYTHON_EXEC ); cmd.setWorkingDirectory( workingDir.getAbsolutePath() ); cmd.addArguments( cmdAndArgs ); if ( !workingDir.exists() ) { boolean success = workingDir.mkdirs(); if ( !success ) { String msg = "Working directory did not exist" + " and it couldn't be created: " + workingDir; throw new ScmException( msg ); } } return cmd; }
/** {@inheritDoc} */ protected StatusScmResult executeStatusCommand( ScmProviderRepository repo, ScmFileSet fileSet ) throws ScmException { CvsScmProviderRepository repository = (CvsScmProviderRepository) repo; Commandline cl = CvsCommandUtils.getBaseCommand( "update", repository, fileSet, "-n" ); cl.createArg().setValue( "-d" ); if ( getLogger().isInfoEnabled() ) { getLogger().info( "Executing: " + cl ); getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() ); } return executeCvsCommand( cl ); }
protected Commandline getCommandLine(ExecContext context) { Commandline cl = new Commandline(); cl.setExecutable(context.getExecutable()); if (context.isAddSystemEnvironment()) { try { cl.addSystemEnvironment(); } catch (Exception e) { throw new IllegalStateException(e); } } if (context.getArgs() != null) { cl.addArguments(CollectionUtils.toStringArray(context.getArgs())); } if (context.getWorkingDirectory() != null) { cl.setWorkingDirectory(context.getWorkingDirectory()); } return cl; }