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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., 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.slaves;
25
26 import hudson.EnvVars;
27 import hudson.Extension;
28 import hudson.Launcher;
29 import hudson.model.AbstractBuild;
30 import hudson.model.BuildListener;
31 import hudson.model.ComputerSet;
32 import hudson.model.Environment;
33 import hudson.model.Node;
34 import hudson.model.TaskListener;
35 import org.kohsuke.stapler.DataBoundConstructor;
36 import org.kohsuke.stapler.Stapler;
37
38 import java.io.IOException;
39 import java.util.Arrays;
40 import java.util.List;
41
42 /**
43 * {@link NodeProperty} that sets additional environment variables.
44 *
45 * @since 1.286
46 */
47 public class EnvironmentVariablesNodeProperty extends NodeProperty<Node> {
48
49 /**
50 * Slave-specific environment variables
51 */
52 private final EnvVars envVars;
53
54 @DataBoundConstructor
55 public EnvironmentVariablesNodeProperty(List<Entry> env) {
56 this.envVars = toMap(env);
57 }
58
59 public EnvironmentVariablesNodeProperty(Entry... env) {
60 this(Arrays.asList(env));
61 }
62
63 public EnvVars getEnvVars() {
64 return envVars;
65 }
66
67 @Override
68 public Environment setUp(AbstractBuild build, Launcher launcher,
69 BuildListener listener) throws IOException, InterruptedException {
70 return Environment.create(envVars);
71 }
72
73 @Override
74 public void buildEnvVars(EnvVars env, TaskListener listener) throws IOException, InterruptedException {
75 env.putAll(envVars);
76 }
77
78 @Extension
79 public static class DescriptorImpl extends NodePropertyDescriptor {
80
81 @Override
82 public String getDisplayName() {
83 return Messages.EnvironmentVariablesNodeProperty_displayName();
84 }
85
86 public String getHelpPage() {
87 // yes, I know this is a hack.
88 ComputerSet object = Stapler.getCurrentRequest().findAncestorObject(ComputerSet.class);
89 if (object != null) {
90 // we're on a node configuration page, show show that help page
91 return "/help/system-config/nodeEnvironmentVariables.html";
92 } else {
93 // show the help for the global config page
94 return "/help/system-config/globalEnvironmentVariables.html";
95 }
96 }
97 }
98
99 public static class Entry {
100 public String key, value;
101
102 @DataBoundConstructor
103 public Entry(String key, String value) {
104 this.key = key;
105 this.value = value;
106 }
107 }
108
109 private static EnvVars toMap(List<Entry> entries) {
110 EnvVars map = new EnvVars();
111 if (entries!=null)
112 for (Entry entry: entries)
113 map.put(entry.key,entry.value);
114 return map;
115 }
116
117 }
118