ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/util DateUtils.java
Date Fri, 08 Nov 2002 15:40:55 GMT
bodewig     2002/11/08 07:40:55

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/listener MailLogger.java
               src/main/org/apache/tools/ant/taskdefs/email Mailer.java
               src/main/org/apache/tools/ant/util DateUtils.java
  Log:
  Add Date header to MailLogger by reusing code from <mail> task.
  
  PR: 14046
  
  Revision  Changes    Path
  1.314     +2 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.313
  retrieving revision 1.314
  diff -u -r1.313 -r1.314
  --- WHATSNEW	8 Nov 2002 13:10:22 -0000	1.313
  +++ WHATSNEW	8 Nov 2002 15:40:54 -0000	1.314
  @@ -96,6 +96,8 @@
   
   * new task <attrib> to change file attributes on Windows systems.
   
  +* MailLogger now sets the Date header correctly.
  +
   Changes from Ant 1.5.1Beta1 to 1.5.1
   ====================================
   
  
  
  
  1.13      +2 -0      jakarta-ant/src/main/org/apache/tools/ant/listener/MailLogger.java
  
  Index: MailLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/listener/MailLogger.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- MailLogger.java	8 Aug 2002 14:35:23 -0000	1.12
  +++ MailLogger.java	8 Nov 2002 15:40:54 -0000	1.13
  @@ -64,6 +64,7 @@
   import org.apache.tools.ant.BuildEvent;
   import org.apache.tools.ant.DefaultLogger;
   import org.apache.tools.ant.Project;
  +import org.apache.tools.ant.util.DateUtils;
   import org.apache.tools.ant.util.StringUtils;
   import org.apache.tools.mail.MailMessage;
   
  @@ -218,6 +219,7 @@
       private void sendMail(String mailhost, int port, String from, String toList,
                             String subject, String message) throws IOException {
           MailMessage mailMessage = new MailMessage(mailhost, port);
  +        mailMessage.setHeader("Date", DateUtils.getDateForHeader());
   
           mailMessage.from(from);
   
  
  
  
  1.6       +2 -29     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/email/Mailer.java
  
  Index: Mailer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/email/Mailer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Mailer.java	22 Jun 2002 23:38:35 -0000	1.5
  +++ Mailer.java	8 Nov 2002 15:40:55 -0000	1.6
  @@ -53,14 +53,10 @@
    */
   package org.apache.tools.ant.taskdefs.email;
   
  -import java.text.DateFormat;
  -import java.text.SimpleDateFormat;
  -import java.util.Calendar;
  -import java.util.Locale;
  -import java.util.TimeZone;
   import java.util.Vector;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Task;
  +import org.apache.tools.ant.util.DateUtils;
   
   /**
    * Base class for the various emailing implementations.
  @@ -81,9 +77,6 @@
       protected Task task;
       protected boolean includeFileNames = false;
   
  -    private static DateFormat df =
  -        new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss ", Locale.US);
  -
       /**
        * Sets the mail server
        *
  @@ -209,27 +202,7 @@
        * @since Ant 1.5
        */
       protected final String getDate() {
  -        Calendar cal = Calendar.getInstance();
  -        TimeZone tz = cal.getTimeZone();
  -        int offset = tz.getOffset(cal.get(Calendar.ERA), 
  -                                  cal.get(Calendar.YEAR),
  -                                  cal.get(Calendar.MONTH),
  -                                  cal.get(Calendar.DAY_OF_MONTH),
  -                                  cal.get(Calendar.DAY_OF_WEEK),
  -                                  cal.get(Calendar.MILLISECOND));
  -        StringBuffer tzMarker = new StringBuffer(offset < 0 ? "-" : "+");
  -        offset = Math.abs(offset);
  -        int hours = offset / (60 * 60 * 1000);
  -        int minutes = offset / (60 * 1000) - 60 * hours;
  -        if (hours < 10) {
  -            tzMarker.append("0");
  -        }
  -        tzMarker.append(hours);
  -        if (minutes < 10) {
  -            tzMarker.append("0");
  -        }
  -        tzMarker.append(minutes);
  -        return df.format(cal.getTime()) + tzMarker.toString();
  +        return DateUtils.getDateForHeader();
       }
   }
   
  
  
  
  1.6       +38 -1     jakarta-ant/src/main/org/apache/tools/ant/util/DateUtils.java
  
  Index: DateUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/util/DateUtils.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DateUtils.java	15 Apr 2002 14:56:34 -0000	1.5
  +++ DateUtils.java	8 Nov 2002 15:40:55 -0000	1.6
  @@ -59,6 +59,7 @@
   import java.text.SimpleDateFormat;
   import java.util.Calendar;
   import java.util.Date;
  +import java.util.Locale;
   import java.util.TimeZone;
   
   /**
  @@ -94,6 +95,12 @@
       public static final String ISO8601_TIME_PATTERN
               = "HH:mm:ss";
   
  +    /**
  +     * Format used for SMTP (and probably other) Date headers.
  +     */
  +    public static final DateFormat DATE_HEADER_FORMAT
  +        = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss ", Locale.US);
  +
   
   // code from Magesh moved from DefaultLogger and slightly modified
       private static final MessageFormat MINUTE_SECONDS
  @@ -218,5 +225,35 @@
               epact++;
           }
           return (((((dayOfTheYear + epact) * 6) + 11) % 177) / 22) & 7;
  +    }
  +
  +    /**
  +     * Returns the current Date in a format suitable for a SMTP date
  +     * header.
  +     *
  +     * @since Ant 1.5.2
  +     */
  +    public static String getDateForHeader() {
  +        Calendar cal = Calendar.getInstance();
  +        TimeZone tz = cal.getTimeZone();
  +        int offset = tz.getOffset(cal.get(Calendar.ERA), 
  +                                  cal.get(Calendar.YEAR),
  +                                  cal.get(Calendar.MONTH),
  +                                  cal.get(Calendar.DAY_OF_MONTH),
  +                                  cal.get(Calendar.DAY_OF_WEEK),
  +                                  cal.get(Calendar.MILLISECOND));
  +        StringBuffer tzMarker = new StringBuffer(offset < 0 ? "-" : "+");
  +        offset = Math.abs(offset);
  +        int hours = offset / (60 * 60 * 1000);
  +        int minutes = offset / (60 * 1000) - 60 * hours;
  +        if (hours < 10) {
  +            tzMarker.append("0");
  +        }
  +        tzMarker.append(hours);
  +        if (minutes < 10) {
  +            tzMarker.append("0");
  +        }
  +        tzMarker.append(minutes);
  +        return DATE_HEADER_FORMAT.format(cal.getTime()) + tzMarker.toString();
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message