Skip to content

Commit

Permalink
[JENKINS-30777] Generalized the signature to work with Run, not just …
Browse files Browse the repository at this point in the history
…AbstractBuild.
  • Loading branch information
kohsuke committed Oct 2, 2015
1 parent 11c795c commit 36eea3d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
42 changes: 41 additions & 1 deletion core/src/main/java/hudson/console/ConsoleLogFilter.java
Expand Up @@ -26,7 +26,14 @@

import hudson.ExtensionList;
import hudson.ExtensionPoint;
import hudson.FilePath;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.Build;
import hudson.model.Job;
import hudson.model.Node;
import hudson.model.Run;
import hudson.scm.SCM;
import hudson.tasks.BuildWrapper;
import hudson.util.ArgumentListBuilder;
import jenkins.model.Jenkins;
Expand All @@ -48,8 +55,41 @@ public abstract class ConsoleLogFilter implements ExtensionPoint {
/**
* Called on the start of each build, giving extensions a chance to intercept
* the data that is written to the log.
*
* @deprecated as of 1.630. Use {@link #decorateLogger(Run, OutputStream)}
*/
public abstract OutputStream decorateLogger(AbstractBuild build, OutputStream logger) throws IOException, InterruptedException;
public OutputStream decorateLogger(AbstractBuild build, OutputStream logger) throws IOException, InterruptedException {
if (Util.isOverridden(ConsoleLogFilter.class, getClass(), "decorateLogger", Run.class, OutputStream.class)) {
// old client calling newer implementation. forward the call.
return decorateLogger((Run) build, logger);
} else {
// happens only if the subtype fails to override neither decorateLogger method
throw new AssertionError("The plugin '" + this.getClass().getName() + "' still uses " +
"deprecated decorateLogger(AbstractBuild,OutputStream) method. " +
"Update the plugin to use setUp(Run,OutputStream) instead.");
}
}

/**
* Called on the start of each build, giving extensions a chance to intercept
* the data that is written to the log.
*
* <p>
* Even though this method is not marked 'abstract', this is the method that must be overridden
* by extensions.
*/
public OutputStream decorateLogger(Run build, OutputStream logger) throws IOException, InterruptedException {
// this implementation is backward compatibility thunk in case subtypes only override the
// old signature (AbstractBuild,OutputStream)

if (build instanceof AbstractBuild) {
// maybe the plugin implements the old signature.
return decorateLogger((AbstractBuild) build, logger);
} else {
// this ConsoleLogFilter can only decorate AbstractBuild, so just pass through
return logger;
}
}

/**
* All the registered {@link ConsoleLogFilter}s.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/Run.java
Expand Up @@ -1710,7 +1710,7 @@ protected final void execute(@Nonnull RunExecution job) {

// Global log filters
for (ConsoleLogFilter filter : ConsoleLogFilter.all()) {
logger = filter.decorateLogger((AbstractBuild) build, logger);
logger = filter.decorateLogger(build, logger);
}

// Project specific log filters
Expand Down

1 comment on commit 36eea3d

@jglick
Copy link
Member

@jglick jglick commented on 36eea3d Sep 5, 2018

Choose a reason for hiding this comment

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

Please sign in to comment.