File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\matrix\LabelExpAxis.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.Util;
28 import jenkins.model.Jenkins;
29
30 import java.util.LinkedList;
31 import java.util.List;
32
33 import org.kohsuke.stapler.DataBoundConstructor;
34
35 /**
36 * {@link Axis} that selects label expressions.
37 *
38 * @since 1.403
39 */
40 public class LabelExpAxis extends Axis {
41
42 @DataBoundConstructor
43 public LabelExpAxis(String name, String values) {
44 super(name, getExprValues(values));
45 }
46
47 public LabelExpAxis(String name, List<String> values) {
48 super(name, values);
49 }
50
51 @Override
52 public boolean isSystem() {
53 return true;
54 }
55
56 @Override
57 public DescriptorImpl getDescriptor() {
58 return (DescriptorImpl) Jenkins.getInstance().getDescriptorOrDie(getClass());
59 }
60
61 public String getValuesString(){
62 StringBuffer sb = new StringBuffer();
63 for(String item: this.getValues()){
64 sb.append(item);
65 sb.append("\n");
66 }
67 return sb.toString();
68 }
69
70 @Extension
71 public static class DescriptorImpl extends AxisDescriptor {
72 @Override
73 public String getDisplayName() {
74 return Messages.LabelExpAxis_DisplayName();
75 }
76
77 /**
78 * If there's no distributed build set up, it's pointless to provide this axis.
79 */
80 @Override
81 public boolean isInstantiable() {
82 Jenkins h = Jenkins.getInstance();
83 return !h.getNodes().isEmpty() || !h.clouds.isEmpty();
84 }
85 }
86
87 public static List<String> getExprValues(String valuesString){
88 List<String> expressions = new LinkedList<String>();
89 String[] exprs = valuesString.split("\n");
90 for(String expr: exprs){
91 expressions.add(Util.fixEmptyAndTrim(expr));
92 }
93 return expressions;
94 }
95
96 }
97
98