本文整理了Java中org.codehaus.plexus.util.cli.Commandline
类的一些代码示例,展示了Commandline
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Commandline
类的具体详情如下:
包路径:org.codehaus.plexus.util.cli.Commandline
类名称:Commandline
[英]Commandline objects help handling command lines specifying processes to execute.
The class can be used to define a command line as nested elements or as a helper to define a command line by an application.
The element someelement
must provide a method createAcommandline
which returns an instance of this class.
[中]命令行对象有助于处理指定要执行的进程的命令行。
该类可用于将命令行定义为嵌套元素,也可用于帮助应用程序定义命令行。
元素someelement
必须提供返回此类实例的方法createAcommandline
。
代码示例来源:origin: simpligility/android-maven-plugin
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() );
代码示例来源:origin: org.codehaus.plexus/plexus-utils
Creates an argument object. Each commandline object has at most one instance of the argument class. This method calls/**
*
*
*
* this.createArgument(false)
.
*
* @return the argument object.
* @see #createArgument(boolean)
*/
public Arg createArg()
{
return this.createArg( false );
}
代码示例来源:origin: org.codehaus.plexus/plexus-utils
public Object clone()
{
Commandline c = new Commandline( (Shell) shell.clone() );
c.executable = executable;
c.workingDir = workingDir;
c.addArguments( getArguments() );
return c;
}
代码示例来源:origin: org.codehaus.plexus/plexus-utils
/**
* 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
createArgument().setValue( tmp[i] );
}
}
}
代码示例来源:origin: org.codehaus.plexus/plexus-utils
/**
* 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
createArgument().setValue( tmp[i] );
}
}
}
代码示例来源:origin: org.apache.maven.scm/maven-scm-provider-tfs
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;
}
}
代码示例来源:origin: apache/maven-scm
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;
}
代码示例来源:origin: org.apache.maven.scm/maven-scm-provider-clearcase
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
for ( File file : files )
{
if ( logger.isInfoEnabled() )
{
logger.info( "edit file: " + file.getAbsolutePath() );
}
command.createArg().setValue( file.getAbsolutePath() );
}
return command;
}
代码示例来源:origin: org.apache.maven.scm/maven-scm-provider-integrity
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() );
代码示例来源:origin: org.apache.maven.scm/maven-scm-provider-cvs
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() );
代码示例来源:origin: org.apache.maven.scm/maven-scm-provider-git-commons
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;
}
代码示例来源:origin: org.apache.maven.scm/maven-scm-provider-cvs-commons
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;
}
代码示例来源:origin: simpligility/android-maven-plugin
Commandline cli = new Commandline();
cli.setWorkingDirectory( workingDirectory.getAbsolutePath() );
cli.setExecutable( executable );
cli.addArguments( args );
returnCode = CommandLineUtils.executeCommandLine( cli, out, err );
代码示例来源:origin: jenkinsci/scm-sync-configuration-plugin
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;
}
代码示例来源:origin: org.apache.maven.scm/maven-scm-provider-starteam
/** {@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() );
}
代码示例来源:origin: org.apache.maven.scm/maven-scm-provider-cvs
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() );
}
代码示例来源:origin: org.kuali.common/kuali-core
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
cl.addEnvironment(pair.getKey(), pair.getValue());
}
return cl;
}
代码示例来源:origin: apache/maven-scm
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;
}
代码示例来源:origin: org.apache.maven.scm/maven-scm-provider-cvs-commons
/** {@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 );
}
代码示例来源:origin: org.kuali.common/kuali-util
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;
}