diff --git a/core/src/main/java/hudson/EnvVars.java b/core/src/main/java/hudson/EnvVars.java index 3c91cf4c89..071eb98d28 100644 --- a/core/src/main/java/hudson/EnvVars.java +++ b/core/src/main/java/hudson/EnvVars.java @@ -38,13 +38,27 @@ import java.util.UUID; * Environment variables. * *

+ * While all the platforms I tested (Linux 2.6, Solaris, and Windows XP) have the case sensitive + * environment variable table, Windows batch script handles environment variable in the case preserving + * but case insensitive way (that is, cmd.exe can get both FOO and foo as environment variables + * when it's launched, and the "set" command will display it accordingly, but "echo %foo%" results in + * echoing the value of "FOO", not "foo" — this is presumably caused by the behavior of the underlying + * Win32 API GetEnvironmentVariable acting in case insensitive way.) Windows users are also + * used to write environment variable case-insensitively (like %Path% vs %PATH%), and you can see many + * documents on the web that claims Windows environment variables are case insensitive. + * + *

+ * So for a consistent cross platform behavior, it creates the least confusion to make the table + * case insensitive but case preserving. + * + *

* In Hudson, often we need to build up "environment variable overrides" * on master, then to execute the process on slaves. This causes a problem * when working with variables like PATH. So to make this work, * we introduce a special convention PATH+FOO — all entries * that starts with PATH+ are merged and prepended to the inherited * PATH variable, on the process where a new process is executed. - * + * * @author Kohsuke Kawaguchi */ public class EnvVars extends TreeMap { @@ -80,6 +94,9 @@ public class EnvVars extends TreeMap { this((Map)m); } + /** + * Builds an environment variables from an array of the form "key","value","key","value"... + */ public EnvVars(String... keyValuePairs) { this(); if(keyValuePairs.length%2!=0) diff --git a/core/src/main/java/hudson/model/BooleanParameterValue.java b/core/src/main/java/hudson/model/BooleanParameterValue.java index f7a9909f76..6a03bcec84 100755 --- a/core/src/main/java/hudson/model/BooleanParameterValue.java +++ b/core/src/main/java/hudson/model/BooleanParameterValue.java @@ -23,6 +23,7 @@ */ package hudson.model; +import hudson.EnvVars; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.export.Exported; @@ -51,8 +52,8 @@ public class BooleanParameterValue extends ParameterValue { * Exposes the name/value as an environment variable. */ @Override - public void buildEnvVars(AbstractBuild build, Map env) { - env.put(name.toUpperCase(),Boolean.toString(value)); + public void buildEnvVars(AbstractBuild build, EnvVars env) { + env.put(name,Boolean.toString(value)); } @Override diff --git a/core/src/main/java/hudson/model/JobParameterValue.java b/core/src/main/java/hudson/model/JobParameterValue.java index ecf4eff60b..d2d4672e37 100644 --- a/core/src/main/java/hudson/model/JobParameterValue.java +++ b/core/src/main/java/hudson/model/JobParameterValue.java @@ -23,6 +23,7 @@ */ package hudson.model; +import hudson.EnvVars; import org.kohsuke.stapler.DataBoundConstructor; import java.util.Map; @@ -40,8 +41,8 @@ public class JobParameterValue extends ParameterValue { * Exposes the name/value as an environment variable. */ @Override - public void buildEnvVars(AbstractBuild build, Map env) { + public void buildEnvVars(AbstractBuild build, EnvVars env) { // TODO: check with Tom if this is really what he had in mind - env.put(name.toUpperCase(),job.toString()); + env.put(name,job.toString()); } } diff --git a/core/src/main/java/hudson/model/ParameterValue.java b/core/src/main/java/hudson/model/ParameterValue.java index c704813a59..742d1f5ba3 100644 --- a/core/src/main/java/hudson/model/ParameterValue.java +++ b/core/src/main/java/hudson/model/ParameterValue.java @@ -23,6 +23,9 @@ */ package hudson.model; +import hudson.EnvVars; +import hudson.Util; +import hudson.slaves.OfflineCause; import hudson.tasks.BuildWrapper; import hudson.tasks.Builder; import hudson.util.VariableResolver; @@ -109,18 +112,46 @@ public abstract class ParameterValue implements Serializable { * expected to add more values to this map (or do nothing) * *

- * Environment variables should be by convention all upper case. - * (This is so that a Windows/Unix heterogenous environment + * Environment variables should be by convention all upper case. + * (This is so that a Windows/Unix heterogeneous environment * won't get inconsistent result depending on which platform to - * execute.) + * execute.) (see {@link EnvVars} why upper casing is a bad idea.) + * + * @param env + * never null. + * @param build + * The build for which this parameter is being used. Never null. + * @deprecated as of 1.344 + * Use {@link #buildEnvVars(AbstractBuild, EnvVars)} instead. + */ + public void buildEnvVars(AbstractBuild build, Map env) { + if (env instanceof EnvVars && Util.isOverridden(ParameterValue.class,getClass(),"buildEnvVars", AbstractBuild.class,EnvVars.class)) + // if the subtype already derives buildEnvVars(AbstractBuild,Map), then delegate to it + buildEnvVars(build,(EnvVars)env); + + // otherwise no-op by default + } + + /** + * Adds environmental variables for the builds to the given map. + * + *

+ * This provides a means for a parameter to pass the parameter + * values to the build to be performed. + * + *

+ * When this method is invoked, the map already contains the + * current "planned export" list. The implementation is + * expected to add more values to this map (or do nothing) * * @param env * never null. * @param build * The build for which this parameter is being used. Never null. */ - public void buildEnvVars(AbstractBuild build, Map env) { - // no-op by default + public void buildEnvVars(AbstractBuild build, EnvVars env) { + // for backward compatibility + buildEnvVars(build,(Map)env); } /** diff --git a/core/src/main/java/hudson/model/RunParameterValue.java b/core/src/main/java/hudson/model/RunParameterValue.java index 77fb6adb22..b7984f7cd6 100644 --- a/core/src/main/java/hudson/model/RunParameterValue.java +++ b/core/src/main/java/hudson/model/RunParameterValue.java @@ -25,6 +25,7 @@ package hudson.model; import java.util.Map; +import hudson.EnvVars; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.export.Exported; @@ -66,8 +67,8 @@ public class RunParameterValue extends ParameterValue { * Exposes the name/value as an environment variable. */ @Override - public void buildEnvVars(AbstractBuild build, Map env) { - env.put(name.toUpperCase(), Hudson.getInstance().getRootUrl() + getRun().getUrl()); + public void buildEnvVars(AbstractBuild build, EnvVars env) { + env.put(name, Hudson.getInstance().getRootUrl() + getRun().getUrl()); } @Override diff --git a/core/src/main/java/hudson/model/StringParameterValue.java b/core/src/main/java/hudson/model/StringParameterValue.java index de2d7ab0eb..41c2e494ef 100644 --- a/core/src/main/java/hudson/model/StringParameterValue.java +++ b/core/src/main/java/hudson/model/StringParameterValue.java @@ -23,6 +23,7 @@ */ package hudson.model; +import hudson.EnvVars; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.export.Exported; @@ -51,8 +52,8 @@ public class StringParameterValue extends ParameterValue { * Exposes the name/value as an environment variable. */ @Override - public void buildEnvVars(AbstractBuild build, Map env) { - env.put(name.toUpperCase(),value); + public void buildEnvVars(AbstractBuild build, EnvVars env) { + env.put(name,value); } @Override