Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/maven/org.jenkins-ci.plugins-pl…
Browse files Browse the repository at this point in the history
…ugin-4.18
  • Loading branch information
bitwiseman authored May 5, 2021
2 parents 46885da + 6d11613 commit dd833d8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/main/java/jenkins/branch/MultiBranchProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.thoughtworks.xstream.XStreamException;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.BulkChange;
import hudson.Extension;
import hudson.Util;
Expand Down Expand Up @@ -113,6 +114,7 @@
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
import jenkins.util.SystemProperties;

import static hudson.Functions.printStackTrace;

Expand All @@ -126,6 +128,10 @@ public abstract class MultiBranchProject<P extends Job<P, R> & TopLevelItem,
R extends Run<P, R>>
extends ComputedFolder<P> implements SCMSourceOwner, IconSpec {

@SuppressFBWarnings(value = "MS_SHOULD_BE_FINAL", justification = "Accessible via System Groovy Scripts")
private static /* not final */ boolean FIRE_SCM_SOURCE_BUILDS_AFTER_SAVE =
SystemProperties.getBoolean(MultiBranchProject.class.getName() + ".fireSCMSourceBuildsAfterSave", true);

/**
* Our logger.
*/
Expand Down Expand Up @@ -233,7 +239,7 @@ public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOExcep
}
}
}
if (Items.currentlyUpdatingByXml()) {
if (Items.currentlyUpdatingByXml() && FIRE_SCM_SOURCE_BUILDS_AFTER_SAVE) {
fireSCMSourceAfterSave(getSCMSources());
if (isBuildable()) {
scheduleBuild();
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/integration/UpdatingFromXmlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void given_multibranch_when_createFromXml_then_hasItems() throws Exceptio
}

@Test
public void given_multibranch_when_upateFromXml_then_hasItems() throws Exception {
public void given_multibranch_when_updateFromXml_then_hasItems() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
c.cloneBranch("foo", "master", "feature");
Expand Down
67 changes: 67 additions & 0 deletions src/test/java/integration/UpdatingFromXmlWithDisabledFlagTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package integration;

import hudson.model.TopLevelItem;
import integration.harness.BasicMultiBranchProject;
import jenkins.scm.impl.mock.MockSCMController;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.ReaderInputStream;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.Rule;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.FlagRule;

import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import java.io.StringReader;

import static junit.framework.TestCase.assertTrue;

public class UpdatingFromXmlWithDisabledFlagTest {

/**
* All tests in this class only create items and do not affect other global configuration, thus we trade test
* execution time for the restriction on only touching items.
*/
@ClassRule
public static JenkinsRule r = new JenkinsRule();

@Rule
public FlagRule flagRule = FlagRule.systemProperty("jenkins.branch.MultiBranchProject.fireSCMSourceBuildsAfterSave", "false");

@Before
public void cleanOutAllItems() throws Exception {
for (TopLevelItem i : r.getInstance().getItems()) {
i.delete();
}
}

@Test
public void given_multibranch_when_createFromXml_is_disabled_then_hasNoItems() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
c.cloneBranch("foo", "master", "feature");
c.addFile("foo", "feature", "add new feature", "FEATURE", "new".getBytes());
String configXml = IOUtils.toString(getClass().getResourceAsStream("UpdatingFromXmlTest/config.xml")).replace("fixme", c.getId());
BasicMultiBranchProject prj = (BasicMultiBranchProject) r.jenkins.createProjectFromXML("foo", new ReaderInputStream(new StringReader(configXml)));
r.waitUntilNoActivity();
assertTrue(prj.getItems().isEmpty());
}
}

@Test
public void given_multibranch_when_updateFromXml_is_disabled_then_hasNoItems() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
c.cloneBranch("foo", "master", "feature");
c.addFile("foo", "feature", "add new feature", "FEATURE", "new".getBytes());
String configXml = IOUtils.toString(getClass().getResourceAsStream("UpdatingFromXmlTest/config.xml")).replace("fixme", c.getId());
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.updateByXml((Source) new StreamSource(new StringReader(configXml)));
r.waitUntilNoActivity();
assertTrue(prj.getItems().isEmpty());
}
}

}

0 comments on commit dd833d8

Please sign in to comment.