ASF Bugzilla – Attachment 17274 Details for
Bug 38029
Using mail logger with large builds (code attached)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
diff -u of patch to mail logger
MailLogger.diffs (text/plain), 5.88 KB, created by
omri spector
on 2005-12-24 17:55:46 UTC
(
hide
)
Description:
diff -u of patch to mail logger
Filename:
MIME Type:
Creator:
omri spector
Created:
2005-12-24 17:55:46 UTC
Size:
5.88 KB
patch
obsolete
>--- MailLogger.java.orig Thu Jun 02 15:19:00 2005 >+++ MailLogger.java Thu Dec 22 10:56:39 2005 >@@ -55,6 +55,8 @@ > * failed build</li> > * <li> MailLogger.success.subject [default: "Build Success"] - Subject of > * successful build</li> >+ * <li> MailLogger.body [default: ""] - Body of sent mail. If omitted, build >+ * log will be sent. Useful in conjunction with -logfile for very long builds.</li> > * </ul> > * These properties are set using standard Ant property setting mechanisms > * (<property>, command-line -D, etc). Ant properties can be overridden >@@ -67,6 +69,9 @@ > public class MailLogger extends DefaultLogger { > /** Buffer in which the message is constructed prior to sending */ > private StringBuffer buffer = new StringBuffer(); >+ >+ /** Properties used when configuring loader **/ >+ Hashtable properties; > > /** > * Sends an e-mail with the log results. >@@ -75,9 +80,48 @@ > */ > public void buildFinished(BuildEvent event) { > super.buildFinished(event); >+ boolean success = (event.getException() == null); >+ String prefix = success ? "success" : "failure"; >+ loadProperties(event.getProject()); >+ >+ try { >+ String fixedBody=getValue("body",""); >+ boolean notify = Project.toBoolean(getValue(prefix + ".notify", "on")); >+ >+ if (!notify) { >+ return; >+ } >+ >+ >+ String mailhost = getValue("mailhost", "localhost"); >+ int port = Integer.parseInt(getValue("port", >+ String.valueOf(MailMessage.DEFAULT_PORT))); >+ String user = getValue("user", ""); >+ String password = getValue("password", ""); >+ boolean ssl = Project.toBoolean(getValue( >+ "ssl", "off")); >+ String from = getValue("from", null); >+ String replytoList = getValue("replyto", ""); >+ String toList = getValue(prefix + ".to", null); >+ String subject = getValue(prefix + ".subject", >+ (success) ? "Build Success" : "Build Failure"); >+ String body=(fixedBody.length()==0? buffer.substring(0) : fixedBody); >+ if (user.equals("") && password.equals("") && !ssl) { >+ sendMail(mailhost, port, from, replytoList, toList, >+ subject, body); >+ } else { >+ sendMimeMail(event.getProject(), mailhost, port, user, >+ password, ssl, from, replytoList, toList, >+ subject, body); >+ } >+ } catch (Exception e) { >+ System.out.println("MailLogger failed to send e-mail!"); >+ e.printStackTrace(System.err); >+ } >+ } > >- Project project = event.getProject(); >- Hashtable properties = project.getProperties(); >+ private void loadProperties(Project project){ >+ properties = project.getProperties(); > > // overlay specified properties file (if any), which overrides project > // settings >@@ -106,52 +150,19 @@ > String value = fileProperties.getProperty(key); > properties.put(key, project.replaceProperties(value)); > } >- >- boolean success = (event.getException() == null); >- String prefix = success ? "success" : "failure"; >- >- try { >- boolean notify = Project.toBoolean(getValue(properties, >- prefix + ".notify", "on")); >- >- if (!notify) { >- return; >- } >- >- String mailhost = getValue(properties, "mailhost", "localhost"); >- int port = Integer.parseInt(getValue(properties, "port", >- String.valueOf(MailMessage.DEFAULT_PORT))); >- String user = getValue(properties, "user", ""); >- String password = getValue(properties, "password", ""); >- boolean ssl = Project.toBoolean(getValue(properties, >- "ssl", "off")); >- String from = getValue(properties, "from", null); >- String replytoList = getValue(properties, "replyto", ""); >- String toList = getValue(properties, prefix + ".to", null); >- String subject = getValue(properties, prefix + ".subject", >- (success) ? "Build Success" : "Build Failure"); >- if (user.equals("") && password.equals("") && !ssl) { >- sendMail(mailhost, port, from, replytoList, toList, >- subject, buffer.substring(0)); >- } else { >- sendMimeMail(event.getProject(), mailhost, port, user, >- password, ssl, from, replytoList, toList, >- subject, buffer.substring(0)); >- } >- } catch (Exception e) { >- System.out.println("MailLogger failed to send e-mail!"); >- e.printStackTrace(System.err); >- } > } > > >+ > /** > * Receives and buffers log messages. > * > * @param message the message being logger > */ > protected void log(String message) { >- buffer.append(message).append(StringUtils.LINE_SEP); >+ // it would have been nice to avoid this in "fixed body" mode, but sadly >+ // I could not get properties at buildStart event. >+ buffer.append(message).append(StringUtils.LINE_SEP); > } > > >@@ -167,7 +178,7 @@ > * @exception Exception thrown if no default value is specified and the > * property is not present in properties. > */ >- private String getValue(Hashtable properties, String name, >+ private String getValue(String name, > String defaultValue) throws Exception { > String propertyName = "MailLogger." + name; > String value = (String) properties.get(propertyName);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 38029
: 17274