Skip to content

Commit 69e3383

Browse files
committed
Merge branch 'feature/JENKINS-74241' into develop
2 parents 08ca710 + 0210317 commit 69e3383

File tree

17 files changed

+274
-177
lines changed

17 files changed

+274
-177
lines changed

Jenkinsfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
buildPlugin()
1+
buildPlugin(useContainerAgent: true, timeout: 180, configurations: [
2+
[platform: 'linux', jdk: 17],
3+
[platform: 'windows', jdk: 11],
4+
])

README.md

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -91,58 +91,41 @@ pipeline {
9191
properties([
9292
parameters([
9393
multiselect(
94-
decisionTree: [$class : 'de.westemeyer.plugins.multiselect.MultiselectDecisionTree',
95-
variableDescriptions: ([
96-
[$class : 'de.westemeyer.plugins.multiselect.MultiselectVariableDescriptor',
97-
label : "Sport",
98-
variableName: "SELECTED_SPORT"
99-
],
100-
[$class : 'de.westemeyer.plugins.multiselect.MultiselectVariableDescriptor',
101-
label : "Team",
102-
variableName: "SELECTED_TEAM"
103-
]
104-
]),
105-
itemList : ([
106-
[$class : 'de.westemeyer.plugins.multiselect.MultiselectDecisionItem',
107-
value : "Tennis",
108-
children: ([
109-
[$class: 'de.westemeyer.plugins.multiselect.MultiselectDecisionItem',
110-
value : "Tennisclub Rumeln-Kaldenhausen e. V."
111-
],
112-
[$class: 'de.westemeyer.plugins.multiselect.MultiselectDecisionItem',
113-
label : "Alternative label",
114-
value : "Oppumer TC"
115-
]
116-
])
117-
],
118-
[$class : 'de.westemeyer.plugins.multiselect.MultiselectDecisionItem',
119-
value : "Football",
120-
children: ([
121-
[$class: 'de.westemeyer.plugins.multiselect.MultiselectDecisionItem',
122-
value : "Rumelner TV"
123-
],
124-
[$class: 'de.westemeyer.plugins.multiselect.MultiselectDecisionItem',
125-
value : "FC Rumeln"
126-
]
127-
])
128-
],
129-
[$class : 'de.westemeyer.plugins.multiselect.MultiselectDecisionItem',
130-
value : "Wakeboard",
131-
children: ([
132-
[$class: 'de.westemeyer.plugins.multiselect.MultiselectDecisionItem',
133-
value : "WSC Duisburg Rheinhausen"
134-
]
135-
])
136-
]
137-
]),
94+
decisionTree: [
95+
variableDescriptions: [
96+
[
97+
label : 'Sport',
98+
variableName: 'SELECTED_SPORT'
99+
],
100+
[
101+
label : 'Team',
102+
variableName: 'SELECTED_TEAM'
103+
]
104+
],
105+
itemList: [
106+
[children: [
107+
[value: 'Tennisclub Rumeln-Kaldenhausen e. V.'],
108+
[label: 'Alternative label', value: 'Oppumer TC']
109+
],
110+
value : 'Tennis'
111+
],
112+
[children: [
113+
[value: 'Rumelner TV'],
114+
[value: 'FC Rumeln']
115+
],
116+
value : 'Football'],
117+
[children: [
118+
[value: 'WSC Duisburg Rheinhausen']
119+
],
120+
value : 'Wakeboard']
121+
]
138122
],
139123
description: 'Please select your favourite team!',
140124
name: 'Favourite team'
141125
)
142126
])
143127
])
144128
}
145-
146129
}
147130
}
148131

images/sample_pipeline_config.png

-179 KB
Loading

