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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2010, InfraDNA, Inc.
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.matrix;
25
26 import hudson.Extension;
27 import hudson.Functions;
28 import hudson.Util;
29 import jenkins.model.Jenkins;
30 import hudson.model.labels.LabelAtom;
31 import org.kohsuke.stapler.DataBoundConstructor;
32
33 import java.util.List;
34
35 /**
36 * {@link Axis} that selects label expressions.
37 *
38 * @author Kohsuke Kawaguchi
39 */
40 public class LabelAxis extends Axis {
41 @DataBoundConstructor
42 public LabelAxis(String name, List<String> values) {
43 super(name, values);
44 }
45
46 @Override
47 public boolean isSystem() {
48 return true;
49 }
50
51 @Override
52 public String getValueString() {
53 return Util.join(getValues(),"/");
54 }
55
56 @Extension
57 public static class DescriptorImpl extends AxisDescriptor {
58 @Override
59 public String getDisplayName() {
60 return Messages.LabelAxis_DisplayName();
61 }
62
63 /**
64 * If there's no distributed build set up, it's pointless to provide this axis.
65 */
66 @Override
67 public boolean isInstantiable() {
68 Jenkins h = Jenkins.getInstance();
69 return !h.getNodes().isEmpty() || !h.clouds.isEmpty();
70 }
71
72 private String jsstr(String body, Object... args) {
73 return '\"'+Functions.jsStringEscape(String.format(body,args))+'\"';
74 }
75
76 public String buildLabelCheckBox(LabelAtom la, LabelAxis instance) {
77 return jsstr("<input type='checkbox' name='values' json='%s' ",
78 Functions.htmlAttributeEscape(la.getName()))
79 +String.format("+has(%s)+",jsstr(la.getName()))
80 +jsstr("/><label class='attach-previous'>%s (%s)</label>",
81 la.getName(),la.getDescription());
82 // '${h.jsStringEscape('<input type="checkbox" name="values" json="'+h.htmlAttributeEscape(l.name)+'" ')}'+has("${h.jsStringEscape(l.name)}")+'${h.jsStringEscape('/><label class="attach-previous">'+l.name+' ('+l.description+')</label>')}'
83 }
84 }
85 }
86