本文整理汇总了Java中org.codehaus.plexus.util.cli.Commandline.setWorkingDirectory方法的典型用法代码示例。如果您正苦于以下问题:Java Commandline.setWorkingDirectory方法的具体用法?Java Commandline.setWorkingDirectory怎么用?Java Commandline.setWorkingDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.plexus.util.cli.Commandline
的用法示例。
在下文中一共展示了Commandline.setWorkingDirectory方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCommandLine
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
private Commandline getCommandLine() throws ExecutionException {
Commandline commandline = new Commandline(this.phantomJsBinary);
if (configFile != null && configFile.exists()) {
commandline.createArg().setValue("--config=" + configFile.getAbsolutePath());
} else {
commandline.addArguments(this.getCommandLineOptions(commandLineOptions));
}
if (script != null) {
commandline.createArg().setValue(script);
}
if (arguments != null) {
commandline.addArguments(arguments.toArray(new String[arguments.size()]));
}
if (workingDirectory != null) {
commandline.setWorkingDirectory(workingDirectory);
}
return commandline;
}
示例2: createLinkerCommandLine
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
protected Commandline createLinkerCommandLine( List objectFiles, LinkerConfiguration config )
throws NativeBuildException
{
Commandline cl = new Commandline();
cl.setWorkingDirectory( config.getWorkingDirectory().getPath() );
String executable = EXECUTABLE;
if ( config.getExecutable() != null && config.getExecutable().trim().length() != 0 )
{
executable = config.getExecutable();
}
cl.createArg().setValue( executable );
cl.createArg().setValue( "\"" + config.getOutputFile() + "\"" );
for ( int i = 0; i < config.getStartOptions().length; ++i )
{
cl.createArg().setValue( config.getStartOptions()[i] );
}
for ( int i = 0; i < objectFiles.size(); ++i )
{
File objFile = (File) objectFiles.get( i );
cl.createArg().setValue( "+\"" + objFile.getPath() + "\"" );
}
return cl;
}
示例3: run
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
public void run( ManifestConfiguration config )
throws NativeBuildException
{
Commandline cl = new Commandline();
cl.setExecutable( "mt.exe" );
cl.setWorkingDirectory( config.getWorkingDirectory().getPath() );
cl.createArg().setValue( "-manifest" );
int manifestType = 0;
if ( "EXE".equalsIgnoreCase( FileUtils.getExtension( config.getInputFile().getPath() ) ) )
{
manifestType = 1;
}
else if ( "DLL".equalsIgnoreCase( FileUtils.getExtension( config.getInputFile().getPath() ) ) )
{
manifestType = 2;
}
if ( manifestType == 0 )
{
throw new NativeBuildException( "Unknown manifest input file type: " + config.getInputFile() );
}
cl.createArg().setFile( config.getManifestFile() );
cl.createArg().setValue( "-outputresource:" + config.getInputFile() + ";" + manifestType );
EnvUtil.setupCommandlineEnv( cl, config.getEnvFactory() );
CommandLineUtil.execute( cl, this.getLogger() );
}
示例4: _createCommandLine
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
/**
* Creates the command line for the new JVM based on the current
* configuration.
*
* @return The command line used to fork the JVM, never <code>null</code>.
*/
private Commandline _createCommandLine ()
{
/*
* NOTE: This method is designed to work with plexus-utils:1.1 which is used
* by all Maven versions before 2.0.6 regardless of our plugin dependency.
* Therefore, we use setWorkingDirectory(String) rather than
* setWorkingDirectory(File) and addArguments() rather than createArg().
*/
final Commandline cli = new Commandline ();
cli.setExecutable (this.executable);
if (this.workingDirectory != null)
{
cli.setWorkingDirectory (this.workingDirectory.getAbsolutePath ());
}
final String classPath = _getClassPath ();
if (classPath != null && classPath.length () > 0)
{
cli.addArguments (new String [] { "-cp", classPath });
}
if (this.mainClass != null && this.mainClass.length () > 0)
{
cli.addArguments (new String [] { this.mainClass });
}
cli.addArguments (_getArguments ());
return cli;
}
示例5: execute
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
private boolean execute(String command, String... args) throws GitException {
Commandline cl = new Commandline();
cl.setExecutable("git");
cl.createArg().setValue(command);
cl.setWorkingDirectory(workingDirectory.getAbsolutePath());
//args
for (int i = 0; i < args.length; i++){
cl.createArg().setValue(args[i]);
}
if (log.isInfoEnabled()) {
log.info("[" + cl.getWorkingDirectory().getAbsolutePath() + "] Executing: " + cl);
}
int exitCode;
try {
exitCode = CommandLineUtils.executeCommandLine(cl, stdout, stderr);
} catch (CommandLineException e) {
throw new GitException("Error while executing command.", e);
}
if(log.isDebugEnabled()){
log.debug("Run: " + cl + " / $? = " + exitCode);
}
return exitCode == 0;
}
示例6: detectJavaClasspath
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
private boolean detectJavaClasspath( Artifact javaBootClasspathDetector, String javaExecutable )
throws CommandLineException, MojoFailureException
{
final Commandline cli = new Commandline();
cli.setWorkingDirectory( project.getBasedir().getAbsolutePath() );
cli.setExecutable( javaExecutable );
cli.addEnvironment( "CLASSPATH", "" );
cli.addEnvironment( "JAVA_HOME", "" );
cli.addArguments( new String[]{ "-jar", javaBootClasspathDetector.getFile().getAbsolutePath() } );
final CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
final CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
int exitCode = CommandLineUtils.executeCommandLine( cli, stdout, stderr );
if ( exitCode != 0 )
{
getLog().debug( "Stdout: " + stdout.getOutput() );
getLog().debug( "Stderr: " + stderr.getOutput() );
getLog().debug( "Exit code = " + exitCode );
if ( skipIfNoJavaHome )
{
getLog().warn( "Skipping signature generation as could not auto-detect java boot classpath for "
+ javaExecutable );
return false;
}
throw new MojoFailureException( "Could not auto-detect java boot classpath for " + javaExecutable );
}
String[] classpath = StringUtils.split( stdout.getOutput(), File.pathSeparator );
javaHomeClassPath = new File[classpath.length];
for ( int j = 0; j < classpath.length; j++ )
{
javaHomeClassPath[j] = new File( classpath[j] );
}
return true;
}
示例7: executeCommand
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
@Override
public void executeCommand(String executable, List<String> commands, File workingDirectory,
boolean failsOnErrorOutput) throws ExecutionException {
if (commands == null) {
commands = new ArrayList<String>();
}
stdOut = new StreamConsumerImpl(logger, captureStdOut);
stdErr = new ErrorStreamConsumer(logger, errorListener, captureStdErr);
commandline = new Commandline();
if (customShell != null) {
commandline.setShell(customShell);
}
commandline.setExecutable(executable);
// Add the environment variables as needed
if (environment != null) {
for (Map.Entry<String, String> entry : environment.entrySet()) {
commandline.addEnvironment(entry.getKey(), entry.getValue());
}
}
commandline.addArguments(commands.toArray(new String[commands.size()]));
if (workingDirectory != null && workingDirectory.exists()) {
commandline.setWorkingDirectory(workingDirectory.getAbsolutePath());
}
try {
logger.debug("ANDROID-040-000: Executing command: Commandline = " + commandline);
result = CommandLineUtils.executeCommandLine(commandline, stdOut, stdErr);
if (logger != null) {
logger.debug("ANDROID-040-000: Executed command: Commandline = " + commandline + ", Result = "
+ result);
} else {
System.out.println("ANDROID-040-000: Executed command: Commandline = " + commandline
+ ", Result = " + result);
}
if (failsOnErrorOutput && stdErr.hasError() || result != 0) {
throw new ExecutionException("ANDROID-040-001: Could not execute: Command = "
+ commandline.toString() + ", Result = " + result);
}
} catch (CommandLineException e) {
throw new ExecutionException("ANDROID-040-002: Could not execute: Command = "
+ commandline.toString() + ", Error message = " + e.getMessage());
}
setPid(commandline.getPid());
}
示例8: createJavahCommand
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
protected Commandline createJavahCommand( JavahConfiguration config )
throws NativeBuildException
{
this.validateConfiguration( config );
Commandline cl = new Commandline();
if ( config.getWorkingDirectory() != null )
{
cl.setWorkingDirectory( config.getWorkingDirectory().getPath() );
}
cl.setExecutable( this.getJavaHExecutable( config ) );
if ( config.getFileName() != null && config.getFileName().length() > 0 )
{
File outputFile = new File( config.getOutputDirectory(), config.getFileName() );
cl.createArg().setValue( "-o" );
cl.createArg().setFile( outputFile );
}
else
{
if ( config.getOutputDirectory() != null )
{
cl.createArg().setValue( "-d" );
cl.createArg().setFile( config.getOutputDirectory() );
}
}
String[] classPaths = config.getClassPaths();
StringBuffer classPathBuffer = new StringBuffer();
for ( int i = 0; i < classPaths.length; ++i )
{
classPathBuffer.append( classPaths[i] );
if ( i != classPaths.length - 1 )
{
classPathBuffer.append( File.pathSeparatorChar );
}
}
if ( config.getUseEnvClasspath() )
{
cl.addEnvironment( "CLASSPATH", classPathBuffer.toString() );
}
else
{
cl.createArg().setValue( "-classpath" );
cl.createArg().setValue( classPathBuffer.toString() );
}
if ( config.getVerbose() )
{
cl.createArg().setValue( "-verbose" );
}
cl.addArguments( config.getClassNames() );
return cl;
}
示例9: getCommandLine
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
protected Commandline getCommandLine( MessageCompilerConfiguration config, File source )
throws NativeBuildException
{
Commandline cl = new Commandline();
EnvUtil.setupCommandlineEnv( cl, config.getEnvFactory() );
if ( config.getWorkingDirectory() != null )
{
cl.setWorkingDirectory( config.getWorkingDirectory().getPath() );
}
if ( config.getExecutable() == null || config.getExecutable().trim().length() == 0 )
{
config.setExecutable( "mc.exe" );
}
cl.setExecutable( config.getExecutable().trim() );
cl.addArguments( config.getOptions() );
if ( config.getOutputDirectory() != null && config.getOutputDirectory().getPath().trim().length() != 0 )
{
cl.createArg().setValue( "-r" );
cl.createArg().setValue( config.getOutputDirectory().getPath() );
cl.createArg().setValue( "-h" );
cl.createArg().setValue( config.getOutputDirectory().getPath() );
}
if ( config.getDebugOutputDirectory() != null
&& config.getDebugOutputDirectory().getPath().trim().length() != 0 )
{
cl.createArg().setValue( "-x" );
cl.createArg().setValue( config.getDebugOutputDirectory().getPath() );
}
cl.createArg().setValue( source.getPath() );
return cl;
}
示例10: createLinkerCommandLine
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
protected Commandline createLinkerCommandLine( List objectFiles, LinkerConfiguration config )
{
Commandline cl = new Commandline();
cl.setWorkingDirectory( config.getWorkingDirectory().getPath() );
String executable = EXECUTABLE;
if ( !StringUtils.isBlank( config.getExecutable() ) )
{
executable = config.getExecutable();
}
cl.setExecutable( executable );
for ( int i = 0; i < config.getStartOptions().length; ++i )
{
cl.createArg().setValue( config.getStartOptions()[i] );
}
// the next 2 are for completeness, the start options should be good enough
for ( int i = 0; i < config.getMiddleOptions().length; ++i )
{
cl.createArg().setValue( config.getMiddleOptions()[i] );
}
for ( int i = 0; i < config.getEndOptions().length; ++i )
{
cl.createArg().setValue( config.getEndOptions()[i] );
}
cl.createArg().setFile( config.getOutputFile() );
for ( int i = 0; i < objectFiles.size(); ++i )
{
File objFile = (File) objectFiles.get( i );
cl.createArg().setValue( objFile.getPath() );
}
return cl;
}
示例11: executeCommand
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
@Override
public void executeCommand( String executable, List< String > commands, File workingDirectory,
boolean failsOnErrorOutput ) throws ExecutionException
{
if ( commands == null )
{
commands = new ArrayList< String >();
}
stdOut = new StreamConsumerImpl( logger, captureStdOut );
stdErr = new ErrorStreamConsumer( logger, errorListener, captureStdErr );
commandline = new Commandline();
if ( customShell != null )
{
commandline.setShell( customShell );
}
commandline.setExecutable( executable );
// Add the environment variables as needed
if ( environment != null )
{
for ( Map.Entry< String, String > entry : environment.entrySet() )
{
commandline.addEnvironment( entry.getKey(), entry.getValue() );
}
}
commandline.addArguments( commands.toArray( new String[ commands.size() ] ) );
if ( workingDirectory != null && workingDirectory.exists() )
{
commandline.setWorkingDirectory( workingDirectory.getAbsolutePath() );
}
try
{
logger.debug( "ANDROID-040-000: Executing command: Commandline = " + commandline );
result = CommandLineUtils.executeCommandLine( commandline, stdOut, stdErr );
if ( logger != null )
{
logger.debug( "ANDROID-040-000: Executed command: Commandline = " + commandline + ", Result = "
+ result );
}
else
{
System.out.println( "ANDROID-040-000: Executed command: Commandline = " + commandline
+ ", Result = " + result );
}
if ( failsOnErrorOutput && stdErr.hasError() || result != 0 )
{
throw new ExecutionException( "ANDROID-040-001: Could not execute: Command = "
+ commandline.toString() + ", Result = " + result );
}
}
catch ( CommandLineException e )
{
throw new ExecutionException( "ANDROID-040-002: Could not execute: Command = "
+ commandline.toString() + ", Error message = " + e.getMessage() );
}
setPid( commandline.getPid() );
}
示例12: executeReport
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
/**
* @param unusedLocale the wanted locale (actually unused).
* @throws MavenReportException if any
*/
protected void executeReport( Locale unusedLocale )
throws MavenReportException
{
File config = buildConfigurationFile();
Commandline cli = new Commandline();
cli.setWorkingDirectory( getBasedir().getAbsolutePath() );
cli.setExecutable( getExecutablePath() );
cli.createArgument().setValue( config.getAbsolutePath() );
Writer stringWriter = new StringWriter();
StreamConsumer out = new WriterStreamConsumer( stringWriter );
StreamConsumer err = new WriterStreamConsumer( stringWriter );
try
{
int returnCode = CommandLineUtils.executeCommandLine( cli, out, err );
if ( !isQuiet() )
{
// Get all output from doxygen and put it to the log out of Maven.
String[] lines = stringWriter.toString().split( "\n" );
for ( int i = 0; i < lines.length; i++ )
{
lines[i] = lines[i].replaceAll( "\n|\r", "" );
getLog().info( "doxygen: " + lines[i] );
}
}
if ( returnCode != 0 )
{
throw new MavenReportException( "Failed to generate Doxygen documentation." );
}
}
catch ( CommandLineException ex )
{
throw new MavenReportException( "Error while executing Doxygen.", ex );
}
}
示例13: getCommandLine
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
/**
* Setup Compiler Command line
*/
protected Commandline getCommandLine(File srcFile, File destFile, CompilerConfiguration config)
throws NativeBuildException {
if (config.getExecutable() == null) {
config.setExecutable("gcc");
}
Commandline cl = new Commandline();
cl.setExecutable(config.getExecutable());
if (config.getWorkingDirectory() != null) {
cl.setWorkingDirectory(config.getWorkingDirectory().getPath());
}
this.setStartOptions(cl, config);
this.setIncludePaths(cl, config.getIncludePaths());
this.setIncludePaths(cl, config.getSystemIncludePaths());
this.setMiddleOptions(cl, config);
this.setOutputArgs(cl, destFile);
this.setSourceArgs(cl, srcFile);
this.setEndOptions(cl, config);
return cl;
}
示例14: getCommandLine
import org.codehaus.plexus.util.cli.Commandline; //导入方法依赖的package包/类
/**
* Setup Compiler Command line
*/
protected Commandline getCommandLine( File srcFile, File destFile, CompilerConfiguration config )
throws NativeBuildException
{
if ( config.getExecutable() == null )
{
config.setExecutable( "gcc" );
}
Commandline cl = new Commandline();
cl.setExecutable( config.getExecutable() );
if ( config.getWorkingDirectory() != null )
{
cl.setWorkingDirectory( config.getWorkingDirectory().getPath() );
}
this.setStartOptions( cl, config );
this.setIncludePaths( cl, config.getIncludePaths() );
this.setIncludePaths( cl, config.getSystemIncludePaths() );
this.setMiddleOptions( cl, config );
this.setOutputArgs( cl, destFile );
this.setSourceArgs( cl, srcFile );
this.setEndOptions( cl, config );
return cl;
}