Skip to content
Closed
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions core/src/main/java/hudson/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Proc.LocalProc;
import hudson.model.BuildListener;
import hudson.model.Computer;
import hudson.model.Run;
import hudson.util.QuotedStringTokenizer;
import jenkins.model.Jenkins;
import hudson.model.TaskListener;
Expand Down Expand Up @@ -807,6 +809,22 @@ public final Launcher decorateFor(@Nonnull Node node) {
return l;
}

/**
* Returns a decorated {@link Launcher} for the given {@link hudson.model.Run}.
*
* @param run Run for which this launcher is created.
* @param listener Task listener
* @return Decorated instance of the Launcher.
* @since TODO
*/
@Nonnull
public final Launcher decorateFor(@Nonnull Run run, @Nonnull BuildListener listener) {
Launcher l = this;
for (LauncherDecorator d : LauncherDecorator.all())
l = d.decorate(l, run, listener);
return l;
}

/**
* Returns a decorated {@link Launcher} that puts the given set of arguments as a prefix to any commands
* that it invokes.
Expand Down
20 changes: 19 additions & 1 deletion core/src/main/java/hudson/LauncherDecorator.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package hudson;

import hudson.model.BuildListener;
import hudson.model.Node;
import hudson.model.Executor;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.tasks.BuildWrapper;
import javax.annotation.Nonnull;

Expand Down Expand Up @@ -40,7 +43,22 @@ public abstract class LauncherDecorator implements ExtensionPoint {
* @see Launcher#decorateByPrefix(String[])
*/
@Nonnull
public abstract Launcher decorate(@Nonnull Launcher launcher, @Nonnull Node node);
public Launcher decorate(@Nonnull Launcher launcher, @Nonnull Node node) {
return launcher;
}

/**
* Decorates Launcher by Run
* @param launcher Launcher to be decorated
* @param run Run
* @param listener Event Listener
* @return Decorated launcher or the passed launcher if not documented
* @since TODO
*/
@Nonnull
public Launcher decorate(@Nonnull Launcher launcher, @Nonnull Run run, BuildListener listener) {
return launcher;
}

/**
* Returns all the registered {@link LauncherDecorator}s.
Expand Down
73 changes: 40 additions & 33 deletions core/src/main/java/hudson/model/AbstractBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,43 @@ public String getHudsonVersion() {
return hudsonVersion;
}

@Override
protected Launcher createLauncher(@Nonnull Node node, @Nonnull BuildListener listener)
throws IOException, InterruptedException {
Launcher l = super.createLauncher(node, listener);

if (project instanceof BuildableItemWithBuildWrappers) {
BuildableItemWithBuildWrappers biwbw = (BuildableItemWithBuildWrappers) project;
for (BuildWrapper bw : biwbw.getBuildWrappersList())
l = bw.decorateLauncher(AbstractBuild.this,l,listener);
}

buildEnvironments = new ArrayList<Environment>();

for (RunListener rl: RunListener.all()) {
Environment environment = rl.setUpEnvironment(AbstractBuild.this, l, listener);
if (environment != null) {
buildEnvironments.add(environment);
}
}

for (NodeProperty nodeProperty: Jenkins.getInstance().getGlobalNodeProperties()) {
Environment environment = nodeProperty.setUp(AbstractBuild.this, l, listener);
if (environment != null) {
buildEnvironments.add(environment);
}
}

for (NodeProperty nodeProperty: node.getNodeProperties()) {
Environment environment = nodeProperty.setUp(AbstractBuild.this, l, listener);
if (environment != null) {
buildEnvironments.add(environment);
}
}

return l;
}

/**
* @deprecated as of 1.467
* Please use {@link hudson.model.Run.RunExecution}
Expand Down Expand Up @@ -518,6 +555,8 @@ public Result run(@Nonnull BuildListener listener) throws Exception {
return result;
}



Copy link
Member

Choose a reason for hiding this comment

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

revert

/**
* Creates a {@link Launcher} that this build will use. This can be overridden by derived types
* to decorate the resulting {@link Launcher}.
Expand All @@ -527,39 +566,7 @@ public Result run(@Nonnull BuildListener listener) throws Exception {
*/
@Nonnull
protected Launcher createLauncher(@Nonnull BuildListener listener) throws IOException, InterruptedException {
final Node currentNode = getCurrentNode();
Launcher l = currentNode.createLauncher(listener);

if (project instanceof BuildableItemWithBuildWrappers) {
BuildableItemWithBuildWrappers biwbw = (BuildableItemWithBuildWrappers) project;
for (BuildWrapper bw : biwbw.getBuildWrappersList())
l = bw.decorateLauncher(AbstractBuild.this,l,listener);
}

buildEnvironments = new ArrayList<Environment>();

for (RunListener rl: RunListener.all()) {
Environment environment = rl.setUpEnvironment(AbstractBuild.this, l, listener);
if (environment != null) {
buildEnvironments.add(environment);
}
}

for (NodeProperty nodeProperty: Jenkins.getInstance().getGlobalNodeProperties()) {
Environment environment = nodeProperty.setUp(AbstractBuild.this, l, listener);
if (environment != null) {
buildEnvironments.add(environment);
}
}

for (NodeProperty nodeProperty: currentNode.getNodeProperties()) {
Environment environment = nodeProperty.setUp(AbstractBuild.this, l, listener);
if (environment != null) {
buildEnvironments.add(environment);
}
}

return l;
return AbstractBuild.this.createLauncher(getCurrentNode(), listener);
}

public void defaultCheckout() throws IOException, InterruptedException {
Expand Down
22 changes: 22 additions & 0 deletions core/src/main/java/hudson/model/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import hudson.ExtensionPoint;
import hudson.FeedAdapter;
import hudson.Functions;
import hudson.Launcher;
import hudson.LauncherDecorator;
import hudson.console.AnnotatedLargeText;
import hudson.console.ConsoleLogFilter;
import hudson.console.ConsoleNote;
Expand All @@ -44,6 +46,8 @@
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.StandardOpenOption;

import hudson.slaves.NodeProperty;
import jenkins.util.SystemProperties;
import hudson.Util;
import hudson.XmlFile;
Expand Down Expand Up @@ -2579,6 +2583,24 @@ public Object getDynamic(String token, StaplerRequest req, StaplerResponse rsp)
return returnedResult;
}

/**
* Creates a {@link Launcher} that this build will use. This can be overridden by derived types
* to decorate the resulting {@link Launcher}.
*
* @param listener
* Always non-null. Connected to the main build output.
* @param node
* Node for which the launcher is created.
* @since TODO
*/
@Nonnull
protected Launcher createLauncher(@Nonnull Node node, @Nonnull BuildListener listener)
throws IOException, InterruptedException {
Launcher l = node.createLauncher(listener);
l.decorateFor(this, listener);
return l;
}

public static class RedirectUp {
public void doDynamic(StaplerResponse rsp) throws IOException {
// Compromise to handle both browsers (auto-redirect) and programmatic access
Expand Down