From ba67cdd1ad75c9a5b7c7a6b71192a38179329e28 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Mon, 27 Jul 2009 23:05:16 +0000 Subject: [PATCH] Generalized ParametersAction so that this benefits other plugins, too. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@20201 71c3de6d-444a-0410-be80-ed276b4c234a --- .../main/java/hudson/model/AbstractBuild.java | 7 ++- .../model/EnvironmentContributingAction.java | 52 +++++++++++++++++++ .../java/hudson/model/ParametersAction.java | 5 +- 3 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 core/src/main/java/hudson/model/EnvironmentContributingAction.java diff --git a/core/src/main/java/hudson/model/AbstractBuild.java b/core/src/main/java/hudson/model/AbstractBuild.java index 3d0d72021f..63adc697f4 100644 --- a/core/src/main/java/hudson/model/AbstractBuild.java +++ b/core/src/main/java/hudson/model/AbstractBuild.java @@ -465,10 +465,9 @@ public abstract class AbstractBuild

,R extends Abs for (Environment e : buildEnvironments) e.buildEnvVars(env); - ParametersAction parameters = getAction(ParametersAction.class); - if (parameters != null) - parameters.buildEnvVars(this,env); - + for (EnvironmentContributingAction a : Util.filter(getActions(),EnvironmentContributingAction.class)) + a.buildEnvVars(this,env); + EnvVars.resolve(env); return env; diff --git a/core/src/main/java/hudson/model/EnvironmentContributingAction.java b/core/src/main/java/hudson/model/EnvironmentContributingAction.java new file mode 100644 index 0000000000..369a7a9f57 --- /dev/null +++ b/core/src/main/java/hudson/model/EnvironmentContributingAction.java @@ -0,0 +1,52 @@ +/* + * The MIT License + * + * Copyright (c) 2004-2009, Sun Microsystems, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package hudson.model; + +import hudson.EnvVars; +import hudson.tasks.Builder; +import hudson.tasks.BuildWrapper; + +/** + * {@link Action} that contributes environment variables during a build. + * + * @author Kohsuke Kawaguchi + * @since 1.318 + * @see AbstractBuild#getEnvironment(TaskListener) + * @see BuildWrapper + */ +public interface EnvironmentContributingAction extends Action { + /** + * Called by {@link AbstractBuild} to allow plugins to contribute environment variables. + * + *

+ * For example, your {@link Builder} can add an {@link EnvironmentContributingAction} so that + * the rest of the builders or publishers see some behavior changes. + * + * @param build + * The calling build. Never null. + * @param env + * Evironment variables should be added to this map. + */ + public void buildEnvVars(AbstractBuild build, EnvVars env); +} diff --git a/core/src/main/java/hudson/model/ParametersAction.java b/core/src/main/java/hudson/model/ParametersAction.java index 2cefa7e354..50c83fabcf 100644 --- a/core/src/main/java/hudson/model/ParametersAction.java +++ b/core/src/main/java/hudson/model/ParametersAction.java @@ -24,6 +24,7 @@ package hudson.model; import hudson.Util; +import hudson.EnvVars; import hudson.model.Queue.QueueAction; import hudson.tasks.BuildStep; import hudson.tasks.BuildWrapper; @@ -49,7 +50,7 @@ import java.util.Set; * that were specified when scheduling. */ @ExportedBean -public class ParametersAction implements Action, Iterable, QueueAction { +public class ParametersAction implements Action, Iterable, QueueAction, EnvironmentContributingAction { private final List parameters; @@ -73,7 +74,7 @@ public class ParametersAction implements Action, Iterable, Queue } } - public void buildEnvVars(AbstractBuild build, Map env) { + public void buildEnvVars(AbstractBuild build, EnvVars env) { for (ParameterValue p : parameters) p.buildEnvVars(build,env); } -- GitLab