/hudson-core/src/main/java/hudson/model/StringParameterValue.java

http://github.com/hudson/hudson · Java · 99 lines · 58 code · 12 blank · 29 comment · 12 complexity · 7afbdc6cfa47be667bc1c7323f552099 MD5 · raw file

  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. import hudson.EnvVars;
  26. import org.kohsuke.stapler.DataBoundConstructor;
  27. import org.kohsuke.stapler.export.Exported;
  28. import java.util.Locale;
  29. import hudson.util.VariableResolver;
  30. /**
  31. * {@link ParameterValue} created from {@link StringParameterDefinition}.
  32. */
  33. public class StringParameterValue extends ParameterValue {
  34. @Exported(visibility=4)
  35. public final String value;
  36. @DataBoundConstructor
  37. public StringParameterValue(String name, String value) {
  38. this(name, value, null);
  39. }
  40. public StringParameterValue(String name, String value, String description) {
  41. super(name, description);
  42. this.value = value;
  43. }
  44. /**
  45. * Exposes the name/value as an environment variable.
  46. */
  47. @Override
  48. public void buildEnvVars(AbstractBuild<?,?> build, EnvVars env) {
  49. env.put(name,value);
  50. env.put(name.toUpperCase(Locale.ENGLISH),value); // backward compatibility pre 1.345
  51. }
  52. @Override
  53. public VariableResolver<String> createVariableResolver(AbstractBuild<?, ?> build) {
  54. return new VariableResolver<String>() {
  55. public String resolve(String name) {
  56. return StringParameterValue.this.name.equals(name) ? value : null;
  57. }
  58. };
  59. }
  60. @Override
  61. public int hashCode() {
  62. final int prime = 31;
  63. int result = super.hashCode();
  64. result = prime * result + ((value == null) ? 0 : value.hashCode());
  65. return result;
  66. }
  67. @Override
  68. public boolean equals(Object obj) {
  69. if (this == obj)
  70. return true;
  71. if (!super.equals(obj))
  72. return false;
  73. if (getClass() != obj.getClass())
  74. return false;
  75. StringParameterValue other = (StringParameterValue) obj;
  76. if (value == null) {
  77. if (other.value != null)
  78. return false;
  79. } else if (!value.equals(other.value))
  80. return false;
  81. return true;
  82. }
  83. @Override
  84. public String toString() {
  85. return "(StringParameterValue) " + getName() + "='" + value + "'";
  86. }
  87. }