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

Init #192

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from
Draft

Init #192

Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -2589,6 +2593,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
*/
@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));

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

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));
}
}
}
15 changes: 15 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,15 @@
package hudson.model.details;

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
* @implNote This will render Jelly, hence the fields return null
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not sure if this is needed, no null fields anymore

Suggested change
* @implNote This will render Jelly, hence the fields return null

maybe

Suggested change
* @implNote This will render Jelly, hence the fields return null
* @implNote This renders Jelly

*/
public class DurationDetail extends Detail {

public DurationDetail(Run<?, ?> run) {
super(run);
}
}
15 changes: 15 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,15 @@
package hudson.model.details;

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

/**
* Displays the start time of the given run
* @implNote This will render Jelly, hence the fields return null
*/
public class TimestampDetail extends Detail {

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

/**
* Returns true if this detail is applicable to the given Actionable object
*/
public boolean isApplicable() {
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);

public int getOrder() {
return order;
}
}
67 changes: 39 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,66 @@ 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">
<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">
<div class="jenkins-card__details__item">
<div class="jenkins-card__details__item__icon">
<l:icon src="${detail.iconClassName}" />
</div>
${detail.displayName}
</div>
</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