diff --git a/core/src/main/java/hudson/matrix/MatrixBuild.java b/core/src/main/java/hudson/matrix/MatrixBuild.java index a9a6261434..efaffaf1ac 100644 --- a/core/src/main/java/hudson/matrix/MatrixBuild.java +++ b/core/src/main/java/hudson/matrix/MatrixBuild.java @@ -1,11 +1,6 @@ package hudson.matrix; -import hudson.model.AbstractBuild; -import hudson.model.BuildListener; -import hudson.model.Result; -import hudson.model.Executor; -import hudson.model.Hudson; -import hudson.model.Queue; +import hudson.model.*; import hudson.tasks.Publisher; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; @@ -13,11 +8,10 @@ import org.kohsuke.stapler.StaplerResponse; import java.io.File; import java.io.IOException; import java.io.PrintStream; +import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; import java.util.List; -import java.util.ArrayList; -import java.util.logging.Logger; /** * Build of {@link MatrixProject}. @@ -141,7 +135,7 @@ public class MatrixBuild extends AbstractBuild { } } - public void post(BuildListener listener) throws IOException, InterruptedException { + public void post2(BuildListener listener) throws Exception { for (MatrixAggregator a : aggregators) a.endBuild(); } diff --git a/core/src/main/java/hudson/maven/MavenBuild.java b/core/src/main/java/hudson/maven/MavenBuild.java index fbbe6e60b6..0b1b84574f 100644 --- a/core/src/main/java/hudson/maven/MavenBuild.java +++ b/core/src/main/java/hudson/maven/MavenBuild.java @@ -343,7 +343,7 @@ public class MavenBuild extends AbstractBuild { } } - public void post(BuildListener listener) throws IOException, InterruptedException { + public void post2(BuildListener listener) throws Exception { for (MavenReporter reporter : reporters) reporter.end(MavenBuild.this,launcher,listener); diff --git a/core/src/main/java/hudson/maven/MavenModuleSetBuild.java b/core/src/main/java/hudson/maven/MavenModuleSetBuild.java index 1108861f70..6a9d3a8350 100644 --- a/core/src/main/java/hudson/maven/MavenModuleSetBuild.java +++ b/core/src/main/java/hudson/maven/MavenModuleSetBuild.java @@ -330,7 +330,7 @@ public final class MavenModuleSetBuild extends AbstractBuild,R extends Abs */ private volatile transient ChangeLogSet changeSet; + /** + * Cumulative list of people who contributed to the build problem. + * + *

+ * This is a list of {@link User#getId() user ids} who made a change + * since the last non-broken build. Can be null (which should be + * treated like empty set), because of the compatibility. + * + *

+ * This field is semi-final --- once set the value will never be modified. + * + * @since 1.137 + */ + private volatile Set culprits; + protected AbstractBuild(P job) throws IOException { super(job); } @@ -99,6 +110,46 @@ public abstract class AbstractBuild

,R extends Abs return builtOn; } + /** + * List of users who committed a change since the last non-broken build till now. + * + *

+ * This + * + * @return + * can be empty but never null. + */ + @Exported + public Set getCulprits() { + if(culprits==null) { + Set r = new HashSet(); + if(getPreviousBuild()!=null && isBuilding() && getPreviousBuild().getResult().isWorseThan(Result.UNSTABLE)) { + // we are still building, so this is just the current latest information, + // but we seems to be failing so far, so inherit culprits from the previous build. + // isBuilding() check is to avoid recursion when loading data from old Hudson, which doesn't record + // this information + r.addAll(getPreviousBuild().getCulprits()); + } + for( Entry e : getChangeSet() ) + r.add(e.getAuthor()); + return r; + } + + return new AbstractSet() { + public Iterator iterator() { + return new AdaptedIterator(culprits.iterator()) { + protected User adapt(String id) { + return User.get(id); + } + }; + } + + public int size() { + return culprits.size(); + } + }; + } + protected abstract class AbstractRunner implements Runner { /** * Since configuration can be changed while a build is in progress, @@ -180,6 +231,23 @@ public abstract class AbstractBuild

,R extends Abs * Return a non-null value to abort the build right there with the specified result code. */ protected abstract Result doRun(BuildListener listener) throws Exception; + + /** + * @see #post(BuildListener) + */ + protected abstract void post2(BuildListener listener) throws Exception; + + public final void post(BuildListener listener) throws Exception { + try { + post2(listener); + } finally { + // update the culprit list + HashSet r = new HashSet(); + for (User u : getCulprits()) + r.add(u.getId()); + culprits = r; + } + } } /** diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index f500235b45..246253a25c 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -71,8 +71,6 @@ public abstract class AbstractProject

,R extends A */ private Integer quietPeriod = null; - public transient Set culprits; - /** * If this project is configured to be only built on a certain label, * this value will be set to that label. diff --git a/core/src/main/java/hudson/model/Build.java b/core/src/main/java/hudson/model/Build.java index af4f7410c3..362bbd6683 100644 --- a/core/src/main/java/hudson/model/Build.java +++ b/core/src/main/java/hudson/model/Build.java @@ -136,7 +136,7 @@ public abstract class Build

,B extends Build> return null; } - public void post(BuildListener listener) throws IOException, InterruptedException { + public void post2(BuildListener listener) throws IOException, InterruptedException { // run all of them even if one of them failed for( Publisher bs : project.getPublishers().values() ) bs.perform(Build.this, launcher, listener); diff --git a/core/src/main/java/hudson/tasks/MailSender.java b/core/src/main/java/hudson/tasks/MailSender.java index cc7c9e96e4..44018e64cc 100644 --- a/core/src/main/java/hudson/tasks/MailSender.java +++ b/core/src/main/java/hudson/tasks/MailSender.java @@ -2,13 +2,8 @@ package hudson.tasks; import hudson.FilePath; import hudson.Util; -import hudson.model.AbstractBuild; -import hudson.model.AbstractProject; -import hudson.model.BuildListener; -import hudson.model.Result; -import hudson.model.User; +import hudson.model.*; import hudson.scm.ChangeLogSet; -import hudson.scm.ChangeLogSet.Entry; import javax.mail.Address; import javax.mail.Message; @@ -21,7 +16,6 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.util.Date; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; import java.util.StringTokenizer; @@ -117,9 +111,6 @@ public class MailSender

, B extends AbstractBuild appendBuildUrl(build, buf); msg.setText(buf.toString()); - // Reset the list of culprits - build.getProject().culprits.clear(); - return msg; } @@ -245,20 +236,12 @@ public class MailSender

, B extends AbstractBuild while (tokens.hasMoreTokens()) rcp.add(new InternetAddress(tokens.nextToken())); if (sendToIndividuals) { - if(debug) { - int count = 0; - for (Entry cs : build.getChangeSet()) count++; - listener.getLogger().println("Trying to send e-mails to individuals who broke the build. sizeof(changeset)=="+count); - } + Set culprits = build.getCulprits(); - if (build.getProject().culprits == null) - build.getProject().culprits = new HashSet(); + if(debug) + listener.getLogger().println("Trying to send e-mails to individuals who broke the build. sizeof(culprits)=="+culprits.size()); - for (Entry change : build.getChangeSet()) { - build.getProject().culprits.add(change.getAuthor()); - } - - for (User a : build.getProject().culprits) { + for (User a : culprits) { String adrs = Util.fixEmpty(a.getProperty(Mailer.UserProperty.class).getAddress()); if(debug) listener.getLogger().println(" User "+a.getId()+" -> "+adrs);