Skip to content

Commit

Permalink
[JENKINS-32670] Filter branch properties on newly added branch source…
Browse files Browse the repository at this point in the history
…s just like existing ones.
  • Loading branch information
jglick committed Mar 15, 2016
1 parent feae9aa commit cb6bee9
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/resources/jenkins/branch/BranchSource/config.jelly
Expand Up @@ -22,7 +22,7 @@
~ THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:branch="/lib/branch-api">
<tr name="source">
<td colspan="3">
<input type="hidden" name="stapler-class" value="${sourceDescriptor.clazz.name}"/>
Expand All @@ -36,7 +36,7 @@
</td>
</tr>
<f:block>
<f:dropdownDescriptorSelector field="strategy" title="Property strategy"
<branch:dropdownDescriptorSelector field="strategy" title="Property strategy"
descriptors="${descriptor.propertyStrategyDescriptors(it,sourceDescriptor)}"/>
</f:block>
</j:jelly>
72 changes: 72 additions & 0 deletions src/main/resources/lib/branch-api/dropdownDescriptorSelector.jelly
@@ -0,0 +1,72 @@
<!--
The MIT License
Copyright (c) 2010, InfraDNA, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<!-- TODO 1.645+ use standard /lib/form version -->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<st:documentation>
Renders a single &lt;select> control for choosing a Describable.
Depending on the currently selected value, its config.jelly will be
rendered below &lt;select, allowing the user to configure Describable.

<st:attribute name="field" use="required">
form field name. Used for databinding.
</st:attribute>
<st:attribute name="title" use="required">
Human readable title of this control.
</st:attribute>
<st:attribute name="descriptors">
Collection that lists up all the valid candidate descriptors.
If unspecified, inferred from the type of the field.
</st:attribute>
<st:attribute name="default">
If specified, this will be chosen as the default value in case the current selection is null. The default can be an specific instance or a descriptor e.g.
${descriptor.defaultSettingsProvider} or ${descriptor.defaultSettingsProvider.descriptor}. In the later case, the from input fields will be empty.
</st:attribute>
<st:attribute name="capture">
Config fragments from descriptors are rendered lazily by default, which means
variables seen in the caller aren't visible to them. This attribute allows you
to nominate additional variables and their values to be captured for descriptors.
</st:attribute>
</st:documentation>
<f:prepareDatabinding />
<j:set target="${attrs}" property="descriptors" value="${attrs.descriptors ?: descriptor.getPropertyType(instance,attrs.field).getApplicableDescriptors()}" />

<f:dropdownList name="${attrs.field}" title="${attrs.title}" help="${descriptor.getHelpFile(attrs.field)}">
<d:invokeBody />

<j:set var="current" value="${instance[attrs.field]}"/>
<j:set var="current" value="${current!=null ? current : (default.descriptor!=null ? default : null)}"/>
<j:set var="capture" value="${attrs.capture?:''}" />
<j:forEach var="descriptor" items="${attrs.descriptors}" varStatus="loop">
<f:dropdownListBlock value="${loop.index}" title="${descriptor.displayName}"
selected="${current.descriptor==descriptor || (current==null and descriptor==attrs.default)}" staplerClass="${descriptor.clazz.name}"
lazy="descriptor,it,${capture}">
<l:ajax>
<j:set var="instance" value="${current.descriptor==descriptor ? current : null}" />
<st:include from="${descriptor}" page="${descriptor.configPage}" optional="true" />
</l:ajax>
</f:dropdownListBlock>
</j:forEach>
</f:dropdownList>
</j:jelly>

0 comments on commit cb6bee9

Please sign in to comment.