Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental 'Details' widget for builds #10147

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1c71f4c
Init
janfaracik Jan 9, 2025
991f787
Update DurationDetail.java
janfaracik Jan 9, 2025
f4f8ec9
Sorting out stuff
janfaracik Jan 9, 2025
701e7a7
Update Functions.java
janfaracik Jan 9, 2025
959a43b
Use passed in run
janfaracik Jan 9, 2025
4deafbd
Cleanup
janfaracik Jan 9, 2025
1a7bd33
Update DetailFactory.java
janfaracik Jan 9, 2025
abf4d00
Update Functions.java
janfaracik Jan 9, 2025
73a48c0
Make group of() private
janfaracik Jan 9, 2025
5d13a62
Update DetailGroup.java
janfaracik Jan 9, 2025
0da339b
Tidy up
janfaracik Jan 9, 2025
8886cd9
Push
janfaracik Jan 9, 2025
6fd6b1b
Update Detail.java
janfaracik Jan 9, 2025
8cdc3a6
Update Functions.java
janfaracik Jan 9, 2025
538ba93
Update DetailFactory.java
janfaracik Jan 9, 2025
c1cbb0d
Update DetailFactory.java
janfaracik Jan 9, 2025
cac4625
Update DetailGroup.java
janfaracik Jan 10, 2025
c649255
Add isApplicable
janfaracik Jan 10, 2025
b4b01ee
Update DetailGroup.java
janfaracik Jan 10, 2025
64babad
Update grid
janfaracik Jan 10, 2025
7f11407
Apply suggestions from code review
timja Jan 13, 2025
d6cf74c
Merge branch 'master' into experimental-details-widget
janfaracik Jan 13, 2025
c53e9d5
Remove Javadoc implNote
janfaracik Jan 13, 2025
3647925
Add getUrl
janfaracik Jan 13, 2025
cd2d792
Update _cards.scss
janfaracik Jan 13, 2025
0085d2c
Update _cards.scss
janfaracik Jan 13, 2025
89d64f0
Update _cards.scss
janfaracik Jan 13, 2025
924683c
Update _cards.scss
janfaracik Jan 13, 2025
bfcbed3
Update _cards.scss
janfaracik Jan 13, 2025
b7dbb88
Update _cards.scss
janfaracik Jan 13, 2025
64929b5
Update _build.scss
janfaracik Jan 13, 2025
d3ad66e
Move details to jenkins from hudson
janfaracik Jan 13, 2025
a7878e7
Replace flippy timestamp with tooltip (with a delay)
janfaracik Jan 13, 2025
cbf4681
Update _cards.scss
janfaracik Jan 13, 2025
72e1ab0
Update core/src/main/java/jenkins/model/Detail.java
janfaracik Jan 14, 2025
2e85c62
Drop isApplicable
janfaracik Jan 14, 2025
aff8281
Update detail.jelly
janfaracik Jan 14, 2025
91c8e48
Merge branch 'master' into experimental-details-widget
janfaracik Jan 15, 2025
aac7d48
Update on comments
janfaracik Jan 15, 2025
d09ffe9
Merge branch 'master' into experimental-details-widget
janfaracik Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import hudson.init.InitMilestone;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.Actionable;
import hudson.model.Computer;
import hudson.model.Describable;
import hudson.model.Descriptor;
Expand Down Expand Up @@ -161,6 +162,9 @@
import jenkins.console.ConsoleUrlProvider;
import jenkins.console.DefaultConsoleUrlProvider;
import jenkins.console.WithConsoleUrl;
import jenkins.model.Detail;
import jenkins.model.DetailFactory;
import jenkins.model.DetailGroup;
import jenkins.model.GlobalConfiguration;
import jenkins.model.GlobalConfigurationCategory;
import jenkins.model.Jenkins;
Expand Down Expand Up @@ -2586,6 +2590,33 @@ public static String generateItemId() {
return String.valueOf(Math.floor(Math.random() * 3000));
}

/**
* Returns a grouped list of Detail objects for the given Actionable object
janfaracik marked this conversation as resolved.
Show resolved Hide resolved
*/
@Restricted(NoExternalUse.class)
public static Map<DetailGroup, List<Detail>> getDetailsFor(Actionable object) {
List<Detail> details = new ArrayList<>();

for (DetailFactory taf : DetailFactory.factoriesFor(object.getClass())) {
details.addAll(taf.createFor(object));
}

Map<DetailGroup, List<Detail>> orderedMap = new TreeMap<>(Comparator.comparingInt(DetailGroup::getOrder));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so weird only because it doesn't use @Extension.


for (Detail detail : details) {
if (detail.isApplicable()) {
orderedMap.computeIfAbsent(detail.getGroup(), k -> new ArrayList<>()).add(detail);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not extensible if it doesn't handle getOrder clashes gracefully.

}
}

for (Map.Entry<DetailGroup, List<Detail>> entry : orderedMap.entrySet()) {
List<Detail> detailList = entry.getValue();
detailList.sort(Comparator.comparingInt(Detail::getOrder));
}

return orderedMap;
}

