Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-19454] - Added DecoratedLauncher implementation to the…
… core.

This launcher Allows subclasses to only implement methods they want to override.
Originally, this launcher has been implemented in Custom Tools Plugin, but there are many duplicates in other plugins => it would be useful to have it in Jenkins core.

Resolves https://issues.jenkins-ci.org/browse/JENKINS-19454

Signed-off-by: Oleg Nenashev <nenashev@synopsys.com>
(cherry picked from commit a865a52)
  • Loading branch information
oleg-nenashev authored and olivergondza committed Jul 3, 2014
1 parent db26457 commit 56f1ee4
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions core/src/main/java/hudson/Launcher.java
Expand Up @@ -977,6 +977,88 @@ public OutputStream getStdin() {
}
}
}

/**
* A launcher which delegates to a provided inner launcher.
* Allows subclasses to only implement methods they want to override.
* Originally, this launcher has been implemented in
* <a href="https://wiki.jenkins-ci.org/display/JENKINS/Custom+Tools+Plugin">
* Custom Tools Plugin</a>.
*
* @author rcampbell
* @author Oleg Nenashev, Synopsys Inc.
* @since TODO: define version
*/
public static class DecoratedLauncher extends Launcher {

private Launcher inner = null;

public DecoratedLauncher(Launcher inner) {
super(inner);
this.inner = inner;
}

@Override
public Proc launch(ProcStarter starter) throws IOException {
return inner.launch(starter);
}

@Override
public Channel launchChannel(String[] cmd, OutputStream out,
FilePath workDir, Map<String, String> envVars) throws IOException,
InterruptedException {
return inner.launchChannel(cmd, out, workDir, envVars);
}

@Override
public void kill(Map<String, String> modelEnvVars) throws IOException,
InterruptedException {
inner.kill(modelEnvVars);
}

@Override
public boolean isUnix() {
return inner.isUnix();
}

@Override
public Proc launch(String[] cmd, boolean[] mask, String[] env, InputStream in, OutputStream out, FilePath workDir) throws IOException {
return inner.launch(cmd, mask, env, in, out, workDir);
}

@Override
public Computer getComputer() {
return inner.getComputer();
}

@Override
public TaskListener getListener() {
return inner.getListener();
}

@Override
public String toString() {
return super.toString() + "; decorates " + inner.toString();
}

@Override
public VirtualChannel getChannel() {
return inner.getChannel();
}

@Override
public Proc launch(String[] cmd, String[] env, InputStream in, OutputStream out, FilePath workDir) throws IOException {
return inner.launch(cmd, env, in, out, workDir);
}

/**
* Gets nested launcher.
* @return Inner launcher
*/
public Launcher getInner() {
return inner;
}
}

public static class IOTriplet implements Serializable {
InputStream stdout,stderr;
Expand Down

3 comments on commit 56f1ee4

@oleg-nenashev
Copy link
Member Author

Choose a reason for hiding this comment

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

@olivergondza
I'm quite aware of this class back-porting.
I suppose it is required for JENKINS-20559 only

@olivergondza
Copy link
Member

Choose a reason for hiding this comment

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

I will @Restrict new public api members such as this one once I am done backporting. I prefer this than backporting fix without its test. Or is there a problem I do not see?

@oleg-nenashev
Copy link
Member Author

Choose a reason for hiding this comment

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

No, there's no other problems
Thanks for the backporting

Please sign in to comment.