mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 05:52:26 +00:00
[FIXED HUDSON-5391] in 1.344. we should be case insensitive but case preserving.
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@26640 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
eade4cca65
commit
68edd4f804
6 files changed
+66
-14
No files matched your search
@@ -38,13 +38,27 @@ import java.util.UUID;
|
||||
* Environment variables.
|
||||
*
|
||||
* <p>
|
||||
* 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 <b>insensitive</b> 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 <tt>GetEnvironmentVariable</tt> 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.
|
||||
*
|
||||
* <p>
|
||||
* So for a consistent cross platform behavior, it creates the least confusion to make the table
|
||||
* case insensitive but case preserving.
|
||||
*
|
||||
* <p>
|
||||
* 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 <tt>PATH</tt>. So to make this work,
|
||||
* we introduce a special convention <tt>PATH+FOO</tt> — all entries
|
||||
* that starts with <tt>PATH+</tt> are merged and prepended to the inherited
|
||||
* <tt>PATH</tt> variable, on the process where a new process is executed.
|
||||
*
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class EnvVars extends TreeMap<String,String> {
|
||||
@@ -80,6 +94,9 @@ public class EnvVars extends TreeMap<String,String> {
|
||||
this((Map)m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an environment variables from an array of the form <tt>"key","value","key","value"...</tt>
|
||||
*/
|
||||
public EnvVars(String... keyValuePairs) {
|
||||
this();
|
||||
if(keyValuePairs.length%2!=0)
|
||||
|
||||
@@ -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<String,String> env) {
|
||||
env.put(name.toUpperCase(),Boolean.toString(value));
|
||||
public void buildEnvVars(AbstractBuild<?,?> build, EnvVars env) {
|
||||
env.put(name,Boolean.toString(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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<String,String> 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());
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
*
|
||||
* <p>
|
||||
* Environment variables should be by convention all upper case.
|
||||
* (This is so that a Windows/Unix heterogenous environment
|
||||
* <strike>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.)</strike> (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<String,String> 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.
|
||||
*
|
||||
* <p>
|
||||
* This provides a means for a parameter to pass the parameter
|
||||
* values to the build to be performed.
|
||||
*
|
||||
* <p>
|
||||
* 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<String,String> env) {
|
||||
// no-op by default
|
||||
public void buildEnvVars(AbstractBuild<?,?> build, EnvVars env) {
|
||||
// for backward compatibility
|
||||
buildEnvVars(build,(Map<String,String>)env);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<String,String> 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
|
||||
|
||||
@@ -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<String,String> env) {
|
||||
env.put(name.toUpperCase(),value);
|
||||
public void buildEnvVars(AbstractBuild<?,?> build, EnvVars env) {
|
||||
env.put(name,value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user