9898import jenkins .scm .api .metadata .ObjectMetadataAction ;
9999import jenkins .scm .impl .SingleSCMNavigator ;
100100import jenkins .scm .impl .UncategorizedSCMSourceCategory ;
101+ import net .sf .json .JSONObject ;
102+
101103import org .acegisecurity .AccessDeniedException ;
102104import org .acegisecurity .Authentication ;
103105import org .apache .commons .io .Charsets ;
@@ -142,6 +144,13 @@ public final class OrganizationFolder extends ComputedFolder<MultiBranchProject<
142144 */
143145 private DescribableList <BranchBuildStrategy , BranchBuildStrategyDescriptor > buildStrategies = new DescribableList <>(this );
144146
147+ /**
148+ * The branches properties.
149+ *
150+ * @since 2.5.9
151+ */
152+ private BranchPropertyStrategy strategy ;
153+
145154 /**
146155 * The persisted state maintained outside of the config file.
147156 *
@@ -163,6 +172,13 @@ public final class OrganizationFolder extends ComputedFolder<MultiBranchProject<
163172 */
164173 private transient String facDigest ;
165174
175+ /**
176+ * The {@link #propertyStrategy} digest used to detect if we need to trigger a rescan on save.
177+ *
178+ * @since 2.5.9
179+ */
180+ private transient String propsDigest ;
181+
166182 /**
167183 * The {@link #buildStrategies} digest used to detect if we need to trigger a rescan on save.
168184 *
@@ -266,6 +282,11 @@ public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOExcep
266282 } catch (XStreamException e ) {
267283 facDigest = null ;
268284 }
285+ try {
286+ propsDigest = Util .getDigestOf (Items .XSTREAM2 .toXML (strategy ));
287+ } catch (XStreamException e ) {
288+ propsDigest = null ;
289+ }
269290 try {
270291 bbsDigest = Util .getDigestOf (Items .XSTREAM2 .toXML (buildStrategies ));
271292 } catch (XStreamException e ) {
@@ -334,6 +355,26 @@ public DescribableList<MultiBranchProjectFactory,MultiBranchProjectFactoryDescri
334355 return projectFactories ;
335356 }
336357
358+ /**
359+ * Gets the strategy.
360+ *
361+ * @return the strategy.
362+ * @since 2.5.9
363+ */
364+ public BranchPropertyStrategy getStrategy () {
365+ return strategy != null ? strategy : new DefaultBranchPropertyStrategy (new BranchProperty [0 ]);
366+ }
367+
368+ /**
369+ * Sets the branch property strategy.
370+ *
371+ * @param strategy chosen.
372+ * @since 2.5.9
373+ */
374+ public void setStrategy (BranchPropertyStrategy strategy ) {
375+ this .strategy = strategy ;
376+ }
377+
337378 /**
338379 * The {@link BranchBuildStrategy}s to apply.
339380 *
@@ -350,9 +391,13 @@ public DescribableList<BranchBuildStrategy, BranchBuildStrategyDescriptor> getBu
350391 @ Override
351392 protected void submit (StaplerRequest req , StaplerResponse rsp ) throws IOException , ServletException , Descriptor .FormException {
352393 super .submit (req , rsp );
353- navigators .rebuildHetero (req , req .getSubmittedForm (), ExtensionList .lookup (SCMNavigatorDescriptor .class ), "navigators" );
354- projectFactories .rebuildHetero (req , req .getSubmittedForm (), ExtensionList .lookup (MultiBranchProjectFactoryDescriptor .class ), "projectFactories" );
355- buildStrategies .rebuildHetero (req , req .getSubmittedForm (), ExtensionList .lookup (BranchBuildStrategyDescriptor .class ), "buildStrategies" );
394+
395+ JSONObject json = req .getSubmittedForm ();
396+ navigators .rebuildHetero (req , json , ExtensionList .lookup (SCMNavigatorDescriptor .class ), "navigators" );
397+ projectFactories .rebuildHetero (req , json , ExtensionList .lookup (MultiBranchProjectFactoryDescriptor .class ), "projectFactories" );
398+ buildStrategies .rebuildHetero (req , json , ExtensionList .lookup (BranchBuildStrategyDescriptor .class ), "buildStrategies" );
399+ strategy = req .bindJSON (BranchPropertyStrategy .class , json .getJSONObject ("strategy" ));
400+
356401 for (SCMNavigator n : navigators ) {
357402 n .afterSave (this );
358403 }
@@ -368,6 +413,12 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
368413 } catch (XStreamException e ) {
369414 facDigest = null ;
370415 }
416+ String propsDigest ;
417+ try {
418+ propsDigest = Util .getDigestOf (Items .XSTREAM2 .toXML (strategy ));
419+ } catch (XStreamException e ) {
420+ propsDigest = null ;
421+ }
371422 String bbsDigest ;
372423 try {
373424 bbsDigest = Util .getDigestOf (Items .XSTREAM2 .toXML (buildStrategies ));
@@ -376,9 +427,11 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
376427 }
377428 recalculateAfterSubmitted (!StringUtils .equals (navDigest , this .navDigest ));
378429 recalculateAfterSubmitted (!StringUtils .equals (facDigest , this .facDigest ));
430+ recalculateAfterSubmitted (!StringUtils .equals (propsDigest , this .propsDigest ));
379431 recalculateAfterSubmitted (!StringUtils .equals (bbsDigest , this .bbsDigest ));
380432 this .navDigest = navDigest ;
381433 this .facDigest = facDigest ;
434+ this .propsDigest = propsDigest ;
382435 this .bbsDigest = bbsDigest ;
383436 }
384437
@@ -730,6 +783,16 @@ public String getCategoryId() {
730783 return "nested-projects" ;
731784 }
732785
786+ /**
787+ * Gets all the {@link BranchPropertyStrategyDescriptor} instances applicable to the specified project and source.
788+ *
789+ * @return all the {@link BranchPropertyStrategyDescriptor} instances applicable to the specified project and
790+ * source.
791+ */
792+ public List <BranchPropertyStrategyDescriptor > propertyStrategyDescriptors () {
793+ return BranchPropertyStrategyDescriptor .all ();
794+ }
795+
733796 /**
734797 * A description of this {@link OrganizationFolder}.
735798 *
@@ -1388,10 +1451,9 @@ private List<BranchSource> createBranchSources() {
13881451 for (SCMSource source : sources ) {
13891452 BranchSource branchSource = new BranchSource (source );
13901453 branchSource .setBuildStrategies (buildStrategies );
1391- // TODO do we want/need a more general BranchPropertyStrategyFactory?
1454+ branchSource . setStrategy ( strategy );
13921455 branchSources .add (branchSource );
13931456 }
1394- sources = null ; // make sure complete gets called just once
13951457 return branchSources ;
13961458 }
13971459
0 commit comments