Skip to content

Commit

Permalink
[FIXED JENKINS-32670] Suppress branch property strategies, and the wh…
Browse files Browse the repository at this point in the history
…ole associated UI, when there are no relevant branch properties.
  • Loading branch information
jglick committed Mar 15, 2016
1 parent cb6bee9 commit 84e998a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
3 changes: 0 additions & 3 deletions src/main/java/jenkins/branch/BranchPropertyDescriptor.java
Expand Up @@ -89,9 +89,6 @@ public static List<BranchPropertyDescriptor> all(@NonNull MultiBranchProject pro

/**
* Ensures that the configuration screen of (for example) {@link DefaultBranchPropertyStrategy} shows only appropriate descriptors.
* TODO this trick does not work for {@link NamedExceptionsBranchPropertyStrategy} on initial configuration (i.e., when {@link DefaultBranchPropertyStrategy} was initially selected);
* seems {@code filterDescriptors} is not called when {@code instance == null} perhaps?
* Or perhaps {@code it == null} when {@code l:renderOnDemand} is in use (supposed to work due to {@code capture} attribute, but…)?
*/
@Restricted(DoNotUse.class)
@Extension
Expand Down
Expand Up @@ -26,6 +26,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.ExtensionList;
import hudson.model.Descriptor;
import hudson.model.DescriptorVisibilityFilter;
import jenkins.scm.api.SCMSourceDescriptor;

import java.util.ArrayList;
Expand All @@ -46,21 +47,24 @@ public abstract class BranchPropertyStrategyDescriptor extends Descriptor<Branch
* @param sourceDescriptor the source descriptor.
* @return {@code} true iff this property strategy is relevant with this source.
*/
@SuppressWarnings("unused") // by stapler
public boolean isApplicable(@NonNull SCMSourceDescriptor sourceDescriptor) {
return true;
}

/**
* A branch property strategy may not be appropriate for every project, this method lets a strategy
* opt out of being selectable for a specific project.
*
* <p>By default it checks {@link #isApplicable(MultiBranchProjectDescriptor)},
* and whether {@link BranchPropertyDescriptor#all(MultiBranchProject)} is nonempty
* when filtered by {@link DescriptorVisibilityFilter} on the project,
* which due to {@link jenkins.branch.BranchPropertyDescriptor.Visibility}
* also calls {@link BranchPropertyDescriptor#isApplicable(MultiBranchProject)}.
* @param project the project.
* @return {@code} true iff this property strategy is relevant with this project instance.
*/
@SuppressWarnings("unused") // by stapler
public boolean isApplicable(@NonNull MultiBranchProject project) {
return isApplicable(project.getDescriptor());
return isApplicable(project.getDescriptor()) &&
!DescriptorVisibilityFilter.apply(project, BranchPropertyDescriptor.all()).isEmpty();
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/main/resources/jenkins/branch/BranchSource/config.jelly
Expand Up @@ -35,8 +35,10 @@
</table>
</td>
</tr>
<f:block>
<branch:dropdownDescriptorSelector field="strategy" title="Property strategy"
descriptors="${descriptor.propertyStrategyDescriptors(it,sourceDescriptor)}"/>
</f:block>
<j:set var="descriptors" value="${descriptor.propertyStrategyDescriptors(it,sourceDescriptor)}"/>
<j:if test="${!descriptors.isEmpty()}">
<f:block>
<branch:dropdownDescriptorSelector field="strategy" title="Property strategy" descriptors="${descriptors}"/>
</f:block>
</j:if>
</j:jelly>

0 comments on commit 84e998a

Please sign in to comment.