Search in sources :

Example 1 with AdaptedIterator

use of hudson.util.AdaptedIterator in project hudson-2.x by hudson.

the class AbstractBuild method getCulprits.

/**
 * List of users who committed a change since the last non-broken build till now.
 *
 * <p>
 * This list at least always include people who made changes in this build, but
 * if the previous build was a failure it also includes the culprit list from there.
 * Culprits of unstable build are also included
 * see <a href="http://issues.hudson-ci.org/browse/HUDSON-4617">HUDSON-4617</a> for details
 * @return
 *      can be empty but never null.
 */
@Exported
public Set<User> getCulprits() {
    if (culprits == null) {
        Set<User> r = new HashSet<User>();
        R p = getPreviousCompletedBuild();
        if (p != null && isBuilding()) {
            Result pr = p.getResult();
            if (pr != null && pr.isWorseOrEqualTo(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(p.getCulprits());
            }
        }
        for (Entry e : getChangeSet()) r.add(e.getAuthor());
        if (upstreamCulprits) {
            // If we have dependencies since the last successful build, add their authors to our list
            R previousBuild = getPreviousSuccessfulBuild();
            if (previousBuild != null) {
                Map<AbstractProject, AbstractBuild.DependencyChange> depmap = getDependencyChanges(previousBuild);
                for (AbstractBuild.DependencyChange dep : depmap.values()) {
                    for (AbstractBuild<?, ?> b : dep.getBuilds()) {
                        for (Entry entry : b.getChangeSet()) {
                            r.add(entry.getAuthor());
                        }
                    }
                }
            }
        }
        return r;
    }
    return new AbstractSet<User>() {

        public Iterator<User> iterator() {
            return new AdaptedIterator<String, User>(culprits.iterator()) {

                protected User adapt(String id) {
                    return User.get(id);
                }
            };
        }

        public int size() {
            return culprits.size();
        }
    };
}
Also used : AbstractSet(java.util.AbstractSet) AdaptedIterator(hudson.util.AdaptedIterator) Entry(hudson.scm.ChangeLogSet.Entry) HashSet(java.util.HashSet) Exported(org.kohsuke.stapler.export.Exported)

Aggregations

Entry (hudson.scm.ChangeLogSet.Entry)1 AdaptedIterator (hudson.util.AdaptedIterator)1 AbstractSet (java.util.AbstractSet)1 HashSet (java.util.HashSet)1 Exported (org.kohsuke.stapler.export.Exported)1