提交 16709852 编写于 作者: B brucechapman

[FIX HUDSON-2580] "Email Notification" action does not work as a Promotion plugin action

Cause: Mailer extends Publisher extends BuildStepCompatibilityLayer without
overriding BuildStepCompatibilityLayer's version of perform(AbstractBuild...)
therefore perform() does nothing except return true.

Fix: Override the new perform signature in Mailer.

Getting this to work involved removing a whole swag of pointless generics in
MailSender which doesn't actually care about the specific type of AbstractBuild
or AbstractProject so wildcards can be used, simplifying things quite a lot.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@14253 71c3de6d-444a-0410-be80-ed276b4c234a
上级 055b1ce3
......@@ -27,7 +27,7 @@ public class MavenMailer extends MavenReporter {
public boolean sendToIndividuals;
public boolean end(MavenBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
new MailSender<MavenModule,MavenBuild>(recipients,dontNotifyEveryUnstableBuild,sendToIndividuals).execute(build,listener);
new MailSender(recipients,dontNotifyEveryUnstableBuild,sendToIndividuals).execute(build,listener);
return true;
}
......
......@@ -31,7 +31,7 @@ import java.util.regex.Pattern;
* @author Jesse Glick
* @author Kohsuke Kawaguchi
*/
public class MailSender<P extends AbstractProject<P, B>, B extends AbstractBuild<P, B>> {
public class MailSender {
/**
* Whitespace-separated list of e-mail addresses that represent recipients.
*/
......@@ -54,13 +54,13 @@ public class MailSender<P extends AbstractProject<P, B>, B extends AbstractBuild
this.sendToIndividuals = sendToIndividuals;
}
public boolean execute(B build, BuildListener listener) throws InterruptedException {
public boolean execute(AbstractBuild<?, ?> build, BuildListener listener) throws InterruptedException {
try {
MimeMessage mail = getMail(build, listener);
if (mail != null) {
// if the previous e-mail was sent for a success, this new e-mail
// is not a follow up
B pb = build.getPreviousBuild();
AbstractBuild<?, ?> pb = build.getPreviousBuild();
if(pb!=null && pb.getResult()==Result.SUCCESS) {
mail.removeHeader("In-Reply-To");
mail.removeHeader("References");
......@@ -86,13 +86,13 @@ public class MailSender<P extends AbstractProject<P, B>, B extends AbstractBuild
return true;
}
protected MimeMessage getMail(B build, BuildListener listener) throws MessagingException, InterruptedException {
protected MimeMessage getMail(AbstractBuild<?, ?> build, BuildListener listener) throws MessagingException, InterruptedException {
if (build.getResult() == Result.FAILURE) {
return createFailureMail(build, listener);
}
if (build.getResult() == Result.UNSTABLE) {
B prev = build.getPreviousBuild();
AbstractBuild<?, ?> prev = build.getPreviousBuild();
if (!dontNotifyEveryUnstableBuild)
return createUnstableMail(build, listener);
if (prev != null) {
......@@ -102,7 +102,7 @@ public class MailSender<P extends AbstractProject<P, B>, B extends AbstractBuild
}
if (build.getResult() == Result.SUCCESS) {
B prev = build.getPreviousBuild();
AbstractBuild<?, ?> prev = build.getPreviousBuild();
if (prev != null) {
if (prev.getResult() == Result.FAILURE)
return createBackToNormalMail(build, "normal", listener);
......@@ -114,7 +114,7 @@ public class MailSender<P extends AbstractProject<P, B>, B extends AbstractBuild
return null;
}
private MimeMessage createBackToNormalMail(B build, String subject, BuildListener listener) throws MessagingException {
private MimeMessage createBackToNormalMail(AbstractBuild<?, ?> build, String subject, BuildListener listener) throws MessagingException {
MimeMessage msg = createEmptyMail(build, listener);
msg.setSubject(getSubject(build, "Hudson build is back to " + subject + ": "),"UTF-8");
......@@ -125,12 +125,12 @@ public class MailSender<P extends AbstractProject<P, B>, B extends AbstractBuild
return msg;
}
private MimeMessage createUnstableMail(B build, BuildListener listener) throws MessagingException {
private MimeMessage createUnstableMail(AbstractBuild<?, ?> build, BuildListener listener) throws MessagingException {
MimeMessage msg = createEmptyMail(build, listener);
String subject = "Hudson build is unstable: ";
B prev = build.getPreviousBuild();
AbstractBuild<?, ?> prev = build.getPreviousBuild();
if(prev!=null) {
if(prev.getResult()==Result.SUCCESS)
subject = "Hudson build became unstable: ";
......@@ -146,14 +146,14 @@ public class MailSender<P extends AbstractProject<P, B>, B extends AbstractBuild
return msg;
}
private void appendBuildUrl(B build, StringBuffer buf) {
private void appendBuildUrl(AbstractBuild<?, ?> build, StringBuffer buf) {
String baseUrl = Mailer.DESCRIPTOR.getUrl();
if (baseUrl != null) {
buf.append("See ").append(baseUrl).append(Util.encode(build.getUrl())).append("changes\n\n");
}
}
private MimeMessage createFailureMail(B build, BuildListener listener) throws MessagingException, InterruptedException {
private MimeMessage createFailureMail(AbstractBuild<?, ?> build, BuildListener listener) throws MessagingException, InterruptedException {
MimeMessage msg = createEmptyMail(build, listener);
msg.setSubject(getSubject(build, "Build failed in Hudson: "),"UTF-8");
......@@ -236,7 +236,7 @@ public class MailSender<P extends AbstractProject<P, B>, B extends AbstractBuild
return msg;
}
private MimeMessage createEmptyMail(B build, BuildListener listener) throws MessagingException {
private MimeMessage createEmptyMail(AbstractBuild<?, ?> build, BuildListener listener) throws MessagingException {
MimeMessage msg = new MimeMessage(Mailer.DESCRIPTOR.createSession());
// TODO: I'd like to put the URL to the page in here,
// but how do I obtain that?
......@@ -267,7 +267,7 @@ public class MailSender<P extends AbstractProject<P, B>, B extends AbstractBuild
}
msg.setRecipients(Message.RecipientType.TO, rcp.toArray(new InternetAddress[rcp.size()]));
B pb = build.getPreviousBuild();
AbstractBuild<?, ?> pb = build.getPreviousBuild();
if(pb!=null) {
MailMessageIdAction b = pb.getAction(MailMessageIdAction.class);
if(b!=null) {
......@@ -279,14 +279,14 @@ public class MailSender<P extends AbstractProject<P, B>, B extends AbstractBuild
return msg;
}
private String getSubject(B build, String caption) {
private String getSubject(AbstractBuild<?, ?> build, String caption) {
return caption + build.getProject().getFullDisplayName() + " #" + build.getNumber();
}
/**
* Check whether a path (/-separated) will be archived.
*/
protected boolean artifactMatches(String path, B build) {
protected boolean artifactMatches(String path, AbstractBuild<?, ?> build) {
return false;
}
......
......@@ -3,11 +3,11 @@ package hudson.tasks;
import hudson.Launcher;
import hudson.Functions;
import hudson.maven.AbstractMavenProject;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Build;
import hudson.model.BuildListener;
import hudson.model.Descriptor;
import hudson.model.Project;
import hudson.model.User;
import hudson.model.UserPropertyDescriptor;
import hudson.util.FormFieldValidator;
......@@ -67,18 +67,14 @@ public class Mailer extends Publisher {
private transient String subject;
private transient boolean failureOnly;
public boolean perform(Build build, Launcher launcher, BuildListener listener) throws InterruptedException {
return _perform(build,launcher,listener);
}
public <P extends Project<P,B>,B extends Build<P,B>> boolean _perform(B build, Launcher launcher, BuildListener listener) throws InterruptedException {
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException {
if(debug)
listener.getLogger().println("Running mailer");
return new MailSender<P,B>(recipients,dontNotifyEveryUnstableBuild,sendToIndividuals) {
return new MailSender(recipients,dontNotifyEveryUnstableBuild,sendToIndividuals) {
/** Check whether a path (/-separated) will be archived. */
@Override
public boolean artifactMatches(String path, B build) {
ArtifactArchiver aa = (ArtifactArchiver) build.getProject().getPublishers().get(ArtifactArchiver.DESCRIPTOR);
public boolean artifactMatches(String path, AbstractBuild<?,?> build) {
ArtifactArchiver aa = (ArtifactArchiver) build.getProject().getPublishersList().toMap().get(ArtifactArchiver.DESCRIPTOR);
if (aa == null) {
LOGGER.finer("No ArtifactArchiver found");
return false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册