bodewig     2004/06/23 05:30:40

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/taskdefs/optional/net
                        RExecTask.java
  Log:
  PR 25935 applies to <rexec> as well
  
  Revision  Changes    Path
  1.629     +1 -1      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.628
  retrieving revision 1.629
  diff -u -r1.628 -r1.629
  --- WHATSNEW  23 Jun 2004 12:25:04 -0000      1.628
  +++ WHATSNEW  23 Jun 2004 12:30:40 -0000      1.629
  @@ -151,7 +151,7 @@
   * <scp> now has (local|remote)tofile attributes to rename files on the
     fly.  Bugzilla Report 26758.
   
  -* <telnet> didn't close the session.  Bugzilla Report 25935.
  +* <telnet> and <rexec> didn't close the session.  Bugzilla Report 25935.
   
   Other changes:
   --------------
  
  
  
  1.8       +32 -25    
ant/src/main/org/apache/tools/ant/taskdefs/optional/net/RExecTask.java
  
  Index: RExecTask.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/net/RExecTask.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- RExecTask.java    9 Feb 2004 21:05:33 -0000       1.7
  +++ RExecTask.java    23 Jun 2004 12:30:40 -0000      1.8
  @@ -62,11 +62,6 @@
       private int port = RExecClient.DEFAULT_PORT;
   
       /**
  -     *  The Object which handles the rexec session.
  -     */
  -    private AntRExecClient rexec = null;
  -
  -    /**
        *  The list of read/write commands for this session
        */
       private Vector rexecTasks = new Vector();
  @@ -322,34 +317,46 @@
           }
   
           /**  Create the telnet client object */
  -        rexec = new AntRExecClient();
  +        AntRExecClient rexec = null;
           try {
  -            rexec.connect(server, port);
  -        } catch (IOException e) {
  -            throw new BuildException("Can't connect to " + server);
  -        }
  -        /**  Login if userid and password were specified */
  -        if (userid != null && password != null) {
  -            login();
  -        }
  -        /**  Process each sub command */
  -        Enumeration tasksToRun = rexecTasks.elements();
  -        while (tasksToRun != null && tasksToRun.hasMoreElements()) {
  -            RExecSubTask task = (RExecSubTask) tasksToRun.nextElement();
  -            if (task instanceof RExecRead && defaultTimeout != null) {
  -                ((RExecRead) task).setDefaultTimeout(defaultTimeout);
  +            rexec = new AntRExecClient();
  +            try {
  +                rexec.connect(server, port);
  +            } catch (IOException e) {
  +                throw new BuildException("Can't connect to " + server);
  +            }
  +            /**  Login if userid and password were specified */
  +            if (userid != null && password != null) {
  +                login(rexec);
  +            }
  +            /**  Process each sub command */
  +            Enumeration tasksToRun = rexecTasks.elements();
  +            while (tasksToRun != null && tasksToRun.hasMoreElements()) {
  +                RExecSubTask task = (RExecSubTask) tasksToRun.nextElement();
  +                if (task instanceof RExecRead && defaultTimeout != null) {
  +                    ((RExecRead) task).setDefaultTimeout(defaultTimeout);
  +                }
  +                task.execute(rexec);
               }
  -            task.execute(rexec);
  -        }
   
  -        /** Keep reading input stream until end of it or time-out */
  -        rexec.waitForEOF(defaultTimeout);
  +            /** Keep reading input stream until end of it or time-out */
  +            rexec.waitForEOF(defaultTimeout);
  +       } finally {
  +           if (rexec != null) {
  +               try {
  +                   rexec.disconnect();
  +               } catch (IOException e) {
  +                   throw new BuildException("Error disconnecting from " 
  +                                            + server);
  +               }
  +           }
  +       }
       }
       /**
        *  Process a 'typical' login.  If it differs, use the read
        *  and write tasks explicitely
        */
  -    private void login() {
  +    private void login(AntRExecClient rexec) {
           if (addCarriageReturn) {
               rexec.sendString("\n", true);
           }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to