Skip to content
Permalink
Browse files
[JENKINS-20998] Add Timestamp to Workspace View (#3079)
* 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 24ea6846150a5a5dc6882a7a4c0bb3c7084dbbae
@@ -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;
@@ -349,7 +351,7 @@ private String getPath(StaplerRequest req) {
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;
@@ -416,12 +418,26 @@ private static void zip(OutputStream outputStream, VirtualFile dir, String glob)
*/
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() {
@@ -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;
}

@@ -511,7 +550,7 @@ private int dirRank(VirtualFile f) {
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 {
@@ -532,7 +571,7 @@ private int dirRank(VirtualFile f) {
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);
}
@@ -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);
}

@@ -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>

0 comments on commit 24ea684

Please sign in to comment.