Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/main/java/org/jvnet/hudson/test/BuildWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package org.jvnet.hudson.test;

import hudson.Extension;
import hudson.console.AnnotatedLargeText;
import hudson.console.LineTransformationOutputStream;
import hudson.model.Run;
import hudson.model.TaskListener;
Expand Down Expand Up @@ -90,7 +89,7 @@ public final class BuildWatcher extends ExternalResource {
return;
}
RunningBuild build = new RunningBuild(r);
RunningBuild orig = builds.put(r.getLogFile(), build);
RunningBuild orig = builds.put(r.getRootDir(), build);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just needed a unique identifier of a build × $JENKINS_HOME; were not actually using the log file per se.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't help with ExternalTaskLogging story

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are referring to logging from non-Runs, that is true, but anyway BuildWatcher does not support them currently either.

if (orig != null) {
System.err.println(r + " was started twice?!");
}
Expand All @@ -100,7 +99,7 @@ public final class BuildWatcher extends ExternalResource {
if (!active) {
return;
}
RunningBuild build = builds.remove(r.getLogFile());
RunningBuild build = builds.remove(r.getRootDir());
if (build != null) {
build.copy();
} else {
Expand All @@ -112,18 +111,18 @@ public final class BuildWatcher extends ExternalResource {

private static final class RunningBuild {

private final AnnotatedLargeText<?> log;
private final Run<?,?> r;
private final OutputStream sink;
private long pos;

RunningBuild(Run<?,?> r) {
log = r.getLogText();
this.r = r;
sink = new LogLinePrefixOutputFilter(System.err, "[" + r + "] ");
}

synchronized void copy() {
try {
pos = log.writeLogTo(pos, sink);
pos = r.getLogText().writeLogTo(pos, sink);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this precedent. getLogText in general needs to be called repeatedly as more log output arrives.

// Note that !log.isComplete() after the initial call to copy, even if the build is complete, because Run.getLogText never calls markComplete!
// That is why Run.writeWholeLogTo calls getLogText repeatedly.
// Even if it did call markComplete this might not work from RestartableJenkinsRule since you would have a different Run object after the restart.
Expand Down