Skip to content

Commit

Permalink
[FIXED JENKINS-7798]
Browse files Browse the repository at this point in the history
File size should be shown on project dashboard for archived artifacts.

Run.java:
	Add member String length to Artifact object.
	Add paramter String len to Artifact constructor.
	Add method String getLength to Artifact object.
	addArtifacts method of Run class gets length of files as string
	for actual files or "0" if a directory and passes this as arg
	to Artifact constructor.

artifacts-index.jelly and artifactList.jelly
	reworked to use same approach as
	core/src/main/resources/hudson/model/DirectoryBrowserSupport/dir.jelly
	The desire being a consistent look in the interface.

Signed-off-by: Stephen Ware <stephen.e.ware@intel.com>
  • Loading branch information
seware authored and kohsuke committed Sep 13, 2011
1 parent 37a22a1 commit 94cbf5b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 14 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -63,6 +63,9 @@
<div id="rc" style="display:none;"><!--=BEGIN=-->
<h3><a name=v1.431>What's new in 1.431</a> <!--=DATE=--></h3>
<ul class=image>
<li class=rfe>
Display the file size in the artifact list page
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-7798">issue 7798</a>)
<li class=rfe>
Fixed a file permission handling in the unzip code.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-9577">issue 9577</a>)
Expand Down
21 changes: 17 additions & 4 deletions core/src/main/java/hudson/model/Run.java
Expand Up @@ -878,25 +878,28 @@ private int addArtifacts( File dir, String path, String pathHref, ArtifactList r
String childPath = path + child;
String childHref = pathHref + Util.rawEncode(child);
File sub = new File(dir, child);
String length = sub.isFile() ? String.valueOf(sub.length()) : "0";
boolean collapsed = (children.length==1 && parent!=null);
Artifact a;
if (collapsed) {
// Collapse single items into parent node where possible:
a = new Artifact(parent.getFileName() + '/' + child, childPath,
sub.isDirectory() ? null : childHref, parent.getTreeNodeId());
sub.isDirectory() ? null : childHref, length,
parent.getTreeNodeId());
r.tree.put(a, r.tree.remove(parent));
} else {
// Use null href for a directory:
a = new Artifact(child, childPath,
sub.isDirectory() ? null : childHref, "n" + ++r.idSeq);
sub.isDirectory() ? null : childHref, length,
"n" + ++r.idSeq);
r.tree.put(a, parent!=null ? parent.getTreeNodeId() : null);
}
if (sub.isDirectory()) {
n += addArtifacts(sub, childPath + '/', childHref + '/', r, a, upTo-n);
if (n>=upTo) break;
} else {
// Don't store collapsed path in ArrayList (for correct data in external API)
r.add(collapsed ? new Artifact(child, a.relativePath, a.href, a.treeNodeId) : a);
r.add(collapsed ? new Artifact(child, a.relativePath, a.href, length, a.treeNodeId) : a);
if (++n>=upTo) break;
}
}
Expand Down Expand Up @@ -1031,11 +1034,17 @@ public class Artifact {
*/
private String treeNodeId;

/*package for test*/ Artifact(String name, String relativePath, String href, String treeNodeId) {

This comment has been minimized.

Copy link
@orrc

orrc Sep 13, 2011

Member

Looks like removing this method signature broke the test case:
http://ci.jenkins-ci.org/job/jenkins_main_trunk/1125/console

/**
*length of this artifact for files.
*/
private String length;

/*package for test*/ Artifact(String name, String relativePath, String href, String len, String treeNodeId) {
this.name = name;
this.relativePath = relativePath;
this.href = href;
this.treeNodeId = treeNodeId;
this.length = len;
}

/**
Expand All @@ -1062,6 +1071,10 @@ public String getHref() {
return href;
}

public String getLength() {
return length;
}

public String getTreeNodeId() {
return treeNodeId;
}
Expand Down
16 changes: 13 additions & 3 deletions core/src/main/resources/hudson/model/Run/artifacts-index.jelly
Expand Up @@ -31,11 +31,21 @@ THE SOFTWARE.
<t:buildCaption>
${%Build Artifacts}
</t:buildCaption>
<ul>
<table class="fileList">
<j:forEach var="f" items="${it.artifacts}">
<li><a href="artifact/${f.href}">${f.displayPath}</a></li>
<tr>
<td>
<img src="${imagesURL}/16x16/text.png" alt="" height="16" width="16"/>
</td>
<td>
<a href="artifact/${f.href}">${f.displayPath}</a>
</td>
<td class="fileSize">
${f.length}
</td>
</tr>
</j:forEach>
</ul>
</table>
</l:main-panel>
</l:layout>
</j:if>
Expand Down
25 changes: 18 additions & 7 deletions core/src/main/resources/lib/hudson/artifactList.jelly
Expand Up @@ -47,15 +47,26 @@ THE SOFTWARE.
<j:choose>
<j:when test="${size(artifacts) le build.LIST_CUTOFF}">
<!-- if not too many, just list them -->
<ul>
<table class="fileList">
<j:forEach var="f" items="${artifacts}">
<li>
<a href="${baseURL}artifact/${f.href}">${f.displayPath}</a>
<st:nbsp/>
<a href="${baseURL}artifact/${f.href}/*fingerprint*/"><img src="${imagesURL}/16x16/fingerprint.png" alt="[fingerprint]" height="16" width="16" /></a>
</li>
<tr>
<td>
<img src="${imagesURL}/16x16/text.png" alt="" height="16" width="16"/>
</td>
<td>
<a href="${baseURL}artifact/${f.href}">${f.displayPath}</a>
</td>
<td class="fileSize">
${f.length}
</td>
<td>
<a href="${baseURL}artifact/${f.href}/*fingerprint*/">
<img src="${imagesURL}/16x16/fingerprint.png" alt="[fingerprint]" height="16" width="16"/>
</a>
</td>
</tr>
</j:forEach>
</ul>
</table>
</j:when>
<j:when test="${size(artifacts) le build.TREE_CUTOFF}">
<!-- otherwise (unless way too many) use a tree view -->
Expand Down

0 comments on commit 94cbf5b

Please sign in to comment.