donaldp 02/01/05 18:24:12
Modified:
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ccm
CCMCreateTask.java Continuus.java
Log:
Moved to Execute2 + ExecOutputHandler rather than Execute1 and friends
Revision Changes Path
1.8 +53 -71
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ccm/CCMCreateTask.java
Index: CCMCreateTask.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ccm/CCMCreateTask.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- CCMCreateTask.java 23 Dec 2001 06:31:54 -0000 1.7
+++ CCMCreateTask.java 6 Jan 2002 02:24:12 -0000 1.8
@@ -7,13 +7,8 @@
*/
package org.apache.tools.ant.taskdefs.optional.ccm;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.ant.taskdefs.exec.ExecuteStreamHandler;
+import org.apache.myrmidon.framework.exec.ExecOutputHandler;
import org.apache.tools.ant.types.Commandline;
/**
@@ -23,7 +18,7 @@
*/
public class CCMCreateTask
extends Continuus
- implements ExecuteStreamHandler
+ implements ExecOutputHandler
{
/**
* /comment -- comments associated to the task
@@ -138,47 +133,48 @@
public void execute()
throws TaskException
{
- final Commandline commandLine = new Commandline();
-
- // build the command line from what we got the format
- // as specified in the CCM.EXE help
- commandLine.setExecutable( getCcmCommand() );
- commandLine.createArgument().setValue( getCcmAction() );
-
- checkOptions( commandLine );
-
- final int result = run( commandLine, this );
- if( result != 0 )
+ final Commandline commandLine = determineTask();
+ if( null == m_task )
{
- String msg = "Failed executing: " + commandLine.toString();
- throw new TaskException( msg );
+ final String message = "Error determining task";
+ throw new TaskException( message );
}
//create task ok, set this task as the default one
- final Commandline commandLine2 = new Commandline();
- commandLine2.setExecutable( getCcmCommand() );
- commandLine2.createArgument().setValue( COMMAND_DEFAULT_TASK );
- commandLine2.createArgument().setValue( m_task );
+ final Commandline cmd = new Commandline();
+ cmd.setExecutable( getCcmCommand() );
+ cmd.createArgument().setValue( COMMAND_DEFAULT_TASK );
+ cmd.createArgument().setValue( m_task );
getLogger().debug( commandLine.toString() );
- final int result2 = run( commandLine2 );
+ final int result2 = run( cmd, null );
if( result2 != 0 )
{
- String msg = "Failed executing: " + commandLine2.toString();
- throw new TaskException( msg );
+ final String message = "Failed executing: " + cmd.toString();
+ throw new TaskException( message );
}
}
- // implementation of org.apache.tools.ant.taskdefs.ExecuteStreamHandler
interface
-
- public void start()
- throws IOException
+ private Commandline determineTask()
+ throws TaskException
{
- }
+ final Commandline commandLine = new Commandline();
- public void stop()
- {
+ // build the command line from what we got the format
+ // as specified in the CCM.EXE help
+ commandLine.setExecutable( getCcmCommand() );
+ commandLine.createArgument().setValue( getCcmAction() );
+
+ checkOptions( commandLine );
+
+ final int result = run( commandLine, this );
+ if( result != 0 )
+ {
+ final String message = "Failed executing: " +
commandLine.toString();
+ throw new TaskException( message );
+ }
+ return commandLine;
}
/**
@@ -218,55 +214,41 @@
}
/**
- * @param is The new ProcessErrorStream value
- * @exception IOException Description of Exception
+ * Receive notification about the process writing
+ * to standard output.
*/
- public void setProcessErrorStream( final InputStream error )
- throws IOException
+ public void stdout( final String line )
{
- final BufferedReader reader = new BufferedReader( new
InputStreamReader( error ) );
- final String errorLine = reader.readLine();
- if( errorLine != null )
- {
- getLogger().debug( "err " + errorLine );
- }
- }
+ getLogger().debug( "buffer:" + line );
+ final String task = getTask( line );
- public void setProcessInputStream( final OutputStream output )
- throws IOException
- {
+ setTask( task );
+ getLogger().debug( "task is " + m_task );
}
- /**
- * read the output stream to retrieve the new task number.
- */
- public void setProcessOutputStream( final InputStream input )
- throws TaskException, IOException
+ private String getTask( final String line )
{
try
{
- final BufferedReader reader =
- new BufferedReader( new InputStreamReader( input ) );
- final String buffer = reader.readLine();
- if( buffer != null )
- {
- getLogger().debug( "buffer:" + buffer );
- String taskstring = buffer.substring( buffer.indexOf( ' ' )
).trim();
- taskstring = taskstring.substring( 0,
taskstring.lastIndexOf( ' ' ) ).trim();
- setTask( taskstring );
- getLogger().debug( "task is " + m_task );
- }
- }
- catch( final NullPointerException npe )
- {
- getLogger().error( "error procession stream , null pointer
exception", npe );
- throw new TaskException( npe.getClass().getName(), npe );
+ final String task = line.substring( line.indexOf( ' ' ) ).trim();
+ return task.substring( 0, task.lastIndexOf( ' ' ) ).trim();
}
catch( final Exception e )
{
- getLogger().error( "error procession stream " + e.getMessage() );
- throw new TaskException( e.getMessage(), e );
+ final String message = "error procession stream " +
e.getMessage();
+ getLogger().error( message, e );
}
+
+ return null;
+ }
+
+ /**
+ * Receive notification about the process writing
+ * to standard error.
+ */
+ public void stderr( final String line )
+ {
+ getLogger().debug( "err " + line );
}
}
1.15 +11 -18
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ccm/Continuus.java
Index: Continuus.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ccm/Continuus.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Continuus.java 30 Dec 2001 10:46:58 -0000 1.14
+++ Continuus.java 6 Jan 2002 02:24:12 -0000 1.15
@@ -9,12 +9,10 @@
import java.io.File;
import java.io.IOException;
+import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.taskdefs.exec.Execute;
-import org.apache.tools.ant.taskdefs.exec.ExecuteStreamHandler;
-import org.apache.tools.ant.taskdefs.exec.LogOutputStream;
-import org.apache.tools.ant.taskdefs.exec.LogStreamHandler;
+import org.apache.myrmidon.framework.exec.ExecOutputHandler;
+import org.apache.tools.ant.taskdefs.exec.Execute2;
import org.apache.tools.ant.types.Commandline;
/**
@@ -28,7 +26,7 @@
* @author Benoit Moussaud [EMAIL PROTECTED]
*/
public abstract class Continuus
- extends Task
+ extends AbstractTask
{
/**
* Constant for the thing to execute
@@ -108,13 +106,17 @@
return toReturn;
}
- protected int run( final Commandline cmd,
- final ExecuteStreamHandler handler )
+ protected int run( final Commandline cmd, final ExecOutputHandler
handler )
throws TaskException
{
try
{
- final Execute exe = new Execute( handler );
+ final Execute2 exe = new Execute2();
+ setupLogger( exe );
+ if( null != handler )
+ {
+ exe.setExecOutputHandler( handler );
+ }
exe.setWorkingDirectory( getBaseDirectory() );
exe.setCommandline( cmd.getCommandline() );
return exe.execute();
@@ -123,14 +125,5 @@
{
throw new TaskException( "Error", ioe );
}
- }
-
- protected int run( final Commandline cmd )
- throws TaskException
- {
- final LogOutputStream output = new LogOutputStream( getLogger(),
false );
- final LogOutputStream error = new LogOutputStream( getLogger(), true
);
- final LogStreamHandler handler = new LogStreamHandler( output, error
);
- return run( cmd, handler );
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>