Skip to content

Commit

Permalink
Merge pull request #95 from stephenc/jenkins-34691
Browse files Browse the repository at this point in the history
[JENKINS-34691] Adopt proposed veto mechanism
  • Loading branch information
stephenc committed Mar 15, 2017
2 parents d7f50ea + 7b2dafd commit f4ffb3e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/jenkins/branch/MultiBranchProject.java
Expand Up @@ -44,6 +44,7 @@
import hudson.model.Cause;
import hudson.model.CauseAction;
import hudson.model.Descriptor;
import hudson.model.Failure;
import hudson.model.Item;
import hudson.model.ItemGroup;
import hudson.model.Items;
Expand All @@ -54,6 +55,7 @@
import hudson.model.TaskListener;
import hudson.model.TopLevelItem;
import hudson.model.View;
import hudson.model.listeners.ItemListener;
import hudson.model.listeners.SaveableListener;
import hudson.scm.PollingResult;
import hudson.security.ACL;
Expand Down Expand Up @@ -2229,4 +2231,18 @@ public final XmlFile getStateFile() {
return new XmlFile(Items.XSTREAM, new File(owner.getRootDir(), "state.xml"));
}
}

/**
* Veto attempts to copy branch projects outside of their multibranch container. Only works on Jenkins core
* versions with JENKINS-34691 merged.
*/
@Extension
public static class CopyItemVeto extends ItemListener {
//@Override // TODO once Jenkins 2.51+ which has JENKINS-34691 merged
public void onCheckCopy(Item item, ItemGroup parent) throws Failure {
if (item.getParent() instanceof MultiBranchProject) {
throw new Failure(Messages.MultiBranchProject_CopyItemVeto_reason());
}
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/jenkins/branch/Messages.properties
Expand Up @@ -41,6 +41,7 @@ RateLimitBranchProperty.duration.week=Week
RateLimitBranchProperty.duration.month=Month
RateLimitBranchProperty.duration.year=Year
MultiBranchProject.BranchIndexing.displayName=Scan {0}
MultiBranchProject.CopyItemVeto.reason=Copying branch projects outside of their multi-branch container is not supported.
OrganizationFolder.OrganizationScan.displayName=Scan {0}
OrganizationFolder.DefaultPronoun=Organization
OrganizationFolder.DefaultProject=Multibranch
Expand Down

0 comments on commit f4ffb3e

Please sign in to comment.