Skip to content

Commit

Permalink
Merge pull request #52 from oleg-nenashev/bug/JENKINS-38236-real
Browse files Browse the repository at this point in the history
[JENKINS38236,JENKINS-38235] - Prevent issues during ItemPolicy handling
  • Loading branch information
oleg-nenashev committed Sep 15, 2016
2 parents 1c9e093 + e9e1883 commit 2550b23
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Expand Up @@ -25,6 +25,7 @@
package com.synopsys.arc.jenkins.plugins.ownership;

import com.synopsys.arc.jenkins.plugins.ownership.extensions.ItemOwnershipPolicy;
import com.synopsys.arc.jenkins.plugins.ownership.extensions.item_ownership_policy.DropOwnershipPolicy;
import org.jenkinsci.plugins.ownership.util.mail.MailOptions;
import hudson.Extension;
import hudson.model.Describable;
Expand Down Expand Up @@ -87,7 +88,7 @@ public OwnershipPluginConfiguration(@Nonnull ItemOwnershipPolicy itemOwnershipPo
}

public @Nonnull ItemOwnershipPolicy getItemOwnershipPolicy() {
return itemOwnershipPolicy;
return itemOwnershipPolicy != null ? itemOwnershipPolicy : ItemOwnershipPolicy.getDefault();
}

public @Nonnull MailOptions getMailOptions() {
Expand Down
Expand Up @@ -25,6 +25,7 @@
package com.synopsys.arc.jenkins.plugins.ownership.extensions;

import com.synopsys.arc.jenkins.plugins.ownership.OwnershipDescription;
import com.synopsys.arc.jenkins.plugins.ownership.extensions.item_ownership_policy.DropOwnershipPolicy;
import hudson.DescriptorExtensionList;
import hudson.ExtensionPoint;
import hudson.model.Describable;
Expand All @@ -33,6 +34,8 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import jenkins.model.Jenkins;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

/**
* Implements an ownership changes policy for {@link Item}s.
Expand All @@ -42,6 +45,18 @@
public abstract class ItemOwnershipPolicy
implements ExtensionPoint, Describable<ItemOwnershipPolicy> {

private static final ItemOwnershipPolicy DEFAULT = new DropOwnershipPolicy();

/**
* Returns default Item Ownership Policy, which should be assigned on first startup.
* @return Ownership policy
*/
@Nonnull
@Restricted(NoExternalUse.class)
public static ItemOwnershipPolicy getDefault() {
return DEFAULT;
}

/**
* A handler for newly created items.
* By default, the ownership won't be set.
Expand All @@ -68,7 +83,7 @@ public abstract class ItemOwnershipPolicy
@Override
public ItemOwnershipPolicyDescriptor getDescriptor() {
return (ItemOwnershipPolicyDescriptor) Jenkins.getActiveInstance()
.getDescriptorOrDie(ItemOwnershipPolicy.class);
.getDescriptorOrDie(getClass());
}

/**
Expand Down

0 comments on commit 2550b23

Please sign in to comment.