ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Cvs.java Exec.java
Date Wed, 26 Jan 2000 03:46:06 GMT
rubys       00/01/25 19:46:06

  Modified:    src/bin  antRun
               src/main/org/apache/tools/ant/taskdefs Cvs.java Exec.java
  Log:
  Simultaneously consume both the stdout and stderr during exec calls
  (StreamPumper code based on org.apache.jasper.compiler.JikesJavaCompiler)
  
  Revision  Changes    Path
  1.2       +1 -1      jakarta-ant/src/bin/antRun
  
  Index: antRun
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/bin/antRun,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- antRun	2000/01/13 10:41:39	1.1
  +++ antRun	2000/01/26 03:46:05	1.2
  @@ -11,4 +11,4 @@
   fi
   
   echo $CMD $@
  -$CMD $@ 2>&1
  +$CMD $@
  
  
  
  1.2       +10 -39    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Cvs.java
  
  Index: Cvs.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Cvs.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Cvs.java	2000/01/13 10:41:41	1.1
  +++ Cvs.java	2000/01/26 03:46:06	1.2
  @@ -64,7 +64,7 @@
    * @author stefano@apache.org
    */
   
  -public class Cvs extends Task {
  +public class Cvs extends Exec {
   
       private String cvsRoot;
       private String dest;
  @@ -76,47 +76,18 @@
   	// XXX: we should use JCVS (www.ice.com/JCVS) instead of command line
   	// execution so that we don't rely on having native CVS stuff around (SM)
   	
  -	try {
  -	    String ant=project.getProperty("ant.home");
  -	    if(ant==null) throw new BuildException("Needs ant.home");
  +	String ant=project.getProperty("ant.home");
  +	if(ant==null) throw new BuildException("Needs ant.home");
   
  -	    StringBuffer sb=new StringBuffer();
  -	    sb.append(ant).append("/bin/antRun ").append(dest);
  -	    sb.append(" cvs -d ").append( cvsRoot ).append(" checkout ");
  -	    if(tag!=null)
  -		sb.append("-r ").append(tag).append(" ");
  +	StringBuffer sb=new StringBuffer();
  +	sb.append(ant).append("/bin/antRun ").append(dest);
  +	sb.append(" cvs -d ").append( cvsRoot ).append(" checkout ");
  +	if (tag!=null)
  +            sb.append("-r ").append(tag).append(" ");
   
  -	    sb.append( pack );
  -	    String command=sb.toString();
  +	sb.append( pack );
   
  -            project.log(command, "cvs", Project.MSG_WARN);
  -
  -
  -	    // exec command on system runtime
  -	    Process proc = Runtime.getRuntime().exec( command);
  -	    
  -	    // ignore response
  -	    InputStreamReader isr=new InputStreamReader(proc.getInputStream());
  -	    BufferedReader din = new BufferedReader(isr);
  -
  -	    // pipe CVS output to STDOUT
  -	    String line;
  -	    while((line = din.readLine()) != null) {
  -		project.log(line, "cvs", Project.MSG_WARN);
  -		//System.out.println(line);
  -	    }
  -	    
  -	    proc.waitFor();
  -	    int err = proc.exitValue();
  -	    if (err != 0) {
  -	       throw new BuildException( "Error " + err + "in " + command);
  -	    }
  -	    
  -	} catch (IOException ioe) {
  -	    ioe.printStackTrace();
  -	    throw new BuildException("Error checking out: " + pack );
  -	} catch (InterruptedException ex) {
  -	}
  +        run(sb.toString());
       }
   
       public void setCvsRoot(String root) {
  
  
  
  1.4       +65 -20    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Exec.java
  
  Index: Exec.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Exec.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Exec.java	2000/01/25 23:03:22	1.3
  +++ Exec.java	2000/01/26 03:46:06	1.4
  @@ -69,6 +69,8 @@
       private String dir;
       private String command;
   
  +    private static final int BUFFER_SIZE = 512;
  +
       public void execute() throws BuildException {
           // test if os match
           String myos = System.getProperty("os.name");
  @@ -103,13 +105,22 @@
                   fos=new PrintWriter( new FileWriter( out ) );
                   project.log("Output redirected to " + out, Project.MSG_VERBOSE);
               }
  -            pipeOutput(proc.getInputStream(), "exec", fos);
  -            pipeOutput(proc.getErrorStream(), "error", fos);
  -            if (null != fos)
  -        	fos.close();
   
  +            // copy input and error to the output stream
  +            StreamPumper inputPumper = 
  +                new StreamPumper(proc.getInputStream(), "exec", project, fos);
  +            StreamPumper errorPumper = 
  +                new StreamPumper(proc.getErrorStream(), "error", project, fos);
  +
  +            inputPumper.start();
  +            errorPumper.start();
  +
  +            // Wait for everything to finish
               proc.waitFor();
  -            
  +            inputPumper.join();
  +            errorPumper.join();
  +            proc.destroy();
  +
               // close the output file if required 
               if (fos != null) fos.close();
   
  @@ -140,20 +151,54 @@
           this.out = out;
       }
   
  -    private void pipeOutput(InputStream is, String name, PrintWriter fos) 
  -        throws IOException 
  -    {
  -project.log("pipeOutput", name, Project.MSG_INFO);
  -        InputStreamReader isr=new InputStreamReader(is);
  -        BufferedReader din = new BufferedReader(isr);
  -
  -        // pipe output to STDOUT
  -        String line;
  -        while((line = din.readLine()) != null) {
  -        if( fos==null)
  -            project.log(line, name, Project.MSG_INFO);
  -        else
  -            fos.println(line);
  -        }
  +    // Inner class for continually pumping the input stream during
  +    // Process's runtime.
  +    class StreamPumper extends Thread {
  +	private BufferedReader din;
  +        private String name;
  +	private boolean endOfStream = false;
  +	private int SLEEP_TIME = 5;
  +        private Project project;
  +	private PrintWriter fos;
  +
  +	public StreamPumper(InputStream is, String name, Project project, PrintWriter fos) {
  +            this.din     = new BufferedReader(new InputStreamReader(is));
  +            this.name    = name;
  +            this.project = project;
  +	    this.fos     = fos;
  +	}
  +
  +	public void pumpStream()
  +	    throws IOException
  +	{
  +	    byte[] buf = new byte[BUFFER_SIZE];
  +	    if (!endOfStream) {
  +                String line = din.readLine();
  +
  +		if (line != null) {
  +                    if (fos==null)
  +                        project.log(line, name, Project.MSG_INFO);
  +                    else
  +                        fos.println(line);
  +		} else {
  +		    endOfStream=true;
  +		}
  +	    }
  +	}
  +
  +	public void run() {
  +            try {
  +	        try {
  +		    while (!endOfStream) {
  +		        pumpStream();
  +		        sleep(SLEEP_TIME);
  +		    }
  +	        } catch (InterruptedException ie) {
  +                }
  +                din.close();
  +	    } catch (IOException ioe) {
  +	    }
  +	}
       }
  +
   }
  
  
  

Mime
View raw message