Skip to content

Commit

Permalink
Merge pull request #908 from jglick/stderr
Browse files Browse the repository at this point in the history
Use stderr rather than stdout for `RealJenkinsRule` & `TailLog`
  • Loading branch information
jglick authored Jan 24, 2025
2 parents 8235962 + 5442d6e commit f1281ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/main/java/org/jvnet/hudson/test/RealJenkinsRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ public static List<String> getJacocoAgentOptions() {
this.description = description;
return new Statement() {
@Override public void evaluate() throws Throwable {
System.out.println("=== Starting " + description);
System.err.println("=== Starting " + description);
try {
jenkinsOptions("--webroot=" + createTempDirectory("webroot"), "--pluginroot=" + createTempDirectory("pluginroot"));
if (war == null) {
Expand Down Expand Up @@ -649,7 +649,7 @@ private void provision() throws Exception {
Files.copy(snapshotManifest, plugins.toPath().resolve(shortName + ".jpl"));
snapshotPlugins.add(shortName);
} else {
System.out.println("Warning: found " + indexJelly + " but did not find corresponding ../test-classes/the.[hj]pl");
System.err.println("Warning: found " + indexJelly + " but did not find corresponding ../test-classes/the.[hj]pl");
}
} else {
// Do not warn about the common case of jar:file:/**/.m2/repository/**/*.jar!/index.jelly
Expand Down Expand Up @@ -706,7 +706,7 @@ private void provision() throws Exception {
for (SyntheticPlugin syntheticPlugin : syntheticPlugins) {
syntheticPlugin.writeTo(new File(plugins, syntheticPlugin.shortName + ".jpi"), targetJenkinsVersion);
}
System.out.println("Will load plugins: " + Stream.of(plugins.list()).filter(n -> n.matches(".+[.][hj]p[il]")).sorted().collect(Collectors.joining(" ")));
System.err.println("Will load plugins: " + Stream.of(plugins.list()).filter(n -> n.matches(".+[.][hj]p[il]")).sorted().collect(Collectors.joining(" ")));
}

/**
Expand Down Expand Up @@ -1013,14 +1013,14 @@ public void startJenkins() throws Throwable {
}
}
// TODO escape spaces like Launcher.printCommandLine, or LabelAtom.escape (beware that QuotedStringTokenizer.quote(String) Javadoc is untrue):
System.out.println(env.entrySet().stream().map(Map.Entry::toString).collect(Collectors.joining(" ")) + " " + String.join(" ", argv));
System.err.println(env.entrySet().stream().map(Map.Entry::toString).collect(Collectors.joining(" ")) + " " + String.join(" ", argv));
ProcessBuilder pb = new ProcessBuilder(argv);
pb.environment().putAll(env);
// TODO options to set Winstone options, etc.
// TODO pluggable launcher interface to support a Dockerized Jenkins JVM
pb.redirectErrorStream(true);
proc = pb.start();
new StreamCopyThread(description.toString(), proc.getInputStream(), prefixedOutputStreamBuilder.build(System.out)).start();
new StreamCopyThread(description.toString(), proc.getInputStream(), prefixedOutputStreamBuilder.build(System.err)).start();
int tries = 0;
while (true) {
if (!proc.isAlive()) {
Expand All @@ -1038,7 +1038,7 @@ public void startJenkins() throws Throwable {

String checkResult = checkResult(conn);
if (checkResult == null) {
System.out.println((getName() != null ? getName() : "Jenkins") + " is running at " + getUrl());
System.err.println((getName() != null ? getName() : "Jenkins") + " is running at " + getUrl());
break;
}else {
throw new IOException("Response code " + conn.getResponseCode() + " for " + status + ": " + checkResult +
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jvnet/hudson/test/TailLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ public TailLog(File buildDirectory, String job, int number) {
@Override
public void handle(String line) {
if (ps == null) {
ps = new PrintStream(new PlainTextConsoleOutputStream(prefixedOutputStreamBuilder.withName(job + '#' + number).build(System.out)), false, StandardCharsets.UTF_8);
ps = new PrintStream(new PlainTextConsoleOutputStream(prefixedOutputStreamBuilder.withName(job + '#' + number).build(System.err)), false, StandardCharsets.UTF_8);
}
synchronized (System.out) {
synchronized (System.err) {
ps.append(DeltaSupportLogFormatter.elapsedTime());
ps.print(' ');
ps.print(line);
Expand Down

0 comments on commit f1281ba

Please sign in to comment.