Skip to content
Permalink
Browse files
[JENKINS-29537] Merged #2993: amended EnvironmentContributingAction s…
…ignature.
  • Loading branch information
jglick committed Aug 25, 2017
1 parent 12a949e commit b3e2ed8a37531d65e32d45070aaaae450e8af543
@@ -887,7 +887,7 @@ public EnvVars getEnvironment(TaskListener log) throws IOException, InterruptedE
e.buildEnvVars(env);

for (EnvironmentContributingAction a : getActions(EnvironmentContributingAction.class))
a.buildEnvVars(this,env,getBuiltOn());
a.buildEnvVars(this,env);

EnvVars.resolve(env);

@@ -31,7 +31,6 @@
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.ProtectedExternally;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

/**
@@ -46,23 +45,20 @@
*
* @author Kohsuke Kawaguchi
* @since 1.318
* @see AbstractBuild#getEnvironment(TaskListener)
* @see Run#getEnvironment(TaskListener)
* @see BuildWrapper
*/
public interface EnvironmentContributingAction extends Action {
/**
* Called by {@link Run} or {@link AbstractBuild} to allow plugins to contribute environment variables.
* Called by {@link Run} to allow plugins to contribute environment variables.
*
* @param run
* The calling build. Never null.
* @param node
* The node execute on. Can be {@code null} when the Run is not binded to the node,
* e.g. in Pipeline outside the {@code node() step}
* @param env
* Environment variables should be added to this map.
* @since TODO
* @since 2.76
*/
default void buildEnvVars(@Nonnull Run<?, ?> run, @Nonnull EnvVars env, @CheckForNull Node node) {
default void buildEnvironment(@Nonnull Run<?, ?> run, @Nonnull EnvVars env) {
if (run instanceof AbstractBuild
&& Util.isOverridden(EnvironmentContributingAction.class,
getClass(), "buildEnvVars", AbstractBuild.class, EnvVars.class)) {
@@ -73,7 +69,7 @@ default void buildEnvVars(@Nonnull Run<?, ?> run, @Nonnull EnvVars env, @CheckFo
/**
* Called by {@link AbstractBuild} to allow plugins to contribute environment variables.
*
* @deprecated Use {@link #buildEnvVars(Run, EnvVars, Node)} instead
* @deprecated Use {@link #buildEnvironment} instead
*
* @param build
* The calling build. Never null.
@@ -84,8 +80,8 @@ default void buildEnvVars(@Nonnull Run<?, ?> run, @Nonnull EnvVars env, @CheckFo
@Restricted(ProtectedExternally.class)
default void buildEnvVars(AbstractBuild<?, ?> build, EnvVars env) {
if (Util.isOverridden(EnvironmentContributingAction.class,
getClass(), "buildEnvVars", Run.class, EnvVars.class, Node.class)) {
buildEnvVars(build, env, build.getBuiltOn());
getClass(), "buildEnvironment", Run.class, EnvVars.class)) {
buildEnvironment(build, env);
}
}
}
@@ -139,7 +139,7 @@ public void createBuildWrappers(AbstractBuild<?,?> build, Collection<? super Bui
}

@Override
public void buildEnvVars(Run<?,?> run, EnvVars env, Node node) {
public void buildEnvironment(Run<?,?> run, EnvVars env) {
for (ParameterValue p : getParameters()) {
if (p == null) continue;
p.buildEnvironment(run, env);
@@ -2301,8 +2301,11 @@ public EnvVars getEnvironment() throws IOException, InterruptedException {
for (EnvironmentContributor ec : EnvironmentContributor.all().reverseView())
ec.buildEnvironmentFor(this,env,listener);

for (EnvironmentContributingAction a : getActions(EnvironmentContributingAction.class))
a.buildEnvVars(this,env,n);
if (!(this instanceof AbstractBuild)) {
for (EnvironmentContributingAction a : getActions(EnvironmentContributingAction.class)) {
a.buildEnvironment(this, env);
}
} // else for compatibility reasons, handled in override after buildEnvironments

return env;
}
@@ -3,7 +3,6 @@
import hudson.EnvVars;
import org.junit.Test;

import javax.annotation.CheckForNull;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
@@ -16,7 +15,7 @@
private boolean wasCalled = false;

@Override
public void buildEnvVars(Run<?, ?> run, EnvVars env, @CheckForNull Node node) {
public void buildEnvironment(Run<?, ?> run, EnvVars env) {
wasCalled = true;
}

@@ -50,7 +49,7 @@ public void buildEnvVars(AbstractBuild<?, ?> abstractBuild, EnvVars envVars) {
}

@Override
public void buildEnvVars(Run<?, ?> run, EnvVars env, @CheckForNull Node node) {
public void buildEnvironment(Run<?, ?> run, EnvVars env) {
wasCalledRun = true;
}

@@ -71,7 +70,7 @@ public void testOverrideRunMethodAndCallNewMethod() throws Exception {
Node node = mock(Node.class);

OverrideRun overrideRun = new OverrideRun();
overrideRun.buildEnvVars(run, envVars, node);
overrideRun.buildEnvironment(run, envVars);

assertTrue(overrideRun.wasNewMethodCalled());
}
@@ -99,10 +98,9 @@ public void testOverrideRunMethodAndCallDeprecatedMethod() throws Exception {
@Test
public void testOverrideAbstractBuildAndCallNewMethodWithAbstractBuild() throws Exception {
AbstractBuild abstractBuild = mock(AbstractBuild.class);
Node node = mock(Node.class);

OverrideAbstractBuild action = new OverrideAbstractBuild();
action.buildEnvVars(abstractBuild, envVars, node);
action.buildEnvironment(abstractBuild, envVars);

assertTrue(action.wasDeprecatedMethodCalled());
}
@@ -114,10 +112,9 @@ public void testOverrideAbstractBuildAndCallNewMethodWithAbstractBuild() throws
@Test
public void testOverrideAbstractBuildAndCallNewMethodWithRun() throws Exception {
Run run = mock(Run.class);
Node node = mock(Node.class);

OverrideAbstractBuild action = new OverrideAbstractBuild();
action.buildEnvVars(run, envVars, node);
action.buildEnvironment(run, envVars);

assertFalse(action.wasDeprecatedMethodCalled());
}
@@ -139,10 +136,9 @@ public void testOverrideAbstractBuildAndCallDeprecatedMethod() throws Exception
@Test
public void testOverrideBothAndCallNewMethod() throws Exception {
Run run = mock(Run.class);
Node node = mock(Node.class);

OverrideBoth overrideRun = new OverrideBoth();
overrideRun.buildEnvVars(run, envVars, node);
overrideRun.buildEnvironment(run, envVars);

assertTrue(overrideRun.wasRunCalled());
}
@@ -105,7 +105,7 @@ public void checkNullParameterValues() {

// Interaction with build
EnvVars vars = new EnvVars();
parametersAction.buildEnvVars(build, vars, build.getBuiltOn());
parametersAction.buildEnvironment(build, vars);
assertEquals(2, vars.size());
parametersAction.createVariableResolver(build);

@@ -155,7 +155,7 @@ private void setVariables(Node node, Entry... entries) throws IOException {
// use a timeout so we don't wait infinitely in case of failure
FreeStyleBuild build = project.scheduleBuild2(0).get(/*10, TimeUnit.SECONDS*/);

System.out.println(build.getLog());
System.out.println(build.getLog()); // TODO switch to BuildWatcher when converted to JenkinsRule
assertEquals(Result.SUCCESS, build.getResult());

return builder.getEnvVars();

0 comments on commit b3e2ed8

Please sign in to comment.