Skip to content

Commit

Permalink
[JENKINS-20998] Add Timestamp to Workspace View (#3079)
Browse files Browse the repository at this point in the history
* Add Timestamp to Workspace View

* suggested changes
javadoc

* suggested changes
control on dates before 1970-01-01 00:00

* constructor suggestions, I18N

* revert to N/A but in I18N
  • Loading branch information
kuisathaverat authored and oleg-nenashev committed Jun 8, 2018
1 parent c405ae7 commit 24ea684
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
47 changes: 43 additions & 4 deletions core/src/main/java/hudson/model/DirectoryBrowserSupport.java
Expand Up @@ -33,9 +33,11 @@
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;
Expand Down Expand Up @@ -349,7 +351,7 @@ private List<Path> buildParentPath(String pathList, int restSize) {
int current=1;
while(tokens.hasMoreTokens()) {
String token = tokens.nextToken();
r.add(new Path(createBackRef(total-current+restSize),token,true,0, true));
r.add(new Path(createBackRef(total-current+restSize),token,true,0, true,0));
current++;
}
return r;
Expand Down Expand Up @@ -416,12 +418,26 @@ public static final class Path implements Serializable {
*/
private final boolean isReadable;

/**
* For a file, the last modified timestamp.
*/
private final long lastModified;

/**
* @deprecated Use {@link #Path(String, String, boolean, long, boolean, long)}
*/
@Deprecated
public Path(String href, String title, boolean isFolder, long size, boolean isReadable) {
this(href, title, isFolder, size, isReadable, 0L);
}

public Path(String href, String title, boolean isFolder, long size, boolean isReadable, long lastModified) {
this.href = href;
this.title = title;
this.isFolder = isFolder;
this.size = size;
this.isReadable = isReadable;
this.lastModified = lastModified;
}

public boolean isFolder() {
Expand Down Expand Up @@ -458,6 +474,29 @@ public long getSize() {
return size;
}

/**
*
* @return A long value representing the time the file was last modified, measured in milliseconds since
* the epoch (00:00:00 GMT, January 1, 1970), or 0L if is not possible to obtain the times.
* @since TODO
*/
public long getLastModified() {
return lastModified;
}

/**
*
* @return A Calendar representing the time the file was last modified, it lastModified is 0L
* it will return 00:00:00 GMT, January 1, 1970.
* @since TODO
*/
@Restricted(NoExternalUse.class)
public Calendar getLastModifiedAsCalendar() {
final Calendar cal = new GregorianCalendar();
cal.setTimeInMillis(lastModified);
return cal;
}

private static final long serialVersionUID = 1L;
}

Expand Down Expand Up @@ -511,7 +550,7 @@ private static List<List<Path>> buildChildPaths(VirtualFile cur, Locale locale)
Arrays.sort(files,new FileComparator(locale));

for( VirtualFile f : files ) {
Path p = new Path(Util.rawEncode(f.getName()), f.getName(), f.isDirectory(), f.length(), f.canRead());
Path p = new Path(Util.rawEncode(f.getName()), f.getName(), f.isDirectory(), f.length(), f.canRead(), f.lastModified());
if(!f.isDirectory()) {
r.add(Collections.singletonList(p));
} else {
Expand All @@ -532,7 +571,7 @@ private static List<List<Path>> buildChildPaths(VirtualFile cur, Locale locale)
break;
f = sub.get(0);
relPath += '/'+Util.rawEncode(f.getName());
l.add(new Path(relPath,f.getName(),true,0, f.canRead()));
l.add(new Path(relPath,f.getName(),true, f.length(), f.canRead(), f.lastModified()));
}
r.add(l);
}
Expand Down Expand Up @@ -586,7 +625,7 @@ private static void buildPathList(VirtualFile baseDir, VirtualFile filePath, Lis
href.append("/");
}

Path path = new Path(href.toString(), filePath.getName(), filePath.isDirectory(), filePath.length(), filePath.canRead());
Path path = new Path(href.toString(), filePath.getName(), filePath.isDirectory(), filePath.length(), filePath.canRead(), filePath.lastModified());
pathList.add(path);
}

Expand Down
Expand Up @@ -70,6 +70,14 @@ THE SOFTWARE.
</j:forEach>
</td>
<j:if test="${!x.folder}">
<td class="fileSize">
<j:if test="${x.lastModifiedAsCalendar.timeInMillis &gt; 0}">
<i:formatDate value="${x.lastModifiedAsCalendar.time}" type="both" dateStyle="medium" timeStyle="medium"/>
</j:if>
<j:if test="${x.lastModifiedAsCalendar.timeInMillis &lt;= 0}">
${%N/A}
</j:if>
</td>
<td class="fileSize">
${h.humanReadableByteSize(x.getSize())}
</td>
Expand Down

0 comments on commit 24ea684

Please sign in to comment.