pom.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
43
<modelVersion>4.0.0</modelVersion>
54
<parent>
65
<groupId>org.jenkins-ci.plugins</groupId>
76
<artifactId>plugin</artifactId>
87
<version>4.60</version>
9-
<relativePath/>
8+
<relativePath />
109
</parent>
1110
<groupId>io.jenkins.plugins</groupId>
1211
<artifactId>multiselect-parameter</artifactId>
13-
<version>1.5-SNAPSHOT</version>
12+
<version>1.8-SNAPSHOT</version>
1413
<url>https://github.com/jenkinsci/${project.artifactId}-plugin/blob/main/README.md</url>
1514
<packaging>hpi</packaging>
1615
<properties>
@@ -187,7 +186,7 @@
187186
<connection>scm:git:https://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
188187
<developerConnection>scm:git:[email protected]:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
189188
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
190-
<tag>HEAD</tag>
189+
<tag>multiselect-parameter-1.5</tag>
191190
</scm>
192191
<repositories>
193192
<repository>

src/main/java/de/westemeyer/plugins/multiselect/MultiselectDecisionItem.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ public class MultiselectDecisionItem implements Serializable {
3030

3131
/**
3232
* Create a new decision item with label and value.
33-
* @param parent parent item to traverse tree backwards
3433
* @param label label for display in selection list
3534
* @param value value for use in variable
3635
*/
3736
@DataBoundConstructor
38-
public MultiselectDecisionItem(MultiselectDecisionItem parent, String label, String value) {
39-
this.parent = parent;
37+
public MultiselectDecisionItem(String label, String value) {
4038
this.label = label;
4139
this.value = value;
4240
}
@@ -55,7 +53,7 @@ public void visitSubTree(MultiselectDecisionItemVisitor visitor, Queue<Multisele
5553
/**
5654
* Static visitor pattern implementation to walk through the tree collecting information.
5755
* @param visitor visitor object or lambda collecting information
58-
* @param items item list (column entries) to iterate
56+
* @param items item list (column entries) to iterate
5957
* @param columns column descriptions to go along with the items
6058
* @throws Exception if an error occurs in visitor
6159
*/
@@ -75,8 +73,8 @@ public static void visitSubTree(MultiselectDecisionItemVisitor visitor, List<Mul
7573
/**
7674
* Visitor pattern implementation to walk through the tree collecting information. Select the column items
7775
* by their column index (no iteration involved).
78-
* @param visitor visitor object or lambda collecting information
79-
* @param columns column descriptions to go along with the items
76+
* @param visitor visitor object or lambda collecting information
77+
* @param columns column descriptions to go along with the items
8078
* @param itemPath indices of items in columns to select and walk through
8179
*/
8280
public void visitSelectedItems(MultiselectDecisionItemVisitor visitor, Queue<MultiselectVariableDescriptor> columns, Queue<Integer> itemPath) {
@@ -87,9 +85,9 @@ public void visitSelectedItems(MultiselectDecisionItemVisitor visitor, Queue<Mul
8785
/**
8886
* Static visitor pattern implementation to walk through the tree collecting information. Select the column items
8987
* by their column index (no iteration involved).
90-
* @param visitor visitor object or lambda collecting information
91-
* @param items item list (column entries) to iterate
92-
* @param columns column descriptions to go along with the items
88+
* @param visitor visitor object or lambda collecting information
89+
* @param items item list (column entries) to iterate
90+
* @param columns column descriptions to go along with the items
9391
* @param itemPath indices of items in columns to select and walk through
9492
*/
9593
public static void visitSelectedItems(MultiselectDecisionItemVisitor visitor, List<MultiselectDecisionItem> items, Queue<MultiselectVariableDescriptor> columns, Queue<Integer> itemPath) {
@@ -102,7 +100,7 @@ public static void visitSelectedItems(MultiselectDecisionItemVisitor visitor, Li
102100
MultiselectDecisionItem subItem = items.get(index);
103101

104102
// apply visitor function/lambda, removing first item from queue at the same time
105-
if(visitor.visit(subItem, columns.poll())) {
103+
if (visitor.visit(subItem, columns.poll())) {
106104
// recursion with copy of remaining items in queue
107105
subItem.visitSelectedItems(visitor, new ArrayDeque<>(columns), itemPath);
108106
}
@@ -117,6 +115,10 @@ public String getLabel() {
117115
return label;
118116
}
119117

118+
/**
119+
* Set label for this item.
120+
* @param label the new label
121+
*/
120122
@DataBoundSetter
121123
public void setLabel(String label) {
122124
this.label = label;

src/main/java/de/westemeyer/plugins/multiselect/MultiselectDecisionTree.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public class MultiselectDecisionTree implements Serializable {
4343
@NonNull
4444
private List<MultiselectVariableDescriptor> variableDescriptions = new ArrayList<>();
4545

46+
/**
47+
* Empty constructor for pipeline configuration.
48+
*/
4649
@DataBoundConstructor
4750
public MultiselectDecisionTree() {
4851
// empty constructor is necessary, otherwise pipelines can not create

src/main/java/de/westemeyer/plugins/multiselect/MultiselectParameterDefinition.java

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.io.IOException;
2222
import java.util.ArrayDeque;
2323
import java.util.ArrayList;
24-
import java.util.Collections;
24+
import java.util.Arrays;
2525
import java.util.HashMap;
2626
import java.util.List;
2727
import java.util.Map;
@@ -50,7 +50,7 @@ public class MultiselectParameterDefinition extends ParameterDefinition {
5050

5151
/** Configuration format for a parameter definition. */
5252
@CheckForNull
53-
private MultiselectConfigurationFormat format;
53+
private MultiselectConfigurationFormat format = MultiselectConfigurationFormat.CSV;
5454

5555
/** UUID to be used to distinguish JavaScript values for multiple parameters from each other. */
5656
private String uuid = UUIDGenerator.generateUUID(15);
@@ -84,7 +84,7 @@ public MultiselectParameterDefinition(String name, String description, @CheckFor
8484
* @param coordinates coordinates in tree, i.e. item indices from columns
8585
* @return array of parameter values for given coordinates
8686
*/
87-
@JavaScriptMethod
87+
@JavaScriptMethod(name = "getItemList")
8888
public String[] getItemList(Integer[] coordinates) {
8989
Queue<Integer> itemPath = createCoordinates(coordinates);
9090
List<String> returnList = new ArrayList<>();
@@ -100,6 +100,30 @@ public String[] getItemList(Integer[] coordinates) {
100100
return returnList.toArray(new String[0]);
101101
}
102102

103+
/**
104+
* Method used by JavaScript code to get all combo box ids that depend on content of the given combo box ID.
105+
* @param selectedId combo box ID
106+
* @return all combo box ids that depend on content of the given combo box ID
107+
*/
108+
@JavaScriptMethod(name = "getDependingVariableIds")
109+
public String[] getDependingVariableIds(String selectedId) {
110+
if (decisionTree == null) {
111+
return new String[0];
112+
}
113+
boolean found = false;
114+
List<String> result = new ArrayList<>();
115+
for (MultiselectVariableDescriptor variableDescription : decisionTree.getVariableDescriptions()) {
116+
if (found) {
117+
result.add(variableDescription.getUuid());
118+
}
119+
if (variableDescription.getUuid().equals(selectedId)) {
120+
found = true;
121+
}
122+
}
123+
124+
return result.toArray(new String[0]);
125+
}
126+
103127
/**
104128
* Create coordinates queue from integer array.
105129
* @param coordinates integer array
@@ -110,7 +134,7 @@ public static Queue<Integer> createCoordinates(Integer... coordinates) {
110134
Queue<Integer> itemPath = new ArrayDeque<>();
111135

112136
// add all items to queue
113-
Collections.addAll(itemPath, coordinates);
137+
Arrays.stream(coordinates).filter(Objects::nonNull).forEach(itemPath::add);
114138

115139
// return queue object
116140
return itemPath;
@@ -141,7 +165,7 @@ public MultiselectParameterValue createValue(Map<String, Object> jsonObject) {
141165
// convert json object to map of strings to integers (values from parameter form)
142166
jsonObject.forEach((key, value) -> {
143167
// exclude parameter name
144-
if (!key.equals(PARAMETER_NAME) && value instanceof String && ((String) value).length() > 0) {
168+
if (!key.equals(PARAMETER_NAME) && value instanceof String && !((String) value).isEmpty()) {
145169
try {
146170
// store new key combination in map
147171
selectedValues.put(key, Integer.valueOf((String) value));
@@ -297,15 +321,17 @@ public void setUuid(String uuid) {
297321

298322
@Override
299323
public boolean equals(Object o) {
300-
if (this == o) return true;
301-
if (!(o instanceof MultiselectParameterDefinition)) return false;
302-
if (!super.equals(o)) return false;
303-
MultiselectParameterDefinition that = (MultiselectParameterDefinition) o;
304-
return Objects.equals(decisionTree, that.decisionTree) && format == that.format && Objects.equals(uuid, that.uuid);
324+
if (this == o) {
325+
return true;
326+
}
327+
if (!(o instanceof MultiselectParameterDefinition)) {
328+
return false;
329+
}
330+
return super.equals(o);
305331
}
306332

307333
@Override
308334
public int hashCode() {
309-
return Objects.hash(super.hashCode(), decisionTree, format, uuid);
335+
return Objects.hash(decisionTree, uuid);
310336
}
311337
}

src/main/java/de/westemeyer/plugins/multiselect/MultiselectParameterValue.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import hudson.model.ParameterValue;
66
import hudson.model.Run;
77
import hudson.util.VariableResolver;
8+
import org.kohsuke.stapler.DataBoundConstructor;
89
import org.kohsuke.stapler.DataBoundSetter;
910

1011
import java.util.Map;
@@ -34,6 +35,7 @@ public MultiselectParameterValue(String name) {
3435
* @param name name of parameter
3536
* @param selectedValues selected values in select boxes
3637
*/
38+
@DataBoundConstructor
3739
public MultiselectParameterValue(String name, Map<String, String> selectedValues) {
3840
this(name);
3941
this.selectedValues = selectedValues;
@@ -46,6 +48,10 @@ public void buildEnvironment(Run<?, ?> build, EnvVars env) {
4648
env.putAll(getSelectedValues());
4749
}
4850

51+
/**
52+
* Set the selectedValues map.
53+
* @param selectedValues the new map of selected values
54+
*/
4955
@DataBoundSetter
5056
public void setSelectedValues(Map<String, String> selectedValues) {
5157
this.selectedValues = selectedValues;

src/main/java/de/westemeyer/plugins/multiselect/MultiselectVariableDescriptor.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ public class MultiselectVariableDescriptor implements Serializable {
3232
* Create new variable description object.
3333
* @param label variable label
3434
* @param variableName variable name
35-
* @param columnIndex index of this column
3635
*/
3736
@DataBoundConstructor
38-
public MultiselectVariableDescriptor(String label, String variableName, int columnIndex) {
37+
public MultiselectVariableDescriptor(String label, String variableName) {
3938
this.label = label;
4039
this.variableName = variableName;
41-
this.columnIndex = columnIndex;
4240
}
4341

4442
/**
@@ -49,6 +47,10 @@ public String getLabel() {
4947
return label;
5048
}
5149

50+
/**
51+
* Set label for this variable.
52+
* @param label the new variable label
53+
*/
5254
@DataBoundSetter
5355
public void setLabel(String label) {
5456
this.label = label;
@@ -62,6 +64,10 @@ public String getVariableName() {
6264
return variableName;
6365
}
6466

67+
/**
68+
* Set the variable name.
69+
* @param variableName the new variable name
70+
*/
6571
@DataBoundSetter
6672
public void setVariableName(String variableName) {
6773
this.variableName = variableName;
@@ -99,6 +105,10 @@ public int getColumnIndex() {
99105
return columnIndex;
100106
}
101107

108+
/**
109+
* Set column index for the descriptor.
110+
* @param columnIndex the new column index
111+
*/
102112
public void setColumnIndex(int columnIndex) {
103113
this.columnIndex = columnIndex;
104114
}

0 commit comments

Comments
 (0)