@Restricted(NoExternalUse.class)
public static ExtensionList<SearchFactory> getSearchFactories() {
return SearchFactory.all();
Expand Down
18 changes: 18 additions & 0 deletions core/src/main/java/hudson/model/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import hudson.AbortException;
import hudson.BulkChange;
import hudson.EnvVars;
import hudson.Extension;
import hudson.ExtensionList;
import hudson.ExtensionPoint;
import hudson.FeedAdapter;
Expand All @@ -53,6 +54,8 @@
import hudson.console.ModelHyperlinkNote;
import hudson.console.PlainTextConsoleOutputStream;
import hudson.model.Descriptor.FormException;
import hudson.model.details.DurationDetail;
import hudson.model.details.TimestampDetail;
import hudson.model.listeners.RunListener;
import hudson.model.listeners.SaveableListener;
import hudson.model.queue.SubTask;
Expand Down Expand Up @@ -115,6 +118,8 @@
import jenkins.model.ArtifactManagerConfiguration;
import jenkins.model.ArtifactManagerFactory;
import jenkins.model.BuildDiscarder;
import jenkins.model.Detail;
import jenkins.model.DetailFactory;
import jenkins.model.HistoricalBuild;
import jenkins.model.Jenkins;
import jenkins.model.JenkinsLocationConfiguration;
Expand Down Expand Up @@ -2669,4 +2674,17 @@ public void doDynamic(StaplerRequest2 req, StaplerResponse2 rsp) throws IOExcept
out.flush();
}
}

@Extension
public static final class BasicRunDetailFactory extends DetailFactory<Run> {

@Override
public Class<Run> type() {
return Run.class;
}

@NonNull @Override public Collection<? extends Detail> createFor(@NonNull Run target) {
return List.of(new TimestampDetail(target), new DurationDetail(target));
}
}
}
14 changes: 14 additions & 0 deletions core/src/main/java/hudson/model/details/DurationDetail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package hudson.model.details;
janfaracik marked this conversation as resolved.
Show resolved Hide resolved

import hudson.model.Run;
import jenkins.model.Detail;

/**
* Displays the duration of the given run, or, if the run has completed, shows the total time it took to execute
*/
public class DurationDetail extends Detail {

public DurationDetail(Run<?, ?> run) {
super(run);
}
}
14 changes: 14 additions & 0 deletions core/src/main/java/hudson/model/details/TimestampDetail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package hudson.model.details;
janfaracik marked this conversation as resolved.
Show resolved Hide resolved

import hudson.model.Run;
import jenkins.model.Detail;

/**
* Displays the start time of the given run
*/
public class TimestampDetail extends Detail {

public TimestampDetail(Run<?, ?> run) {
super(run);
}
}
74 changes: 74 additions & 0 deletions core/src/main/java/jenkins/model/Detail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package jenkins.model;

import edu.umd.cs.findbugs.annotations.Nullable;
import hudson.model.Actionable;
import hudson.model.ModelObject;
import hudson.model.Run;
import org.jenkins.ui.icon.IconSpec;

/**
* {@link Detail} represents a piece of information about a {@link Run}.
* Such information could include:
* <ul>
* <li>the date and time the run started</li>
* <li>the amount of time the run took to complete</li>
* <li>SCM information for the build</li>
* <li>who kicked the build off</li>
* </ul>
* @since TODO
*/
public abstract class Detail implements ModelObject, IconSpec {

private final Actionable object;

public Detail(Actionable object) {
this.object = object;
}

public Actionable getObject() {
return object;
}

/**
* {@inheritDoc}
*/
public @Nullable String getIconClassName() {
return null;
}

/**
* {@inheritDoc}
*/
@Override
public @Nullable String getDisplayName() {
return null;
}

/**
* Optional URL for the {@link Detail}
*/
public @Nullable String getUrl() {
return null;
}
janfaracik marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns true if this detail is applicable to the given Actionable object
*/
public boolean isApplicable() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Action this would be the job of the factory. Why create an object just to discard it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair, I was using isApplicable to encapsulate show/hide logic of the detail inside of the Detail, so that its factory didn't need to worry about that.

return true;
}

/**
* @return the grouping of the detail
*/
public DetailGroup getGroup() {
return DetailGroup.GENERAL;
}

/**
* @return order in the group, zero is first, MAX_VALUE is any order
*/
public int getOrder() {
return Integer.MAX_VALUE;
}
}
58 changes: 58 additions & 0 deletions core/src/main/java/jenkins/model/DetailFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* The MIT License
*
* Copyright 2025 Jan Faracik
*
* 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.model;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.ExtensionList;
import hudson.ExtensionPoint;
import hudson.model.Actionable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

