Skip to content

Commit

Permalink
[FIXED JENKINS-47311] Fix the broken form submission and add the miss…
Browse files Browse the repository at this point in the history
…ing form support for org folders
  • Loading branch information
stephenc committed Oct 6, 2017
1 parent 22c8d12 commit 96e1f79
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
Expand Up @@ -28,6 +28,7 @@
import hudson.model.Descriptor;
import java.util.ArrayList;
import java.util.List;
import jenkins.scm.api.SCMNavigatorDescriptor;
import jenkins.scm.api.SCMSourceDescriptor;

/**
Expand Down
46 changes: 45 additions & 1 deletion src/main/java/jenkins/branch/OrganizationFolder.java
Expand Up @@ -130,6 +130,12 @@ public final class OrganizationFolder extends ComputedFolder<MultiBranchProject<
* Our project factories.
*/
private final DescribableList<MultiBranchProjectFactory,MultiBranchProjectFactoryDescriptor> projectFactories = new DescribableList<MultiBranchProjectFactory,MultiBranchProjectFactoryDescriptor>(this);
/**
* The rules for automatic building of branches.
*
* @since 2.0.12
*/
private final DescribableList<BranchBuildStrategy, BranchBuildStrategyDescriptor> buildStrategies = new DescribableList<>(this);

/**
* The persisted state maintained outside of the config file.
Expand All @@ -152,6 +158,13 @@ public final class OrganizationFolder extends ComputedFolder<MultiBranchProject<
*/
private transient String facDigest;

/**
* The {@link #buildStrategies} digest used to detect if we need to trigger a rescan on save.
*
* @since 2.0.12
*/
private transient String bbsDigest;

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -218,6 +231,11 @@ public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOExcep
} catch (XStreamException e) {
facDigest = null;
}
try {
bbsDigest = Util.getDigestOf(Items.XSTREAM2.toXML(buildStrategies));
} catch (XStreamException e) {
bbsDigest = null;
}
}
}

Expand Down Expand Up @@ -281,6 +299,16 @@ public DescribableList<MultiBranchProjectFactory,MultiBranchProjectFactoryDescri
return projectFactories;
}

/**
* The {@link BranchBuildStrategy}s to apply.
*
* @return The {@link BranchBuildStrategy}s to apply.
* @since 2.0.12
*/
public DescribableList<BranchBuildStrategy, BranchBuildStrategyDescriptor> getBuildStrategies() {
return buildStrategies;
}

/**
* {@inheritDoc}
*/
Expand All @@ -289,6 +317,7 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
super.submit(req, rsp);
navigators.rebuildHetero(req, req.getSubmittedForm(), ExtensionList.lookup(SCMNavigatorDescriptor.class), "navigators");
projectFactories.rebuildHetero(req, req.getSubmittedForm(), ExtensionList.lookup(MultiBranchProjectFactoryDescriptor.class), "projectFactories");
buildStrategies.rebuildHetero(req, req.getSubmittedForm(), ExtensionList.lookup(BranchBuildStrategyDescriptor.class), "buildStrategies");
for (SCMNavigator n : navigators) {
n.afterSave(this);
}
Expand All @@ -304,10 +333,18 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
} catch (XStreamException e) {
facDigest = null;
}
String bbsDigest;
try {
bbsDigest = Util.getDigestOf(Items.XSTREAM2.toXML(buildStrategies));
} catch (XStreamException e) {
bbsDigest = null;
}
recalculateAfterSubmitted(!StringUtils.equals(navDigest, this.navDigest));
recalculateAfterSubmitted(!StringUtils.equals(facDigest, this.facDigest));
recalculateAfterSubmitted(!StringUtils.equals(bbsDigest, this.bbsDigest));
this.navDigest = navDigest;
this.facDigest = facDigest;
this.bbsDigest = bbsDigest;
}

/**
Expand Down Expand Up @@ -352,6 +389,11 @@ protected void computeChildren(final ChildObserver<MultiBranchProject<?,?>> obse
} catch (XStreamException e) {
facDigest = null;
}
try {
bbsDigest = Util.getDigestOf(Items.XSTREAM2.toXML(buildStrategies));
} catch (XStreamException e) {
bbsDigest = null;
}
long start = System.currentTimeMillis();
listener.getLogger().format("[%tc] Starting organization scan...%n", start);
try {
Expand Down Expand Up @@ -1279,8 +1321,10 @@ private List<BranchSource> createBranchSources() {
}
List<BranchSource> branchSources = new ArrayList<BranchSource>();
for (SCMSource source : sources) {
BranchSource branchSource = new BranchSource(source);
branchSource.setBuildStrategies(buildStrategies);
// TODO do we want/need a more general BranchPropertyStrategyFactory?
branchSources.add(new BranchSource(source));
branchSources.add(branchSource);
}
sources = null; // make sure complete gets called just once
return branchSources;
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/jenkins/branch/BranchSource/config.jelly
Expand Up @@ -43,8 +43,10 @@
</j:if>
<j:set var="descriptors" value="${descriptor.buildStrategiesDescriptors(it,sourceDescriptor)}"/>
<j:if test="${!descriptors.isEmpty()}">
<f:entry title="${%Build strategies}">
<f:hetero-list name="${buildStrategies}" items="${instance.buildStrategies}"
descriptors="${descriptors}"
hasHeader="true" honorOrder="true"/>
</f:entry>
</j:if>
</j:jelly>
@@ -0,0 +1,5 @@
<div>
By default (i.e. when empty), everything except tags will be automatically built whenever discovered or changed.
If you add at least one strategy then the defaults will be disabled and only the configured strategies will be
applied.
</div>
Expand Up @@ -48,5 +48,13 @@
<f:entry field="projectFactories" title="${%Project Recognizers}">
<f:repeatableHeteroProperty field="projectFactories" hasHeader="true" />
</f:entry>
<j:set var="descriptors" value="${descriptor.getPropertyType(instance,'buildStrategies').applicableItemDescriptors}"/>
<j:if test="${!descriptors.isEmpty()}">
<f:entry title="${%Build strategies}" help="${descriptor.getHelpFile('buildStrategies')}">
<f:hetero-list name="${buildStrategies}" items="${instance.buildStrategies}"
descriptors="${descriptors}"
hasHeader="true" honorOrder="true"/>
</f:entry>
</j:if>
</f:section>
</j:jelly>
@@ -0,0 +1,5 @@
<div>
By default (i.e. when empty), everything except tags will be automatically built whenever discovered or changed.
If you add at least one strategy then the defaults will be disabled and only the configured strategies will be
applied.
</div>

0 comments on commit 96e1f79

Please sign in to comment.