Skip to content

Commit

Permalink
Merge pull request #44 from oleg-nenashev/JENKINS-28881
Browse files Browse the repository at this point in the history
[JENKINS-28881] - Folders plugin support
  • Loading branch information
oleg-nenashev committed Feb 2, 2016
2 parents 9d49867 + a188d3e commit fe99e46
Show file tree
Hide file tree
Showing 52 changed files with 2,433 additions and 200 deletions.
20 changes: 19 additions & 1 deletion pom.xml
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
Expand Up @@ -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.
Expand Down
Expand Up @@ -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;
Expand All @@ -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}.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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);
}

Expand Down
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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
*/
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}
}
}
Expand Up @@ -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}.
Expand All @@ -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();
Expand Down
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit fe99e46

Please sign in to comment.