|
40 | 40 | import hudson.scm.SCM; |
41 | 41 | import hudson.util.AlternativeUiTextProvider; |
42 | 42 | import hudson.util.LogTaskListener; |
| 43 | +import hudson.util.StreamTaskListener; |
43 | 44 | import java.io.IOException; |
| 45 | +import java.io.StringWriter; |
44 | 46 | import java.util.Collections; |
45 | 47 | import java.util.HashSet; |
46 | 48 | import java.util.LinkedHashSet; |
@@ -974,15 +976,22 @@ public SCMRevision getTrustedRevision(@NonNull SCMRevision revision, @NonNull Ta |
974 | 976 | @NonNull |
975 | 977 | public final SCMRevision getTrustedRevisionForBuild(@NonNull SCMRevision revision, @NonNull TaskListener listener, @NonNull Run<?, ?> build) |
976 | 978 | throws IOException, InterruptedException { |
977 | | - if (ExtensionList.lookup(TrustworthyBuild.class).stream().anyMatch(tb -> tb.shouldBeTrusted(build, listener))) { |
| 979 | + // Cheaper to check TrustworthyBuild than to call some getTrustedRevision impls, so try that first, |
| 980 | + // but defer printing resulting messages if possible. |
| 981 | + StringWriter buffer = new StringWriter(); |
| 982 | + TaskListener bufferedListener = new StreamTaskListener(buffer); |
| 983 | + if (ExtensionList.lookup(TrustworthyBuild.class).stream().anyMatch(tb -> tb.shouldBeTrusted(build, bufferedListener))) { |
978 | 984 | LOGGER.fine(() -> build + " with " + build.getCauses() + " was considered trustworthy, so using " + revision + " as is"); |
| 985 | + listener.getLogger().print(buffer.toString()); |
979 | 986 | return revision; |
980 | 987 | } else { |
981 | 988 | SCMRevision trustedRevision = getTrustedRevision(revision, listener); |
982 | | - if (trustedRevision.equals(revision)) { |
983 | | - LOGGER.fine(() -> revision + " was trusted anyway so it is irrelevant that " + build + " was not specifically considered trustworthy"); |
| 989 | + if (trustedRevision.equals(revision)) { // common case |
| 990 | + LOGGER.fine(() -> revision + " was trusted anyway so it is irrelevant that " + build + " was not specifically considered trustworthy\n" + buffer); |
984 | 991 | } else { |
985 | 992 | LOGGER.fine(() -> build + " was not considered trustworthy, so replacing " + revision + " with " + trustedRevision); |
| 993 | + listener.getLogger().print(buffer.toString()); |
| 994 | + listener.getLogger().println(build + " was not considered trustworthy, so replacing " + revision + " with " + trustedRevision); |
986 | 995 | } |
987 | 996 | return trustedRevision; |
988 | 997 | } |
|
0 commit comments