Render lazily only for custom ArtifactManager; and cleaner not to use renderOnDemand at all

This commit is contained in:
Jesse Glick committed 2025-05-07 06:10:39 -04:00
1 parent bb3d723ad9
commit 6781baf183
4 files changed
+105 -55

No files matched your search

+6
View File
@@ -135,6 +135,7 @@ import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
import org.apache.commons.jelly.XMLOutput;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.QueryParameter;
@@ -1073,6 +1074,11 @@ public abstract class Run<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
}
}
@Restricted(DoNotUse.class) // Jelly
public final boolean hasCustomArtifactManager() {
return artifactManager != null;
}
/**
* Gets the directory where the artifacts are archived.
* @deprecated Should only be used from {@link StandardArtifactManager} or subclasses.
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License
Copyright 2025 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:l="/lib/layout" xmlns:t="/lib/hudson">
<l:ajax>
<j:if test="${!h.artifactsPermissionEnabled or h.artifactsPermissionEnabled and it.hasPermission(it.ARTIFACTS)}">
<j:set var="artifacts" value="${it.getArtifactsUpTo(it.LIST_CUTOFF+1)}" />
<j:if test="${!empty(artifacts)}">
<t:summary icon="symbol-cube" href="${rootURL}/${it.url}artifact/">
<a href="${rootURL}/${it.url}artifact/">${caption != null ? caption : request2.getParameter('caption')}</a>
<j:if test="${it.building}">
<p>
${%building}
</p>
</j:if>
<j:if test="${size(artifacts) le it.LIST_CUTOFF}">
<!-- if not too many, just list them -->
<table class="fileList">
<j:forEach var="f" items="${artifacts}">
<tr>
<td>
<l:icon class="icon-document icon-sm"/>
</td>
<td>
<a href="${rootURL}/${it.url}artifact/${f.href}">${f.displayPath}</a>
</td>
<td class="fileSize">
${h.humanReadableByteSize(f.getFileSize())}
</td>
<td>
<j:if test="${app.fingerprintMap.ready}">
<a href="${rootURL}/${it.url}artifact/${f.href}/*fingerprint*/">
<l:icon class="icon-fingerprint icon-sm"/>
</a>
<st:nbsp/>
</j:if>
<a href="${rootURL}/${it.url}artifact/${f.href}/*view*/">${%view}</a>
</td>
</tr>
</j:forEach>
</table>
</j:if>
<!-- otherwise just show link to directory browser -->
</t:summary>
</j:if>
</j:if>
</l:ajax>
</j:jelly>
@@ -23,7 +23,7 @@ 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">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
<st:documentation>
Generates a listing of the build artifacts.
Depending on the size of the artifact, this will either produce a list or a link to the directory view.
@@ -34,54 +34,17 @@ THE SOFTWARE.
<st:attribute name="caption" use="required">
Human readable title text
</st:attribute>
<st:attribute name="baseURL">
If the hyperlink to artifacts are at another URL, specify the prefix.
</st:attribute>
</st:documentation>
<j:if test="${build != null and (!h.artifactsPermissionEnabled or h.artifactsPermissionEnabled and h.hasPermission(build, attrs.permission))}">
<l:renderOnDemand tag="tbody" clazz="artifact-list" capture="build,caption,baseURL">
<l:ajax>
<j:set var="artifacts" value="${build.getArtifactsUpTo(build.LIST_CUTOFF+1)}" />
<j:if test="${!empty(artifacts)}">
<t:summary icon="symbol-cube" href="${baseURL}artifact/">
<a href="${baseURL}artifact/">${caption}</a>
<j:if test="${build.building}">
<p>
${%building}
</p>
</j:if>
<j:if test="${size(artifacts) le build.LIST_CUTOFF}">
<!-- if not too many, just list them -->
<table class="fileList">
<j:forEach var="f" items="${artifacts}">
<tr>
<td>
<l:icon class="icon-document icon-sm"/>
</td>
<td>
<a href="${baseURL}artifact/${f.href}">${f.displayPath}</a>
</td>
<td class="fileSize">
${h.humanReadableByteSize(f.getFileSize())}
</td>
<td>
<j:if test="${app.fingerprintMap.ready}">
<a href="${baseURL}artifact/${f.href}/*fingerprint*/">
<l:icon class="icon-fingerprint icon-sm"/>
</a>
<st:nbsp/>
</j:if>
<a href="${baseURL}artifact/${f.href}/*view*/">${%view}</a>
</td>
</tr>
</j:forEach>
</table>
</j:if>
<!-- otherwise just show link to directory browser -->
</t:summary>
</j:if>
</l:ajax>
</l:renderOnDemand>
<st:adjunct includes="lib.hudson.artifactList"/>
</j:if>
<j:choose>
<j:when test="${build == null}">
<!-- nothing to render -->
</j:when>
<j:when test="${build.hasCustomArtifactManager()}">
<tbody class="artifact-list" data-url="${rootURL}/${build.url}artifactList" data-caption="${caption}"/>
<st:adjunct includes="lib.hudson.artifactList"/>
</j:when>
<j:otherwise>
<st:include it="${build}" page="artifactList"/>
</j:otherwise>
</j:choose>
</j:jelly>
@@ -22,8 +22,18 @@
* THE SOFTWARE.
*/
// Or could use Behaviour.specify.
// TODO why is render-on-demand not specified to run this already?
// hudson-behavior.js hard-codes this for .dropdownList,
// and RenderOnDemandTest calls it manually which seems like cheating.
renderOnDemand(document.querySelector(".artifact-list"));
// TODO package this logic into a generic utility like renderOnDemand/refreshPart with Behaviour.specify
var e = document.querySelector(".artifact-list");
fetch(
e.getAttribute("data-url") +
"?" +
new URLSearchParams({ caption: e.getAttribute("data-caption") }),
).then((rsp) => {
if (rsp.ok) {
rsp.text().then((responseText) => {
e.innerHTML = responseText;
Behaviour.applySubtree(e);
layoutUpdateCallback.call();
});
}
});