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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, 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 jenkins.model.Jenkins;
27 import net.sf.json.JSONObject;
28
29 import org.kohsuke.stapler.DataBoundConstructor;
30 import org.kohsuke.stapler.StaplerRequest;
31 import org.kohsuke.stapler.export.Exported;
32 import hudson.Extension;
33 import org.kohsuke.stapler.QueryParameter;
34
35 public class RunParameterDefinition extends SimpleParameterDefinition {
36
37 private final String projectName;
38 private final String runId;
39
40 @DataBoundConstructor
41 public RunParameterDefinition(String name, String projectName, String description) {
42 super(name, description);
43 this.projectName = projectName;
44 this.runId = null;
45 }
46
47 private RunParameterDefinition(String name, String projectName, String runId, String description) {
48 super(name, description);
49 this.projectName = projectName;
50 this.runId = runId;
51 }
52
53 @Override
54 public ParameterDefinition copyWithDefaultValue(ParameterValue defaultValue) {
55 if (defaultValue instanceof RunParameterValue) {
56 RunParameterValue value = (RunParameterValue) defaultValue;
57 return new RunParameterDefinition(getName(), value.getRunId(), getDescription());
58 } else {
59 return this;
60 }
61 }
62
63 @Exported
64 public String getProjectName() {
65 return projectName;
66 }
67
68 public Job getProject() {
69 return Jenkins.getInstance().getItemByFullName(projectName, Job.class);
70 }
71
72 @Extension
73 public static class DescriptorImpl extends ParameterDescriptor {
74 @Override
75 public String getDisplayName() {
76 return Messages.RunParameterDefinition_DisplayName();
77 }
78
79 @Override
80 public String getHelpFile() {
81 return "/help/parameter/run.html";
82 }
83
84 @Override
85 public ParameterDefinition newInstance(StaplerRequest req, JSONObject formData) throws FormException {
86 return req.bindJSON(RunParameterDefinition.class, formData);
87 }
88
89 public AutoCompletionCandidates doAutoCompleteProjectName(@QueryParameter String value) {
90 return AutoCompletionCandidates.ofJobNames(Job.class, value, null, Jenkins.getInstance());
91 }
92
93 }
94
95 @Override
96 public ParameterValue getDefaultParameterValue() {
97 if (runId != null) {
98 return createValue(runId);
99 }
100
101 Run<?,?> lastBuild = getProject().getLastBuild();
102 if (lastBuild != null) {
103 return createValue(lastBuild.getExternalizableId());
104 } else {
105 return null;
106 }
107 }
108
109 @Override
110 public ParameterValue createValue(StaplerRequest req, JSONObject jo) {
111 RunParameterValue value = req.bindJSON(RunParameterValue.class, jo);
112 value.setDescription(getDescription());
113 return value;
114 }
115
116 public RunParameterValue createValue(String value) {
117 return new RunParameterValue(getName(), value, getDescription());
118 }
119
120 }
121