public void buildFinished(BuildEvent event) {
super.buildFinished(event);
Project project = event.getProject();
Hashtable properties = project.getProperties();
// overlay specified properties file (if any), which overrides project
// settings
Properties fileProperties = new Properties();
String filename = (String) properties.get("MailLogger.properties.file");
if (filename != null) {
InputStream is = null;
try {
is = new FileInputStream(filename);
fileProperties.load(is);
} catch (IOException ioe) {
// ignore because properties file is not required
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// ignore
}
}
}
}
for (Enumeration e = fileProperties.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement();
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;
}
Values values = new Values()
.mailhost(getValue(properties, "mailhost", "localhost"))
.port(Integer.parseInt(
getValue(
properties, "port",
String.valueOf(MailMessage.DEFAULT_PORT))))
.user(getValue(properties, "user", ""))
.password(getValue(properties, "password", ""))
.ssl(Project.toBoolean(getValue(properties,
"ssl", "off")))
.from(getValue(properties, "from", null))
.replytoList(getValue(properties, "replyto", ""))
.toList(getValue(properties, prefix + ".to", null))
.subject(getValue(
properties, prefix + ".subject",
(success) ? "Build Success" : "Build Failure"));
if (values.user().equals("")
&& values.password().equals("")
&& !values.ssl()) {
sendMail(values, buffer.substring(0));
} else {
sendMimeMail(
event.getProject(), values, buffer.substring(0));
}
} catch (Exception e) {
System.out.println("MailLogger failed to send e-mail!");
e.printStackTrace(System.err);
}
}
Sends an e-mail with the log results. |