Skip to content

Commit

Permalink
[FIXED JENKINS-40832] Primary branches should have their name in bold
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenc committed Jan 5, 2017
1 parent 682dbb0 commit b31929c
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -66,7 +66,7 @@

<properties>
<jenkins.version>1.642.3</jenkins.version>
<scm-api.version>2.0.1-beta-1</scm-api.version>
<scm-api.version>2.0.1-20170105.115402-8</scm-api.version>
</properties>

<repositories>
Expand Down
120 changes: 120 additions & 0 deletions src/main/java/jenkins/branch/ItemColumn.java
@@ -0,0 +1,120 @@
/*
* 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);
return action != null ? Util.escape(action.getObjectDescription()) : 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;
}
}
}
Expand Up @@ -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;
Expand Down Expand Up @@ -210,6 +211,7 @@ public ViewImpl(ViewGroup owner, @NonNull SCMHeadCategory category) {
getJobFilters().replaceBy(Collections.singletonList(new BranchCategoryFilter(category)));
DescribableList<ListViewColumn, Descriptor<ListViewColumn>> columns = getColumns();
columns.replace(columns.get(StatusColumn.class), new BranchStatusColumn());
columns.replace(columns.get(JobColumn.class), new ItemColumn());
} catch (IOException e) {
// ignore
}
Expand Down
Expand Up @@ -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) {
Expand Down
44 changes: 44 additions & 0 deletions src/main/resources/jenkins/branch/ItemColumn/column.jelly
@@ -0,0 +1,44 @@
<!--
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.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout"
xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<td style="${indenter.getCss(job)}">
<j:choose>
<j:when test="${it.isPrimary(job)}">
<strong>
<a href="${jobBaseUrl}${job.shortUrl}" class='model-link inside' title="${it.getDescription(job)}">
<l:breakable value="${h.getRelativeDisplayNameFrom(job, itemGroup)}"/>
</a>
</strong>
</j:when>
<j:otherwise>
<a href="${jobBaseUrl}${job.shortUrl}" class='model-link inside' title="${it.getDescription(job)}">
<l:breakable value="${h.getRelativeDisplayNameFrom(job, itemGroup)}"/>
</a>
</j:otherwise>
</j:choose>
</td>
</j:jelly>
28 changes: 28 additions & 0 deletions src/main/resources/jenkins/branch/ItemColumn/columnHeader.jelly
@@ -0,0 +1,28 @@
<!--
The MIT License
Copyright (c) 2004-2017, Sun Microsystems, Inc., Kohsuke Kawaguchi, Martin Eigenbrodt, 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.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core">
<th initialSortDir="down">${it.descriptor.displayName}</th>
</j:jelly>
1 change: 1 addition & 0 deletions src/main/resources/jenkins/branch/Messages.properties
Expand Up @@ -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
Expand Down

0 comments on commit b31929c

Please sign in to comment.