File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\model\Environment.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.model;
25
26 import hudson.Launcher;
27 import hudson.model.listeners.RunListener;
28 import hudson.slaves.NodeProperty;
29 import hudson.tasks.BuildWrapper;
30 import hudson.tasks.Builder;
31 import hudson.EnvVars;
32
33 import java.io.IOException;
34 import java.util.Map;
35
36 /**
37 * Represents some resources that are set up for the duration of a build
38 * to be torn down when the build is over.
39 *
40 * <p>
41 * This is often used to run a parallel server necessary during a build,
42 * such as an application server, a database reserved for the build,
43 * X server for performing UI tests, etc.
44 *
45 * <p>
46 * By having a plugin that does this, instead of asking each build script to do this,
47 * we can simplify the build script. {@link Environment} abstraction also gives
48 * you guaranteed "tear down" phase, so that such resource won't keep running forever.
49 *
50 * @since 1.286
51 * @see BuildWrapper
52 * @see NodeProperty
53 * @see RunListener#setUpEnvironment(AbstractBuild, Launcher, BuildListener)
54 */
55 public abstract class Environment {
56 /**
57 * Adds environmental variables for the builds to the given map.
58 *
59 * <p>
60 * If the {@link Environment} object wants to pass in information to the
61 * build that runs, it can do so by exporting additional environment
62 * variables to the map.
63 *
64 * <p>
65 * When this method is invoked, the map already contains the current
66 * "planned export" list.
67 *
68 * @param env
69 * never null. This really should have been typed as {@link EnvVars}
70 * but by the time we realized it it was too late.
71 */
72 public void buildEnvVars(Map<String,String> env) {
73 // no-op by default
74 }
75
76 /**
77 * Runs after the {@link Builder} completes, and performs a tear down.
78 *
79 * <p>
80 * This method is invoked even when the build failed, so that the clean up
81 * operation can be performed regardless of the build result (for example,
82 * you'll want to stop application server even if a build fails.)
83 *
84 * @param build
85 * The same {@link Build} object given to the set up method.
86 * @param listener
87 * The same {@link BuildListener} object given to the set up
88 * method.
89 * @return true if the build can continue, false if there was an error and
90 * the build needs to be failed.
91 * @throws IOException
92 * terminates the build abnormally. Jenkins will handle the
93 * exception and reports a nice error message.
94 */
95 public boolean tearDown(AbstractBuild build, BuildListener listener)
96 throws IOException, InterruptedException {
97 return true;
98 }
99
100 /**
101 * Creates {@link Environment} implementation that just sets the variables as given in the parameter.
102 */
103 public static Environment create(final EnvVars envVars) {
104 return new Environment() {
105 @Override
106 public void buildEnvVars(Map<String, String> env) {
107 env.putAll(envVars);
108 }
109 };
110 }
111
112 }