Skip to content

Commit

Permalink
Merge pull request #81 from stephenc/jenkins-41927
Browse files Browse the repository at this point in the history
[FIXED JENKINS-41927] Orphaned branched should have name in strikethrough
  • Loading branch information
stephenc committed Feb 10, 2017
2 parents 4a57f3a + 7a7f2e2 commit 7ba1e7d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/main/java/jenkins/branch/ItemColumn.java
Expand Up @@ -28,12 +28,20 @@
import hudson.model.Actionable;
import hudson.model.Descriptor;
import hudson.model.DescriptorVisibilityFilter;
import hudson.model.ItemGroup;
import hudson.model.Job;
import hudson.model.TopLevelItem;
import hudson.remoting.Callable;
import hudson.security.ACL;
import hudson.views.JobColumn;
import hudson.views.ListViewColumn;
import hudson.views.ListViewColumnDescriptor;
import jenkins.scm.api.metadata.ObjectMetadataAction;
import jenkins.scm.api.metadata.PrimaryInstanceMetadataAction;
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.remoting.RoleChecker;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down Expand Up @@ -63,6 +71,40 @@ public boolean isPrimary(Object job) {
return job instanceof Actionable && ((Actionable) job).getAction(PrimaryInstanceMetadataAction.class) != null;
}

/**
* Determines if the item is orphaned.
* @param item the item.
* @return {@code true} if and only if the item is orphaned.
*/
public boolean isOrphaned(Object item) {
if (item instanceof Job) {
Job job = (Job) item;
ItemGroup parent = job.getParent();
if (parent instanceof MultiBranchProject) {
BranchProjectFactory factory = ((MultiBranchProject) parent).getProjectFactory();
return factory.isProject(job) && factory.getBranch(job) instanceof Branch.Dead;
}
}
if (item instanceof MultiBranchProject) {
MultiBranchProject<?,?> project = (MultiBranchProject<?,?>) item;
BranchProjectFactory factory = project.getProjectFactory();
SecurityContext ctx = ACL.impersonate(ACL.SYSTEM);
try {
for (Job c: project.getItems()) {
if (factory.isProject(c) && !(factory.getBranch(c) instanceof Branch.Dead)) {
// if we have at least one not-dead branch then the project is alive
return false;
}
}
// if we have no child projects or all child projects are dead, then the project is dead
return true;
} finally {
SecurityContextHolder.setContext(ctx);
}
}
return false;
}

/**
* Gets the tool-tip title of a job.
*
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/jenkins/branch/ItemColumn/column.jelly
Expand Up @@ -27,6 +27,13 @@ THE SOFTWARE.
xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<td style="${indenter.getCss(job)}">
<j:choose>
<j:when test="${it.isOrphaned(job)}">
<s>
<a href="${jobBaseUrl}${job.shortUrl}" class='model-link inside' title="${it.getTitle(job)}">
<l:breakable value="${h.getRelativeDisplayNameFrom(job, itemGroup)}"/>
</a>
</s>
</j:when>
<j:when test="${it.isPrimary(job)}">
<strong>
<a href="${jobBaseUrl}${job.shortUrl}" class='model-link inside' title="${it.getTitle(job)}">
Expand Down

0 comments on commit 7ba1e7d

Please sign in to comment.