Skip to content

Commit

Permalink
[FIXED JENKINS-48536] OrganizationFolder should ensure MultibranchPro…
Browse files Browse the repository at this point in the history
…ject calls SCMSource.afterSave()
  • Loading branch information
stephenc committed Dec 13, 2017
1 parent d267982 commit d4f20e4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
31 changes: 26 additions & 5 deletions src/main/java/jenkins/branch/MultiBranchProject.java
Expand Up @@ -893,9 +893,27 @@ protected void submit(StaplerRequest req, StaplerResponse rsp)
}
setProjectFactory(req.bindJSON(BranchProjectFactory.class, json.getJSONObject("projectFactory")));
}
for (SCMSource scmSource : _sources) {
fireSCMSourceAfterSave(_sources);
recalculateAfterSubmitted(updateDigests());
}

/**
* Fires the {@link SCMSource#afterSave()} method for the supplied sources.
* @param sources the sources.
*/
protected void fireSCMSourceAfterSave(List<SCMSource> sources) {
for (SCMSource scmSource : sources) {
scmSource.afterSave();
}
}

/**
* Updates the digests used to detect changes to the sources and project factories (which would mandate a
* recalculation).
*
* @return {@code true} if the digests have changed.
*/
/*package*/ boolean updateDigests() {
String srcDigest;
try {
srcDigest = Util.getDigestOf(Items.XSTREAM2.toXML(sources));
Expand All @@ -908,10 +926,13 @@ protected void submit(StaplerRequest req, StaplerResponse rsp)
} catch (XStreamException e) {
facDigest = null;
}
recalculateAfterSubmitted(!StringUtils.equals(srcDigest, this.srcDigest));
recalculateAfterSubmitted(!StringUtils.equals(facDigest, this.facDigest));
this.srcDigest = srcDigest;
this.facDigest = facDigest;
try {
return !StringUtils.equals(srcDigest, this.srcDigest)
|| !StringUtils.equals(facDigest, this.facDigest);
} finally {
this.srcDigest = srcDigest;
this.facDigest = facDigest;
}
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/jenkins/branch/OrganizationFolder.java
Expand Up @@ -1385,7 +1385,8 @@ public void complete() throws IllegalStateException, IOException, InterruptedExc
} finally {
bc.commit();
}
if (isBuildable()) {
existing.fireSCMSourceAfterSave(existing.getSCMSources());
if (isBuildable() && existing.isBuildable() && existing.updateDigests()) {
existing.scheduleBuild(cause());
}
return;
Expand Down Expand Up @@ -1425,7 +1426,8 @@ public void complete() throws IllegalStateException, IOException, InterruptedExc
bc.commit();
}
observer.created(project);
if (isBuildable()) {
project.fireSCMSourceAfterSave(project.getSCMSources());
if (isBuildable() && project.isBuildable() && project.updateDigests()) {
project.scheduleBuild(cause());
}
} finally {
Expand Down

0 comments on commit d4f20e4

Please sign in to comment.