You are viewing a plain text version of this content. The canonical link for it is here.
Posted to npanday-commits@incubator.apache.org by lc...@apache.org on 2011/12/21 12:05:21 UTC
svn commit: r1221688 - in
/incubator/npanday/trunk/components/dotnet-executable/src:
main/java/npanday/executable/ main/java/npanday/executable/execution/
test/java/npanday/executable/ test/java/npanday/executable/execution/
Author: lcorneliussen
Date: Wed Dec 21 12:05:20 2011
New Revision: 1221688
URL: http://svn.apache.org/viewvc?rev=1221688&view=rev
Log:
NPANDAY-509: CommandExecutor is confused with MSDeploy-style commandline switches starting with "-" and containing both ":" and "="
o no-op: factored multiple anonymous implementations in separate classes for easier refactoring
Added:
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/CustomCommandline.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/DefaultCommandExecutor.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/ErrorStreamConsumer.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/StandardStreamConsumer.java
incubator/npanday/trunk/components/dotnet-executable/src/test/java/npanday/executable/execution/
incubator/npanday/trunk/components/dotnet-executable/src/test/java/npanday/executable/execution/CommandExecutorTest.java (contents, props changed)
- copied, changed from r1221137, incubator/npanday/trunk/components/dotnet-executable/src/test/java/npanday/executable/CommandExecutorTest.java
Removed:
incubator/npanday/trunk/components/dotnet-executable/src/test/java/npanday/executable/CommandExecutorTest.java
Modified:
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/CommandExecutor.java
Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/CommandExecutor.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/CommandExecutor.java?rev=1221688&r1=1221687&r2=1221688&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/CommandExecutor.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/CommandExecutor.java Wed Dec 21 12:05:20 2011
@@ -18,23 +18,11 @@
*/
package npanday.executable;
-import npanday.PathUtil;
+import npanday.executable.execution.DefaultCommandExecutor;
import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.util.cli.CommandLineException;
-import org.codehaus.plexus.util.cli.CommandLineUtils;
-import org.codehaus.plexus.util.cli.Commandline;
-import org.codehaus.plexus.util.cli.DefaultConsumer;
-import org.codehaus.plexus.util.cli.StreamConsumer;
import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
-import java.util.Properties;
/**
@@ -132,379 +120,9 @@ public interface CommandExecutor
*/
public static CommandExecutor createDefaultCommmandExecutor()
{
- return new CommandExecutor()
- {
- /**
- * Instance of a plugin logger.
- */
- private Logger logger;
-
- /**
- * Standard Out
- */
- private StreamConsumer stdOut;
-
- /**
- * Standard Error
- */
- private ErrorStreamConsumer stdErr;
-
- /**
- * Process result
- */
- private int result;
-
- public void setLogger( Logger logger )
- {
- this.logger = logger;
- }
-
-
- public void executeCommand( String executable, List<String> commands )
- throws ExecutionException
- {
- executeCommand( executable, commands, null, true );
- }
-
- public void executeCommand( String executable, List<String> commands, boolean failsOnErrorOutput )
- throws ExecutionException
- {
- executeCommand( executable, commands, null, failsOnErrorOutput );
- }
-
- public void executeCommand( String executable, List<String> commands, File workingDirectory,
- boolean failsOnErrorOutput )
- throws ExecutionException
- {
- if ( commands == null )
- {
- commands = new ArrayList<String>();
- }
- stdOut = new StreamConsumerImpl();
- stdErr = new ErrorStreamConsumer();
-
- Commandline commandline = new Commandline()
- {
- protected Map envVars = Collections.synchronizedMap( new LinkedHashMap() );
-
-
- public Process execute()
- throws CommandLineException
- {
- // TODO: Provided only for backward compat. with <= 1.4
- //verifyShellState();
-
- Process process;
-
- //addEnvironment( "MAVEN_TEST_ENVAR", "MAVEN_TEST_ENVAR_VALUE" );
-
- String[] environment = getEnvironmentVariables();
-
- File workingDir = getWorkingDirectory();
-
- try
- {
- String[] cmd = getEscapedShellCommandline();
-
- if ( workingDir == null )
- {
- process = Runtime.getRuntime().exec( cmd, environment );
- }
- else
- {
- if ( !workingDir.exists() )
- {
- throw new CommandLineException(
- "NPANDAY-040-010: Working directory \"" + workingDir.getPath()
- + "\" does not exist!" );
- }
- else if ( !workingDir.isDirectory() )
- {
- throw new CommandLineException(
- "NPANDAY-040-009: Path \"" + workingDir.getPath()
- + "\" does not specify a directory." );
- }
-
- process = Runtime.getRuntime().exec( cmd, environment, workingDir );
- }
- }
- catch ( IOException ex )
- {
- throw new CommandLineException( "NPANDAY-040-008: Error while executing process.", ex );
- }
-
- return process;
- }
-
- public String[] getEnvironmentVariables()
- throws CommandLineException
- {
- try
- {
- addSystemEnvironment();
- }
- catch ( Exception e )
- {
- throw new CommandLineException(
- "NPANDAY-040-007: Error setting up environmental variables", e );
- }
- String[] environmentVars = new String[envVars.size()];
- int i = 0;
- for ( Iterator iterator = envVars.keySet().iterator(); iterator.hasNext(); )
- {
- String name = (String) iterator.next();
- String value = (String) envVars.get( name );
- environmentVars[i] = name + "=" + value;
- i++;
- }
- return environmentVars;
- }
-
- public void addEnvironment( String name, String value )
- {
- //envVars.add( name + "=" + value );
- envVars.put( name, value );
- }
-
- /**
- * Add system environment variables
- */
- public void addSystemEnvironment()
- throws Exception
- {
- Properties systemEnvVars = CommandLineUtils.getSystemEnvVars();
-
- for ( Iterator i = systemEnvVars.keySet().iterator(); i.hasNext(); )
- {
- String key = (String) i.next();
- if ( !envVars.containsKey( key ) )
- {
- addEnvironment( key, systemEnvVars.getProperty( key ) );
- }
- }
- }
-
- public String toString()
- {
- StringBuffer strBuff = new StringBuffer( "" );
- for ( String command : getEscapedShellCommandline() )
- {
- strBuff.append( " " );
- strBuff.append( command );
- }
- return strBuff.toString();
- }
-
- public String[] getEscapedShellCommandline()
- {
- String[] scl = getShellCommandline();
- for ( int i = 0; i < scl.length; i++ )
- {
- scl[i] = escapeCmdParams( scl[i] );
- }
- return scl;
- }
-
- // escaped to make use of dotnet style of command escapes .
- // Eg. /define:"CONFIG=\"Debug\",DEBUG=-1,TRACE=-1,_MyType=\"Windows\",PLATFORM=\"AnyCPU\""
- private String escapeCmdParams( String param )
- {
- if ( param == null )
- {
- return null;
- }
-
- String str = param;
- if ( param.startsWith( "/" ) && param.indexOf( ":" ) > 0 )
- {
- int delem = param.indexOf( ":" ) + 1;
- String command = param.substring( 0, delem );
- String value = param.substring( delem );
-
- if ( value.indexOf( " " ) > 0 || value.indexOf( "\"" ) > 0 )
- {
- value = "\"" + value.replaceAll( "\"", "\\\\\"" ) + "\"";
- }
-
- str = command + value;
- }
- else if ( param.startsWith( "@" ) )
- {
- str = param;
- }
-
- return str;
- }
- };
-
- // NPANDAY-409
- // On non-Windows platforms, such as Linux, "gmcs" not resolved
- // to gmcs.exe in working directory due to /usr/bin/gmcs
- // but "./gmcs.exe" resolved as desired in working directory
- String osName = System.getProperty( "os.name" );
- if ( !osName.toLowerCase().contains( "win" ) )
- {
- File executableFile = PathUtil.getExecutable( workingDirectory, executable );
- // do not prefix for internal commands, such as mkdir
- if ( executableFile != null && workingDirectory.equals( executableFile.getParentFile() ) )
- {
- executable = new File( "./", executableFile.getName() ).toString();
- }
- }
-
- commandline.setExecutable( executable );
- commandline.addArguments( commands.toArray( new String[commands.size()] ) );
-
- if ( workingDirectory != null && workingDirectory.exists() )
- {
- // TODO: Wrong use of working directory! $(basedir) should be the working dir, and the executable paths should be absolute
- commandline.setWorkingDirectory( workingDirectory.getAbsolutePath() );
- }
- else if (workingDirectory != null && !workingDirectory.exists())
- {
- logger.info( "NPANDAY-040-006: Did not find executable path for " + executable + ", will try system path" );
- }
-
- try
- {
- result = CommandLineUtils.executeCommandLine( commandline, stdOut, stdErr );
- if ( logger != null )
- {
- logger.debug(
- "NPANDAY-040-005: Executed command: Commandline = " + commandline + ", Result = "
- + result );
- }
- else
- {
- System.out.println(
- "NPANDAY-040-004: Executed command: Commandline = " + commandline + ", Result = "
- + result );
- }
- if ( ( failsOnErrorOutput && stdErr.hasError() ) || result != 0 )
- {
- throw new ExecutionException(
- "NPANDAY-040-001: Could not execute: Command = " + commandline.toString()
- + ", Result = " + result );
- }
- }
- catch ( CommandLineException e )
- {
- throw new ExecutionException(
- "NPANDAY-040-002: Could not execute: Command = " + commandline.toString(), e );
- }
- }
-
- public int getResult()
- {
- return result;
- }
-
- public String getStandardOut()
- {
- return stdOut.toString();
- }
-
- public String getStandardError()
- {
- return stdErr.toString();
- }
-
- /**
- * Provides behavior for determining whether the command utility wrote anything to the Standard Error Stream.
- * NOTE: I am using this to decide whether to fail the NPanday build. If the compiler implementation chooses
- * to write warnings to the error stream, then the build will fail on warnings!!!
- */
- class ErrorStreamConsumer
- implements StreamConsumer
- {
-
- /**
- * Is true if there was anything consumed from the stream, otherwise false
- */
- private boolean error;
-
- /**
- * Buffer to store the stream
- */
- private StringBuffer sbe = new StringBuffer();
-
- public ErrorStreamConsumer()
- {
- if ( logger == null )
- {
- System.out.println( "NPANDAY-040-003: Error Log not set: Will not output error logs" );
- }
- error = false;
- }
-
- public void consumeLine( String line )
- {
- sbe.append( line );
- if ( logger != null )
- {
- logger.info( line );
- }
- error = true;
- }
-
- /**
- * Returns false if the command utility wrote to the Standard Error Stream, otherwise returns true.
- *
- * @return false if the command utility wrote to the Standard Error Stream, otherwise returns true.
- */
- public boolean hasError()
- {
- return error;
- }
-
- /**
- * Returns the error stream
- *
- * @return error stream
- */
- public String toString()
- {
- return sbe.toString();
- }
- }
-
- /**
- * StreamConsumer instance that buffers the entire output
- */
- class StreamConsumerImpl
- implements StreamConsumer
- {
-
- private DefaultConsumer consumer;
-
- private StringBuffer sb = new StringBuffer();
-
- public StreamConsumerImpl()
- {
- consumer = new DefaultConsumer();
- }
-
- public void consumeLine( String line )
- {
- sb.append( line );
- if ( logger != null )
- {
- consumer.consumeLine( line );
- }
- }
-
- /**
- * Returns the stream
- *
- * @return the stream
- */
- public String toString()
- {
- return sb.toString();
- }
- }
- };
-
+ return new DefaultCommandExecutor();
}
+
}
+
}
Added: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/CustomCommandline.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/CustomCommandline.java?rev=1221688&view=auto
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/CustomCommandline.java (added)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/CustomCommandline.java Wed Dec 21 12:05:20 2011
@@ -0,0 +1,163 @@
+package npanday.executable.execution;
+
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * @author Shane Isbell
+ * @author <a href="mailto:lcorneliussen@apache.org">Lars Corneliussen</a>
+ */
+public class CustomCommandline
+ extends Commandline
+{
+ protected Map envVars = Collections.synchronizedMap( new LinkedHashMap() );
+
+ public Process execute() throws CommandLineException
+ {
+ Process process;
+
+ String[] environment = getEnvironmentVariables();
+
+ File workingDir = getWorkingDirectory();
+
+ try
+ {
+ String[] cmd = getEscapedShellCommandline();
+
+ if ( workingDir == null )
+ {
+ process = Runtime.getRuntime().exec( cmd, environment );
+ }
+ else
+ {
+ if ( !workingDir.exists() )
+ {
+ throw new CommandLineException(
+ "NPANDAY-040-010: Working directory \"" + workingDir.getPath() + "\" does not exist!"
+ );
+ }
+ else if ( !workingDir.isDirectory() )
+ {
+ throw new CommandLineException(
+ "NPANDAY-040-009: Path \"" + workingDir.getPath() + "\" does not specify a directory."
+ );
+ }
+
+ process = Runtime.getRuntime().exec( cmd, environment, workingDir );
+ }
+ }
+ catch ( IOException ex )
+ {
+ throw new CommandLineException( "NPANDAY-040-008: Error while executing process.", ex );
+ }
+
+ return process;
+ }
+
+ public String[] getEnvironmentVariables() throws CommandLineException
+ {
+ try
+ {
+ addSystemEnvironment();
+ }
+ catch ( Exception e )
+ {
+ throw new CommandLineException(
+ "NPANDAY-040-007: Error setting up environmental variables", e
+ );
+ }
+ String[] environmentVars = new String[envVars.size()];
+ int i = 0;
+ for ( Iterator iterator = envVars.keySet().iterator(); iterator.hasNext(); )
+ {
+ String name = (String) iterator.next();
+ String value = (String) envVars.get( name );
+ environmentVars[i] = name + "=" + value;
+ i++;
+ }
+ return environmentVars;
+ }
+
+ public void addEnvironment( String name, String value )
+ {
+ envVars.put( name, value );
+ }
+
+ /**
+ * Add system environment variables
+ */
+ public void addSystemEnvironment() throws Exception
+ {
+ Properties systemEnvVars = CommandLineUtils.getSystemEnvVars();
+
+ for ( Iterator i = systemEnvVars.keySet().iterator(); i.hasNext(); )
+ {
+ String key = (String) i.next();
+ if ( !envVars.containsKey( key ) )
+ {
+ addEnvironment( key, systemEnvVars.getProperty( key ) );
+ }
+ }
+ }
+
+ public String toString()
+ {
+ StringBuffer strBuff = new StringBuffer( "" );
+ for ( String command : getEscapedShellCommandline() )
+ {
+ strBuff.append( " " );
+ strBuff.append( command );
+ }
+ return strBuff.toString();
+ }
+
+ public String[] getEscapedShellCommandline()
+ {
+ String[] scl = getShellCommandline();
+ for ( int i = 0; i < scl.length; i++ )
+ {
+ scl[i] = escapeCmdParams( scl[i] );
+ }
+ return scl;
+ }
+
+ // escaped to make use of dotnet style of command escapes .
+ // Eg. /define:"CONFIG=\"Debug\",DEBUG=-1,TRACE=-1,_MyType=\"Windows\",PLATFORM=\"AnyCPU\""
+ private String escapeCmdParams( String param )
+ {
+ if ( param == null )
+ {
+ return null;
+ }
+
+ String str = param;
+ if ( param.startsWith( "/" ) && param.indexOf( ":" ) > 0 )
+ {
+ int delem = param.indexOf( ":" ) + 1;
+ String command = param.substring( 0, delem );
+ String value = param.substring( delem );
+
+ if ( value.indexOf( " " ) > 0 || value.indexOf( "\"" ) > 0 )
+ {
+ value = "\"" + value.replaceAll( "\"", "\\\\\"" ) + "\"";
+ }
+
+ str = command + value;
+ }
+ else if ( param.startsWith( "@" ) )
+ {
+ str = param;
+ }
+
+ return str;
+ }
+}
Added: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/DefaultCommandExecutor.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/DefaultCommandExecutor.java?rev=1221688&view=auto
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/DefaultCommandExecutor.java (added)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/DefaultCommandExecutor.java Wed Dec 21 12:05:20 2011
@@ -0,0 +1,148 @@
+package npanday.executable.execution;
+
+import npanday.PathUtil;
+import npanday.executable.CommandExecutor;
+import npanday.executable.ExecutionException;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+import org.codehaus.plexus.util.cli.StreamConsumer;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Shane Isbell
+ * @author <a href="mailto:lcorneliussen@apache.org">Lars Corneliussen</a>
+ */
+public class DefaultCommandExecutor
+ implements CommandExecutor
+{
+ /**
+ * Instance of a plugin logger.
+ */
+ private Logger logger;
+
+ /**
+ * Standard Out
+ */
+ private StreamConsumer stdOut;
+
+ /**
+ * Standard Error
+ */
+ private ErrorStreamConsumer stdErr;
+
+ /**
+ * Process result
+ */
+ private int result;
+
+ public void setLogger( Logger logger )
+ {
+ this.logger = logger;
+ }
+
+ public void executeCommand( String executable, List<String> commands ) throws ExecutionException
+ {
+ executeCommand( executable, commands, null, true );
+ }
+
+ public void executeCommand( String executable, List<String> commands, boolean failsOnErrorOutput ) throws
+ ExecutionException
+ {
+ executeCommand( executable, commands, null, failsOnErrorOutput );
+ }
+
+ public void executeCommand(
+ String executable, List<String> commands, File workingDirectory, boolean failsOnErrorOutput ) throws
+ ExecutionException
+ {
+ if ( commands == null )
+ {
+ commands = new ArrayList<String>();
+ }
+ stdOut = new StandardStreamConsumer( logger );
+ stdErr = new ErrorStreamConsumer( logger );
+
+ Commandline commandline = new CustomCommandline();
+
+ // NPANDAY-409
+ // On non-Windows platforms, such as Linux, "gmcs" not resolved
+ // to gmcs.exe in working directory due to /usr/bin/gmcs
+ // but "./gmcs.exe" resolved as desired in working directory
+ String osName = System.getProperty( "os.name" );
+ if ( !osName.toLowerCase().contains( "win" ) )
+ {
+ File executableFile = PathUtil.getExecutable( workingDirectory, executable );
+ // do not prefix for internal commands, such as mkdir
+ if ( executableFile != null && workingDirectory.equals( executableFile.getParentFile() ) )
+ {
+ executable = new File( "./", executableFile.getName() ).toString();
+ }
+ }
+
+ commandline.setExecutable( executable );
+ commandline.addArguments( commands.toArray( new String[commands.size()] ) );
+
+ if ( workingDirectory != null && workingDirectory.exists() )
+ {
+ // TODO: Wrong use of working directory! $(basedir) should be the working dir,
+ // and the executable paths should be absolute
+ commandline.setWorkingDirectory( workingDirectory.getAbsolutePath() );
+ }
+ else if ( workingDirectory != null && !workingDirectory.exists() )
+ {
+ logger.info(
+ "NPANDAY-040-006: Did not find executable path for " + executable + ", " + "will try system path"
+ );
+ }
+
+ try
+ {
+ result = CommandLineUtils.executeCommandLine( commandline, stdOut, stdErr );
+ if ( logger != null )
+ {
+ logger.debug(
+ "NPANDAY-040-005: Executed command: Commandline = " + commandline + ", Result = " + result
+ );
+ }
+ else
+ {
+ System.out.println(
+ "NPANDAY-040-004: Executed command: Commandline = " + commandline + ", Result = " + result
+ );
+ }
+ if ( ( failsOnErrorOutput && stdErr.hasError() ) || result != 0 )
+ {
+ throw new ExecutionException(
+ "NPANDAY-040-001: Could not execute: Command = " + commandline.toString() + ", Result = " + result
+ );
+ }
+ }
+ catch ( CommandLineException e )
+ {
+ throw new ExecutionException(
+ "NPANDAY-040-002: Could not execute: Command = " + commandline.toString(), e
+ );
+ }
+ }
+
+ public int getResult()
+ {
+ return result;
+ }
+
+ public String getStandardOut()
+ {
+ return stdOut.toString();
+ }
+
+ public String getStandardError()
+ {
+ return stdErr.toString();
+ }
+
+}
Added: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/ErrorStreamConsumer.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/ErrorStreamConsumer.java?rev=1221688&view=auto
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/ErrorStreamConsumer.java (added)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/ErrorStreamConsumer.java Wed Dec 21 12:05:20 2011
@@ -0,0 +1,67 @@
+package npanday.executable.execution;
+
+import com.google.common.base.Preconditions;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.util.cli.StreamConsumer;
+
+/**
+ * Provides behavior for determining whether the command utility wrote anything to the Standard Error Stream.
+ * NOTE: I am using this to decide whether to fail the NPanday build. If the compiler implementation chooses
+ * to write warnings to the error stream, then the build will fail on warnings!!!
+ *
+ * @author Shane Isbell
+ */
+class ErrorStreamConsumer
+ implements StreamConsumer
+{
+
+ /**
+ * Is true if there was anything consumed from the stream, otherwise false
+ */
+ private boolean error;
+
+ /**
+ * Buffer to store the stream
+ */
+ private StringBuffer sbe = new StringBuffer();
+
+ private Logger logger;
+
+ public ErrorStreamConsumer( Logger logger )
+ {
+ Preconditions.checkArgument( logger != null, "logger must not be null" );
+ this.logger = logger;
+
+ error = false;
+ }
+
+ public void consumeLine( String line )
+ {
+ sbe.append( line );
+ if ( logger != null )
+ {
+ logger.info( line );
+ }
+ error = true;
+ }
+
+ /**
+ * Returns false if the command utility wrote to the Standard Error Stream, otherwise returns true.
+ *
+ * @return false if the command utility wrote to the Standard Error Stream, otherwise returns true.
+ */
+ public boolean hasError()
+ {
+ return error;
+ }
+
+ /**
+ * Returns the error stream
+ *
+ * @return error stream
+ */
+ public String toString()
+ {
+ return sbe.toString();
+ }
+}
Added: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/StandardStreamConsumer.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/StandardStreamConsumer.java?rev=1221688&view=auto
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/StandardStreamConsumer.java (added)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/StandardStreamConsumer.java Wed Dec 21 12:05:20 2011
@@ -0,0 +1,50 @@
+package npanday.executable.execution;
+
+import com.google.common.base.Preconditions;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.util.cli.DefaultConsumer;
+import org.codehaus.plexus.util.cli.StreamConsumer;
+
+/**
+ * StreamConsumer instance that buffers the entire output
+ *
+ * @author Shane Isbell
+ */
+class StandardStreamConsumer
+ implements StreamConsumer
+{
+
+ private DefaultConsumer consumer;
+
+ private StringBuffer sb = new StringBuffer();
+
+ private Logger logger;
+
+
+ public StandardStreamConsumer( Logger logger )
+ {
+ Preconditions.checkArgument( logger != null, "logger must not be null" );
+
+ this.logger = logger;
+ consumer = new DefaultConsumer();
+ }
+
+ public void consumeLine( String line )
+ {
+ sb.append( line );
+ if ( logger != null )
+ {
+ consumer.consumeLine( line );
+ }
+ }
+
+ /**
+ * Returns the stream
+ *
+ * @return the stream
+ */
+ public String toString()
+ {
+ return sb.toString();
+ }
+}
Copied: incubator/npanday/trunk/components/dotnet-executable/src/test/java/npanday/executable/execution/CommandExecutorTest.java (from r1221137, incubator/npanday/trunk/components/dotnet-executable/src/test/java/npanday/executable/CommandExecutorTest.java)
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/test/java/npanday/executable/execution/CommandExecutorTest.java?p2=incubator/npanday/trunk/components/dotnet-executable/src/test/java/npanday/executable/execution/CommandExecutorTest.java&p1=incubator/npanday/trunk/components/dotnet-executable/src/test/java/npanday/executable/CommandExecutorTest.java&r1=1221137&r2=1221688&rev=1221688&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/test/java/npanday/executable/CommandExecutorTest.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/test/java/npanday/executable/execution/CommandExecutorTest.java Wed Dec 21 12:05:20 2011
@@ -16,8 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package npanday.executable;
+package npanday.executable.execution;
+import npanday.executable.CommandExecutor;
+import npanday.executable.ExecutionException;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.junit.Test;
Propchange: incubator/npanday/trunk/components/dotnet-executable/src/test/java/npanday/executable/execution/CommandExecutorTest.java
------------------------------------------------------------------------------
svn:eol-style = native