Skip to content
Permalink
Browse files
Merge pull request #44 from oleg-nenashev/JENKINS-28881
[JENKINS-28881] - Folders plugin support
  • Loading branch information
oleg-nenashev committed Feb 2, 2016
2 parents 9d49867 + a188d3e commit fe99e468f024c217fda09b75900f74ac38d1e806
Showing 52 changed files with 2,433 additions and 200 deletions.
20 pom.xml
@@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.509.3</version>
<version>1.609.3</version>
</parent>

<groupId>com.synopsys.jenkinsci</groupId>
@@ -81,13 +81,31 @@
<version>0.1</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>cloudbees-folder</artifactId>
<version>5.1</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>authorize-project</artifactId>
<version>1.0.2</version>
<optional>true</optional>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<version>1.6</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-auth</artifactId>
<version>1.2</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>mailer</artifactId>
@@ -219,6 +219,43 @@ public boolean hasPrimaryOwner() {
public boolean isPrimaryOwner(User user) {
return user != null && user == getPrimaryOwner();
}

@Override
public int hashCode() {
int hash = 7;
hash = 41 * hash + (this.ownershipEnabled ? 1 : 0);
hash = 41 * hash + (this.primaryOwnerId != null ? this.primaryOwnerId.hashCode() : 0);
hash = 41 * hash + (this.coownersIds != null ? this.coownersIds.hashCode() : 0);
return hash;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final OwnershipDescription other = (OwnershipDescription) obj;
if (this.ownershipEnabled != other.ownershipEnabled) {
return false;
} else if (!this.ownershipEnabled) {
// Treat disabled ownership configurations as equal ones
return true;
}

if ((this.primaryOwnerId == null) ? (other.primaryOwnerId != null) : !this.primaryOwnerId.equals(other.primaryOwnerId)) {
return false;
}
if (this.coownersIds != other.coownersIds && (this.coownersIds == null || !this.coownersIds.equals(other.coownersIds))) {
return false;
}
return true;
}

/**
* Check if ownership is enabled.
@@ -32,6 +32,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.jenkinsci.plugins.ownership.config.DisplayOptions;
import org.jenkinsci.plugins.ownership.config.InheritanceOptions;
import org.jenkinsci.plugins.ownership.model.runs.OwnershipRunListener;
import org.jenkinsci.plugins.ownership.util.environment.EnvSetupOptions;
import org.kohsuke.stapler.DataBoundConstructor;
@@ -47,6 +48,7 @@ public class OwnershipPluginConfiguration
private final ItemOwnershipPolicy itemOwnershipPolicy;
private final @CheckForNull MailOptions mailOptions;
private final @CheckForNull DisplayOptions displayOptions;
private final @CheckForNull InheritanceOptions inheritanceOptions;

/**
* Enforces the injection of ownership variables in {@link OwnershipRunListener}.
@@ -55,14 +57,22 @@ public class OwnershipPluginConfiguration
*/
private final @CheckForNull EnvSetupOptions globalEnvSetupOptions;

@DataBoundConstructor
@Deprecated
public OwnershipPluginConfiguration(@Nonnull ItemOwnershipPolicy itemOwnershipPolicy,
@Nonnull MailOptions mailOptions, EnvSetupOptions globalEnvSetupOptions,
@Nonnull DisplayOptions displayOptions) {
this(itemOwnershipPolicy, mailOptions, globalEnvSetupOptions, displayOptions, InheritanceOptions.DEFAULT);
}

@DataBoundConstructor
public OwnershipPluginConfiguration(@Nonnull ItemOwnershipPolicy itemOwnershipPolicy,
@Nonnull MailOptions mailOptions, EnvSetupOptions globalEnvSetupOptions,
@Nonnull DisplayOptions displayOptions, @Nonnull InheritanceOptions inheritanceOptions) {
this.itemOwnershipPolicy = itemOwnershipPolicy;
this.mailOptions = mailOptions;
this.globalEnvSetupOptions = globalEnvSetupOptions;
this.displayOptions = displayOptions;
this.inheritanceOptions = inheritanceOptions;
}

@Deprecated
@@ -93,6 +103,10 @@ public OwnershipPluginConfiguration(@Nonnull ItemOwnershipPolicy itemOwnershipPo
public @Nonnull DisplayOptions getDisplayOptions() {
return displayOptions != null ? displayOptions : DisplayOptions.DEFAULT;
}

public InheritanceOptions getInheritanceOptions() {
return inheritanceOptions != null ? inheritanceOptions : InheritanceOptions.DEFAULT;
}

/**
* @return Global environment inject options. Null - global setup is disabled
@@ -48,7 +48,7 @@ public AssignCreatorPolicy() {
@Override
public OwnershipDescription onCreated(Item item) {
User creator = User.current();
if (creator != null && creator != User.getUnknown() && item instanceof Job) {
if (creator != null && creator != User.getUnknown()) {
return new OwnershipDescription(true, creator.getId(), null);
}

@@ -23,16 +23,21 @@
*/
package com.synopsys.arc.jenkins.plugins.ownership.jobs;

import com.synopsys.arc.jenkins.plugins.ownership.IOwnershipHelper;
import com.synopsys.arc.jenkins.plugins.ownership.OwnershipDescription;
import com.synopsys.arc.jenkins.plugins.ownership.OwnershipPlugin;
import com.synopsys.arc.jenkins.plugins.ownership.OwnershipPluginConfiguration;
import com.synopsys.arc.jenkins.plugins.ownership.security.itemspecific.ItemSpecificSecurity;
import com.synopsys.arc.jenkins.plugins.ownership.util.AbstractOwnershipHelper;
import com.synopsys.arc.jenkins.plugins.ownership.util.UserCollectionFilter;
import com.synopsys.arc.jenkins.plugins.ownership.util.userFilters.AccessRightsFilter;
import com.synopsys.arc.jenkins.plugins.ownership.util.userFilters.IUserFilter;
import com.synopsys.arc.jenkins.plugins.ownership.wrappers.OwnershipBuildWrapper;
import hudson.Extension;
import hudson.matrix.MatrixConfiguration;
import hudson.model.AbstractBuild;
import hudson.model.Item;
import hudson.model.ItemGroup;
import hudson.model.Job;
import hudson.model.JobProperty;
import hudson.model.Project;
@@ -42,6 +47,9 @@
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.jenkinsci.plugins.ownership.model.OwnershipHelperLocator;
import org.jenkinsci.plugins.ownership.model.OwnershipInfo;
import org.jenkinsci.plugins.ownership.model.jobs.JobOwnershipDescriptionSource;

/**
* Helper for Jobs Ownership.
@@ -53,9 +61,12 @@ public class JobOwnerHelper extends AbstractOwnershipHelper<Job<?,?>> {
public final static JobOwnerHelper Instance = new JobOwnerHelper();

/**
* Gets JobOwnerProperty from job if possible.
* Gets {@link JobOwnerJobProperty} from the job if possible.
* The function also handles multi-configuration jobs, so it should be used
* wherever it is possible.
* <p/>
* This method should not be used to retrieve Ownership descriptions,
* because it does not take inheritance into account.
* @param job Job
* @return JobOwnerJobProperty or null if it is not configured
*/
@@ -86,8 +97,42 @@ public static boolean isUserExists(@Nonnull String userIdOrFullName) {

@Override
public @Nonnull OwnershipDescription getOwnershipDescription(@Nonnull Job<?, ?> job) {
// TODO: Maybe makes sense to unwrap the method to get a better performance (esp. for Security)
return getOwnershipInfo(job).getDescription();
}

@Override
public OwnershipInfo getOwnershipInfo(Job<?, ?> job) {
JobOwnerJobProperty prop = getOwnerProperty(job);
return (prop != null) ? prop.getOwnership() : OwnershipDescription.DISABLED_DESCR;
if (prop != null) {
OwnershipDescription d = prop.getOwnership();
if (d.isOwnershipEnabled()) {
// If Ownership on this level is enabled, we return it
return new OwnershipInfo(d, new JobOwnershipDescriptionSource(job));
}
}

// We go to upper items in order to get the ownership description
if (!OwnershipPluginConfiguration.get().getInheritanceOptions().isBlockInheritanceFromItemGroups()) {
ItemGroup parent = job.getParent();
AbstractOwnershipHelper<ItemGroup> located = OwnershipHelperLocator.locate(parent);
while (located != null) {
OwnershipInfo fromParent = located.getOwnershipInfo(parent);
if (fromParent.getDescription().isOwnershipEnabled()) {
return fromParent;
}
if (parent instanceof Item) {
Item parentItem = (Item)parent;
parent = parentItem.getParent();
located = OwnershipHelperLocator.locate(parent);
} else {
located = null;
}
}
}

// Fallback: we have not found the Ownership using known approaches
return OwnershipInfo.DISABLED_INFO;
}

/**
@@ -146,4 +191,16 @@ public String getItemDisplayName(Job<?, ?> item) {
public String getItemURL(Job<?, ?> item) {
return item.getUrl();
}

@Extension
public static class LocatorImpl extends OwnershipHelperLocator<Job<?,?>> {

@Override
public AbstractOwnershipHelper<Job<?,?>> findHelper(Object item) {
if (item instanceof Job<?,?>) {
return Instance;
}
return null;
}
}
}
@@ -32,6 +32,7 @@
import java.util.Collection;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.jenkinsci.plugins.ownership.model.OwnershipInfo;

/**
* Provides ownership helper for {@link Computer}.
@@ -48,12 +49,21 @@ public static ComputerOwnerHelper getInstance() {

@Override
public OwnershipDescription getOwnershipDescription(@Nonnull Computer item) {
// TODO: This method impl is a performance hack. May be replaced by getOwnershipInfo() in 1.0
Node node = item.getNode();
return node != null
? NodeOwnerHelper.Instance.getOwnershipDescription(node)
: OwnershipDescription.DISABLED_DESCR; // No node - no ownership
}


@Override
public OwnershipInfo getOwnershipInfo(Computer item) {
Node node = item.getNode();
return node != null
? NodeOwnerHelper.Instance.getOwnershipInfo(node)
: OwnershipInfo.DISABLED_INFO;
}

@Override
public Collection<User> getPossibleOwners(@Nonnull Computer computer) {
Node node = computer.getNode();
@@ -37,6 +37,9 @@
import java.util.Collection;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.jenkinsci.plugins.ownership.model.OwnershipDescriptionSource;
import org.jenkinsci.plugins.ownership.model.OwnershipInfo;
import org.jenkinsci.plugins.ownership.model.nodes.NodeOwnershipDescriptionSource;

/**
* Provides helper for Node owner.
@@ -63,13 +66,25 @@ public static OwnerNodeProperty getOwnerProperty(@Nonnull Node node) {

@Override
public OwnershipDescription getOwnershipDescription(Node item) {
// TODO: This method impl is a performance hack. May be replaced by getOwnershipInfo() in 1.0
if (item == null) { // Handle renames, etc.
return OwnershipDescription.DISABLED_DESCR;
}

OwnerNodeProperty prop = getOwnerProperty(item);
return prop != null ? prop.getOwnership() : OwnershipDescription.DISABLED_DESCR;
}

@Override
public OwnershipInfo getOwnershipInfo(Node item) {
if (item == null) { // Handle renames, etc.
return OwnershipInfo.DISABLED_INFO;
}

OwnerNodeProperty prop = getOwnerProperty(item);
return prop != null ? new OwnershipInfo(OwnershipDescription.DISABLED_DESCR,
new NodeOwnershipDescriptionSource(item)) : OwnershipInfo.DISABLED_INFO;
}

@Override
public Collection<User> getPossibleOwners(Node item) {
@@ -33,6 +33,8 @@
import java.util.Collection;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.jenkinsci.plugins.ownership.model.OwnershipInfo;
import org.jenkinsci.plugins.ownership.model.nodes.NodeOwnershipDescriptionSource;

/**
* Provides helper for Node owner
@@ -57,10 +59,20 @@ private static OwnerNodeProperty getOwnerProperty(@CheckForNull NodeProperty nod
@Nonnull
@Override
public OwnershipDescription getOwnershipDescription(@CheckForNull NodeProperty item) {
// TODO: This method impl is a performance hack. May be replaced by getOwnershipInfo() in 1.0
OwnerNodeProperty prop = getOwnerProperty(item);
OwnershipDescription descr = (prop != null) ? prop.getOwnership() : null;
return descr != null ? descr : OwnershipDescription.DISABLED_DESCR;
}

@Override
public OwnershipInfo getOwnershipInfo(NodeProperty item) {
OwnerNodeProperty prop = getOwnerProperty(item);
OwnershipDescription descr = (prop != null) ? prop.getOwnership() : null;
return descr != null
? new OwnershipInfo(descr, new NodeOwnershipDescriptionSource(getNode(item)))
: OwnershipInfo.DISABLED_INFO;
}

@Nonnull
@Override

0 comments on commit fe99e46

Please sign in to comment.