Author: sisbell
Date: Sat Nov 24 12:22:33 2007
New Revision: 597907
URL: http://svn.apache.org/viewvc?rev=597907&view=rev
Log:
Additional compiler classes, cleanup of API.
Added:
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CommandExecutor.java
(with props)
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerException.java
(with props)
Modified:
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerContext.java
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/impl/NetCompilerContextImpl.java
Added:
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CommandExecutor.java
URL:
http://svn.apache.org/viewvc/incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CommandExecutor.java?rev=597907&view=auto
==============================================================================
---
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CommandExecutor.java
(added)
+++
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CommandExecutor.java
Sat Nov 24 12:22:33 2007
@@ -0,0 +1,306 @@
+package org.apache.maven.dotnet.compiler;
+
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.util.cli.StreamConsumer;
+import org.codehaus.plexus.util.cli.Commandline;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.DefaultConsumer;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.io.File;
+
+/**
+ * Provides services for executing commands (executables or compilers). A
<code>NetExecutable</code> or
+ * <code>CompilerExecutable</code> implementation can use the services of this
interface for executing commands.
+ *
+ * @author Shane Isbell
+ */
+public interface CommandExecutor
+{
+ /**
+ * Sets the plexus logger.
+ *
+ * @param logger the plexus logger
+ */
+ void setLogger( Logger logger );
+
+ /**
+ * Executes the command for the specified executable and list of command
options.
+ *
+ * @param executable the name of the executable (csc, xsd, etc).
+ * @param commands the command options for the compiler/executable
+ * @throws org.apache.maven.dotnet.executable.ExecutionException if
compiler or executable writes anything to the standard error stream or if the
process
+ * returns a process result != 0.
+ */
+ void executeCommand( String executable, List<String> commands )
+ throws CompilerException;
+
+ /**
+ * Executes the command for the specified executable and list of command
options.
+ *
+ * @param executable the name of the executable (csc, xsd, etc).
+ * @param commands the commands options for the
compiler/executable
+ * @param failsOnErrorOutput if true, throws an
<code>ExecutionException</code> if there the compiler or executable
+ * writes anything to the error output stream.
By default, this value is true
+ * @throws org.apache.maven.dotnet.executable.ExecutionException if
compiler or executable writes anything to the standard error stream (provided
the
+ * failsOnErrorOutput is not false) or if the
process returns a process result != 0.
+ */
+ void executeCommand( String executable, List<String> commands, boolean
failsOnErrorOutput )
+ throws CompilerException;
+
+ /**
+ * Executes the command for the specified executable and list of command
options. If the compiler or executable is
+ * not within the environmental path, you should use this method to
specify the working directory. Always use this
+ * method for executables located within the local maven repository.
+ *
+ * @param executable the name of the executable (csc, xsd, etc).
+ * @param commands the command options for the compiler/executable
+ * @param workingDirectory the directory where the command will be executed
+ * @throws org.apache.maven.dotnet.executable.ExecutionException if
compiler or executable writes anything to the standard error stream (provided
the
+ * failsOnErrorOutput is not false) or if the
process returns a process result != 0.
+ */
+ void executeCommand( String executable, List<String> commands, File
workingDirectory, boolean failsOnErrorOutput )
+ throws CompilerException;
+
+ /**
+ * Returns the process result of executing the command. Typically a value
of 0 means that the process executed
+ * successfully.
+ *
+ * @return the process result of executing the command
+ */
+ int getResult();
+
+ /**
+ * Returns the standard output from executing the command.
+ *
+ * @return the standard output from executing the command
+ */
+ String getStandardOut();
+
+ /**
+ * Returns the standard error from executing the command.
+ *
+ * @return the standard error from executing the command
+ */
+ String getStandardError();
+
+ /**
+ * Provides factory services for creating a default instance of the
command executor.
+ */
+ public static class Factory
+ {
+
+ /**
+ * Constructor
+ */
+ private Factory()
+ {
+ }
+
+ /**
+ * Returns a default instance of the command executor
+ *
+ * @return a default instance of the command executor
+ */
+ public static org.apache.maven.dotnet.compiler.CommandExecutor
createDefaultCommmandExecutor()
+ {
+ return new org.apache.maven.dotnet.compiler.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 CompilerException
+ {
+ executeCommand( executable, commands, null, true );
+ }
+
+ public void executeCommand( String executable, List<String>
commands, boolean failsOnErrorOutput )
+ throws CompilerException
+ {
+ executeCommand( executable, commands, null,
failsOnErrorOutput );
+ }
+
+ public void executeCommand( String executable, List<String>
commands, File workingDirectory,
+ boolean failsOnErrorOutput )
+ throws CompilerException
+ {
+ if ( commands == null )
+ {
+ commands = new ArrayList<String>();
+ }
+ stdOut = new StreamConsumerImpl();
+ stdErr = new ErrorStreamConsumer();
+
+ Commandline commandline = new Commandline();
+ commandline.setExecutable( executable );
+ commandline.addArguments( commands.toArray( new
String[commands.size()]));
+ if ( workingDirectory != null && workingDirectory.exists()
)
+ {
+ commandline.setWorkingDirectory(
workingDirectory.getAbsolutePath() );
+ }
+ try
+ {
+ result = CommandLineUtils.executeCommandLine(
commandline, stdOut, stdErr );
+ if ( logger != null )
+ {
+ logger.debug( "NMAVEN-040-000: Executed command:
Commandline = " + commandline +
+ ", Result = " + result );
+ }
+ else
+ {
+ System.out.println( "NMAVEN-040-000: Executed
command: Commandline = " + commandline +
+ ", Result = " + result );
+ }
+ if ( ( failsOnErrorOutput && stdErr.hasError() ) ||
result != 0 )
+ {
+ throw new CompilerException( "NMAVEN-040-001:
Could not execute: Command = " +
+ commandline.toString() + ", Result = " +
result );
+ }
+ }
+ catch ( CommandLineException e )
+ {
+ throw new CompilerException(
+ "NMAVEN-040-002: Could not execute: Command = " +
commandline.toString() );
+ }
+ }
+
+ 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 NMaven
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( "NMAVEN-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.error( 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();
+ }
+ }
+ };
+
+ }
+ }
+}
Propchange:
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CommandExecutor.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerContext.java
URL:
http://svn.apache.org/viewvc/incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerContext.java?rev=597907&r1=597906&r2=597907&view=diff
==============================================================================
---
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerContext.java
(original)
+++
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerContext.java
Sat Nov 24 12:22:33 2007
@@ -15,6 +15,6 @@
*
* @return an instance of the NetExecutable appropriate for given
language/vendor/OS.
*/
- Compiler getCompiler();
+ Compiler getCompiler();
}
Added:
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerException.java
URL:
http://svn.apache.org/viewvc/incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerException.java?rev=597907&view=auto
==============================================================================
---
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerException.java
(added)
+++
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerException.java
Sat Nov 24 12:22:33 2007
@@ -0,0 +1,52 @@
+package org.apache.maven.dotnet.compiler;
+
+/**
+ * Exception thrown for compiler errors.
+ *
+ * @author Shane Isbell
+ */
+public class CompilerException
+ extends Exception
+{
+
+ static final long serialVersionUID = -7843278034782074384L;
+
+ /**
+ * Constructs an <code>ExecutionException</code> with no exception
message.
+ */
+ public CompilerException()
+ {
+ super();
+ }
+
+ /**
+ * Constructs an <code>ExecutionException</code> with the specified
exception message.
+ *
+ * @param message the exception message
+ */
+ public CompilerException( String message )
+ {
+ super( message );
+ }
+
+ /**
+ * Constructs an <code>ExecutionException</code> with the specified
exception message and cause of the exception.
+ *
+ * @param message the exception message
+ * @param cause the cause of the exception
+ */
+ public CompilerException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ /**
+ * Constructs an <code>ExecutionException</code> with the cause of the
exception.
+ *
+ * @param cause the cause of the exception
+ */
+ public CompilerException( Throwable cause )
+ {
+ super( cause );
+ }
+}
Propchange:
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerException.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/impl/NetCompilerContextImpl.java
URL:
http://svn.apache.org/viewvc/incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/impl/NetCompilerContextImpl.java?rev=597907&r1=597906&r2=597907&view=diff
==============================================================================
---
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/impl/NetCompilerContextImpl.java
(original)
+++
incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/impl/NetCompilerContextImpl.java
Sat Nov 24 12:22:33 2007
@@ -1,9 +1,7 @@
package org.apache.maven.dotnet.compiler.impl;
-import org.apache.maven.dotnet.compiler.NetCompilerContext;
-import org.apache.maven.dotnet.compiler.KeyInfo;
-import org.apache.maven.dotnet.compiler.InvalidArtifactException;
-import org.apache.maven.dotnet.compiler.CompilerConfig;
+import org.apache.maven.dotnet.compiler.*;
+import org.apache.maven.dotnet.compiler.Compiler;
import org.apache.maven.artifact.Artifact;
import java.util.List;
@@ -64,6 +62,11 @@
public CompilerConfig getCompilerConfig()
{
- return null;
+ return null;
+ }
+
+ public Compiler getCompiler()
+ {
+ return null;
}
}