File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\model\StringParameterValue.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Luca Domenico Milanesio, Tom Huybrechts
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.model;
25
26 import hudson.EnvVars;
27 import org.kohsuke.stapler.DataBoundConstructor;
28 import org.kohsuke.stapler.export.Exported;
29
30 import java.util.Locale;
31
32 import hudson.util.VariableResolver;
33
34 /**
35 * {@link ParameterValue} created from {@link StringParameterDefinition}.
36 */
37 public class StringParameterValue extends ParameterValue {
38 @Exported(visibility=4)
39 public final String value;
40
41 @DataBoundConstructor
42 public StringParameterValue(String name, String value) {
43 this(name, value, null);
44 }
45
46 public StringParameterValue(String name, String value, String description) {
47 super(name, description);
48 this.value = value;
49 }
50
51 /**
52 * Exposes the name/value as an environment variable.
53 */
54 @Override
55 public void buildEnvVars(AbstractBuild<?,?> build, EnvVars env) {
56 env.put(name,value);
57 env.put(name.toUpperCase(Locale.ENGLISH),value); // backward compatibility pre 1.345
58 }
59
60 @Override
61 public VariableResolver<String> createVariableResolver(AbstractBuild<?, ?> build) {
62 return new VariableResolver<String>() {
63 public String resolve(String name) {
64 return StringParameterValue.this.name.equals(name) ? value : null;
65 }
66 };
67 }
68
69
70 @Override
71 public int hashCode() {
72 final int prime = 31;
73 int result = super.hashCode();
74 result = prime * result + ((value == null) ? 0 : value.hashCode());
75 return result;
76 }
77
78 @Override
79 public boolean equals(Object obj) {
80 if (this == obj)
81 return true;
82 if (!super.equals(obj))
83 return false;
84 if (getClass() != obj.getClass())
85 return false;
86 StringParameterValue other = (StringParameterValue) obj;
87 if (value == null) {
88 if (other.value != null)
89 return false;
90 } else if (!value.equals(other.value))
91 return false;
92 return true;
93 }
94
95 @Override
96 public String toString() {
97 return "(StringParameterValue) " + getName() + "='" + value + "'";
98 }
99 }
100