/**
* Allows you to add multiple details to an Actionable object at once.
* @param <T> the type of object to add to; typically an {@link Actionable} subtype
* @since TODO
*/
public abstract class DetailFactory<T extends Actionable> implements ExtensionPoint {

public abstract Class<T> type();

public abstract @NonNull Collection<? extends Detail> createFor(@NonNull T target);

@Restricted(NoExternalUse.class)
public static <T extends Actionable> Iterable<DetailFactory<T>> factoriesFor(Class<T> type) {
List<DetailFactory<T>> result = new ArrayList<>();
for (DetailFactory<T> wf : ExtensionList.lookup(DetailFactory.class)) {
if (wf.type().isAssignableFrom(type)) {
result.add(wf);
}
}
return result;
}
}
25 changes: 25 additions & 0 deletions core/src/main/java/jenkins/model/DetailGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package jenkins.model;

/**
* Represents a group for categorizing {@link Detail}, each with an associated order.
*/
public class DetailGroup {

private final int order;

private DetailGroup(int order) {
if (order < 0) {
throw new RuntimeException("Orders cannot be less than 0");
}

this.order = order;
}

public static DetailGroup SCM = new DetailGroup(0);

public static DetailGroup GENERAL = new DetailGroup(Integer.MAX_VALUE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these not @Extension(ordinal = …)?


public int getOrder() {
return order;
}
}
69 changes: 41 additions & 28 deletions core/src/main/resources/hudson/model/Run/new-build-page.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -24,55 +24,68 @@ THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:i="jelly:fmt">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:x="jelly:xml">
<l:layout title="${it.fullDisplayName}">
<st:include page="sidepanel.jelly" />

<!-- no need for additional breadcrumb here as we're on an index page already including breadcrumb -->
<l:main-panel>
<script src="${resURL}/jsbundles/pages/job.js" type="text/javascript" defer="true" />

<j:set var="controls">
<t:editDescriptionButton permission="${it.UPDATE}"/>
<l:hasPermission permission="${it.UPDATE}">
<st:include page="logKeep.jelly" />
</l:hasPermission>
</j:set>

<t:buildCaption controls="${controls}">${it.displayName} (<i:formatDate value="${it.timestamp.time}" type="both" dateStyle="medium" timeStyle="medium"/>)</t:buildCaption>
<t:buildCaption controls="${controls}">${it.displayName}</t:buildCaption>

<div>
<t:editableDescription permission="${it.UPDATE}" hideButton="true"/>
</div>

<st:include page="console.jelly" from="${h.getConsoleProviderFor(it)}" optional="true" />

<div style="float:right; z-index: 1; position:relative; margin-left: 1em">
<div style="margin-top:1em">
${%startedAgo(it.timestampString)}
</div>
<div>
<j:if test="${it.building}">
${%beingExecuted(it.executor.timestampString)}
</j:if>
<j:if test="${!it.building}">
${%Took} <a href="${rootURL}/${it.parent.url}buildTimeTrend">${it.durationString}</a>
</j:if>
<st:include page="details.jelly" optional="true" />
</div>
</div>
<div class="app-build__grid">
<st:include page="console.jelly" from="${h.getConsoleProviderFor(it)}" optional="true" />
<l:card title="${%Details}">
<div class="jenkins-card__details">
<j:forEach var="group" items="${h.getDetailsFor(it)}" indexVar="index">
<j:if test="${index gt 0}">
<hr />
</j:if>
<j:forEach var="detail" items="${group.value}">
<st:include page="detail.jelly" it="${detail}" optional="true">
<x:element name="${detail.url != null ? 'a' : 'div'}">
<x:attribute name="class">jenkins-card__details__item</x:attribute>
<x:attribute name="href">${detail.url}</x:attribute>
<div class="jenkins-card__details__item__icon">
<l:icon src="${detail.iconClassName}" />
</div>
${detail.displayName}
</x:element>
</st:include>
</j:forEach>
</j:forEach>
</div>
</l:card>

<table>
<t:artifactList build="${it}" caption="${%Build Artifacts}"
permission="${it.ARTIFACTS}" />
<l:card title="Summary">
<div>
<table>
<t:artifactList build="${it}" caption="${%Build Artifacts}" permission="${it.ARTIFACTS}" />

<!-- give actions a chance to contribute summary item -->
<j:forEach var="a" items="${it.allActions}">
<st:include page="summary.jelly" from="${a}" optional="true" it="${a}" />
</j:forEach>
<!-- give actions a chance to contribute summary item -->
<j:forEach var="a" items="${it.allActions}">
<st:include page="summary.jelly" from="${a}" optional="true" it="${a}" />
</j:forEach>

<st:include page="summary.jelly" optional="true" />
</table>
<st:include page="summary.jelly" optional="true" />
</table>

<st:include page="main.jelly" optional="true" />
<st:include page="main.jelly" optional="true" />
</div>
</l:card>
</div>
</l:main-panel>
</l:layout>
</j:jelly>
Loading
Loading