diff --git a/src/main/java/jenkins/branch/ItemColumn.java b/src/main/java/jenkins/branch/ItemColumn.java new file mode 100644 index 00000000..df102df7 --- /dev/null +++ b/src/main/java/jenkins/branch/ItemColumn.java @@ -0,0 +1,121 @@ +/* + * The MIT License + * + * Copyright (c) 2017 CloudBees, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package jenkins.branch; + +import hudson.Extension; +import hudson.Util; +import hudson.markup.MarkupFormatter; +import hudson.model.Actionable; +import hudson.model.Descriptor; +import hudson.model.DescriptorVisibilityFilter; +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.kohsuke.accmod.Restricted; +import org.kohsuke.accmod.restrictions.NoExternalUse; +import org.kohsuke.stapler.DataBoundConstructor; + +/** + * Like {@link JobColumn} only is aware of {@link PrimaryInstanceMetadataAction} and {@link ObjectMetadataAction} + * + * @since 2.0.1 + */ +@Restricted(NoExternalUse.class) // we are not exposing this outside of +public class ItemColumn extends ListViewColumn { + /** + * Default constructor + */ + @DataBoundConstructor + public ItemColumn() { + } + + /** + * Determines if the item has a {@link PrimaryInstanceMetadataAction}. + * + * @param job the item. + * @return {@code true} if and only if the item has a {@link PrimaryInstanceMetadataAction}. + */ + @SuppressWarnings("unused") // used via Jelly EL binding + public boolean isPrimary(Object job) { + return job instanceof Actionable && ((Actionable) job).getAction(PrimaryInstanceMetadataAction.class) != null; + } + + /** + * Gets the description of a job. + * + * @param job the job. + * @return the description. + */ + @SuppressWarnings("unused") // used via Jelly EL binding + public String getDescription(Object job) { + if (job instanceof Actionable) { + ObjectMetadataAction action = ((Actionable)job).getAction(ObjectMetadataAction.class); + String description = action != null ? action.getObjectDescription() : null; + return description != null ? Util.escape(description) : null; + } + return null; + } + + /** + * Our extension. + */ + @Extension + public static class DescriptorImpl extends ListViewColumnDescriptor { + /** + * {@inheritDoc} + */ + @Override + public String getDisplayName() { + return Messages.ItemColumn_DisplayName(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean shownByDefault() { + return false; + } + } + + /** + * Hide this column from user views as it would only confuse them. + */ + @Extension + public static class DescriptorVisibilityFilterImpl extends DescriptorVisibilityFilter { + + /** + * {@inheritDoc} + */ + @Override + public boolean filter(Object context, Descriptor descriptor) { + return !(descriptor instanceof BranchStatusColumn.DescriptorImpl) + || context instanceof MultiBranchProjectViewHolder.ViewImpl + || context instanceof OrganizationFolderViewHolder.ViewImpl; + } + } +} diff --git a/src/main/java/jenkins/branch/MultiBranchProjectViewHolder.java b/src/main/java/jenkins/branch/MultiBranchProjectViewHolder.java index de836242..9febf499 100644 --- a/src/main/java/jenkins/branch/MultiBranchProjectViewHolder.java +++ b/src/main/java/jenkins/branch/MultiBranchProjectViewHolder.java @@ -36,6 +36,7 @@ import hudson.security.ACL; import hudson.security.Permission; import hudson.util.DescribableList; +import hudson.views.JobColumn; import hudson.views.ListViewColumn; import hudson.views.StatusColumn; import hudson.views.ViewsTabBar; @@ -210,6 +211,7 @@ public ViewImpl(ViewGroup owner, @NonNull SCMHeadCategory category) { getJobFilters().replaceBy(Collections.singletonList(new BranchCategoryFilter(category))); DescribableList> columns = getColumns(); columns.replace(columns.get(StatusColumn.class), new BranchStatusColumn()); + columns.replace(columns.get(JobColumn.class), new ItemColumn()); } catch (IOException e) { // ignore } diff --git a/src/main/java/jenkins/branch/OrganizationFolderViewHolder.java b/src/main/java/jenkins/branch/OrganizationFolderViewHolder.java index 0a156610..dbfe541d 100644 --- a/src/main/java/jenkins/branch/OrganizationFolderViewHolder.java +++ b/src/main/java/jenkins/branch/OrganizationFolderViewHolder.java @@ -203,7 +203,7 @@ public ViewImpl(ViewGroup owner, @NonNull SCMSourceCategory category) { getColumns().replaceBy(asList( new StatusColumn(), new WeatherColumn(), - new JobColumn(), + new ItemColumn(), new DescriptionColumn() )); } catch (IOException e) { diff --git a/src/main/resources/jenkins/branch/ItemColumn/column.jelly b/src/main/resources/jenkins/branch/ItemColumn/column.jelly new file mode 100644 index 00000000..294e2566 --- /dev/null +++ b/src/main/resources/jenkins/branch/ItemColumn/column.jelly @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/jenkins/branch/ItemColumn/columnHeader.jelly b/src/main/resources/jenkins/branch/ItemColumn/columnHeader.jelly new file mode 100644 index 00000000..5f0b0de2 --- /dev/null +++ b/src/main/resources/jenkins/branch/ItemColumn/columnHeader.jelly @@ -0,0 +1,28 @@ + + + + + ${it.descriptor.displayName} + diff --git a/src/main/resources/jenkins/branch/Messages.properties b/src/main/resources/jenkins/branch/Messages.properties index 5ae88ed9..61babd01 100644 --- a/src/main/resources/jenkins/branch/Messages.properties +++ b/src/main/resources/jenkins/branch/Messages.properties @@ -25,6 +25,7 @@ BaseEmptyView.displayName=Welcome BranchStatusColumn.displayName=Status DefaultBranchPropertyStrategy.DisplayName=All branches get the same properties DescriptionColumn.displayName=Project description +ItemColumn.DisplayName=Name NamedExceptionsBranchPropertyStrategy.DisplayName=Named branches get different properties NoTriggerBranchProperty.suppress_automatic_scm_triggering=Suppress automatic SCM triggering RateLimitBranchProperty.ApproxDaysBetweenBuilds=Approximately {0,choice,1\#a day|1<{0,number,integer} days} between builds