From 8d3ee3fbeaf149ab8408b65a9728d1fcb01f1f27 Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Sun, 20 Jan 2002 03:20:06 +0000 Subject: [PATCH] Reworked task to remove dependency on Execute git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270799 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/taskdefs/optional/pvcs/Pvcs.java | 40 ++++++++++++++++--- .../ant/taskdefs/optional/pvcs/Pvcs.java | 40 ++++++++++++++++--- 2 files changed, 70 insertions(+), 10 deletions(-) diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java index 841cfb133..c18f9f741 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java @@ -19,11 +19,11 @@ import java.text.MessageFormat; import java.text.ParseException; import java.util.ArrayList; import java.util.Iterator; +import org.apache.aut.nativelib.ExecOutputHandler; +import org.apache.avalon.excalibur.io.IOUtil; import org.apache.myrmidon.api.AbstractTask; import org.apache.myrmidon.api.TaskException; -import org.apache.tools.ant.taskdefs.exec.Execute; import org.apache.tools.ant.taskdefs.exec.Execute2; -import org.apache.tools.ant.taskdefs.exec.LogOutputStream; import org.apache.tools.ant.types.Commandline; /** @@ -44,6 +44,7 @@ import org.apache.tools.ant.types.Commandline; */ public class Pvcs extends AbstractTask + implements ExecOutputHandler { /** * Constant for the thing to execute @@ -72,6 +73,7 @@ public class Pvcs private String m_repository; private boolean m_updateOnly; private String m_workspace; + private FileOutputStream m_output; /** * Creates a Pvcs object @@ -269,9 +271,10 @@ public class Pvcs tmp = File.createTempFile( "pvcs_ant_", ".log" ); final File fileList = File.createTempFile( "pvcs_ant_", ".log" ); - final Execute exe = new Execute(); - exe.setOutput( new FileOutputStream( tmp ) ); - exe.setError( new LogOutputStream( getLogger(), true ) ); + final Execute2 exe = new Execute2(); + setupLogger( exe ); + exe.setExecOutputHandler( this ); + m_output = new FileOutputStream( tmp ); exe.setWorkingDirectory( getBaseDirectory() ); exe.setCommandline( cmd.getCommandline() ); final int result = exe.execute(); @@ -306,6 +309,7 @@ public class Pvcs } finally { + IOUtil.shutdownStream( m_output ); if( null != tmp ) { tmp.delete(); @@ -313,6 +317,32 @@ public class Pvcs } } + /** + * Receive notification about the process writing + * to standard output. + */ + public void stdout( final String line ) + { + try + { + m_output.write( line.getBytes() ); + } + catch( final IOException ioe ) + { + final String message = "Failed to write to output stream"; + getLogger().error( message ); + } + } + + /** + * Receive notification about the process writing + * to standard error. + */ + public void stderr( final String line ) + { + getLogger().warn( line ); + } + private Commandline buildPCLICommand() throws TaskException { diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java index 841cfb133..c18f9f741 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java @@ -19,11 +19,11 @@ import java.text.MessageFormat; import java.text.ParseException; import java.util.ArrayList; import java.util.Iterator; +import org.apache.aut.nativelib.ExecOutputHandler; +import org.apache.avalon.excalibur.io.IOUtil; import org.apache.myrmidon.api.AbstractTask; import org.apache.myrmidon.api.TaskException; -import org.apache.tools.ant.taskdefs.exec.Execute; import org.apache.tools.ant.taskdefs.exec.Execute2; -import org.apache.tools.ant.taskdefs.exec.LogOutputStream; import org.apache.tools.ant.types.Commandline; /** @@ -44,6 +44,7 @@ import org.apache.tools.ant.types.Commandline; */ public class Pvcs extends AbstractTask + implements ExecOutputHandler { /** * Constant for the thing to execute @@ -72,6 +73,7 @@ public class Pvcs private String m_repository; private boolean m_updateOnly; private String m_workspace; + private FileOutputStream m_output; /** * Creates a Pvcs object @@ -269,9 +271,10 @@ public class Pvcs tmp = File.createTempFile( "pvcs_ant_", ".log" ); final File fileList = File.createTempFile( "pvcs_ant_", ".log" ); - final Execute exe = new Execute(); - exe.setOutput( new FileOutputStream( tmp ) ); - exe.setError( new LogOutputStream( getLogger(), true ) ); + final Execute2 exe = new Execute2(); + setupLogger( exe ); + exe.setExecOutputHandler( this ); + m_output = new FileOutputStream( tmp ); exe.setWorkingDirectory( getBaseDirectory() ); exe.setCommandline( cmd.getCommandline() ); final int result = exe.execute(); @@ -306,6 +309,7 @@ public class Pvcs } finally { + IOUtil.shutdownStream( m_output ); if( null != tmp ) { tmp.delete(); @@ -313,6 +317,32 @@ public class Pvcs } } + /** + * Receive notification about the process writing + * to standard output. + */ + public void stdout( final String line ) + { + try + { + m_output.write( line.getBytes() ); + } + catch( final IOException ioe ) + { + final String message = "Failed to write to output stream"; + getLogger().error( message ); + } + } + + /** + * Receive notification about the process writing + * to standard error. + */ + public void stderr( final String line ) + { + getLogger().warn( line ); + } + private Commandline buildPCLICommand() throws TaskException {