forked from jenkinsci/cloudbees-folder-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPseudoRun.java
More file actions
150 lines (122 loc) · 3.99 KB
/
PseudoRun.java
File metadata and controls
150 lines (122 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package com.cloudbees.hudson.plugins.folder.computed;
import hudson.Util;
import hudson.model.Actionable;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TopLevelItem;
import java.io.File;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.Ancestor;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.StaplerFallback;
import org.kohsuke.stapler.StaplerRequest2;
/**
* A fake {@link Run} used to render last build information via Stapler and Jelly
*/
@Restricted(NoExternalUse.class) // used by stapler / jelly only
public class PseudoRun<I extends TopLevelItem> extends Actionable implements StaplerFallback {
private final FolderComputation<I> computation;
PseudoRun(FolderComputation<I> computation) {
this.computation = computation;
}
public String getDisplayName() {
return "log";
}
public RunUrl decompose(StaplerRequest2 req) {
List<Ancestor> ancestors = req.getAncestors();
// find the first and last Run instances
Ancestor f = null, l = null;
for (Ancestor anc : ancestors) {
if (anc.getObject() instanceof PseudoRun) {
if (f == null) f = anc;
l = anc;
}
}
if (l == null) return null; // there was no Run object
String base = l.getUrl();
return new RunUrl(base);
}
/**
* Gets the string that says how long since this build has started.
*
* @return string like "3 minutes" "1 day" etc.
*/
@NonNull
public String getTimestampString() {
long duration = new GregorianCalendar().getTimeInMillis() - computation.getTimestamp().getTimeInMillis();
return Util.getPastTimeString(duration);
}
/**
* Returns the timestamp formatted in xs:dateTime.
*
* @return the timestamp formatted in xs:dateTime.
*/
@NonNull
public String getTimestampString2() {
return Util.XS_DATETIME_FORMATTER2.format(computation.getTimestamp().toInstant());
}
@CheckForNull
public Result getResult() {
return computation.getResult();
}
@NonNull
public Calendar getTimestamp() {
return computation.getTimestamp();
}
@NonNull
public String getDurationString() {
return computation.getDurationString();
}
@Override
public String getSearchUrl() {
return computation.getSearchUrl();
}
@NonNull
public File getLogFile() {
return computation.getLogFile();
}
@Override
public Object getStaplerFallback() {
return computation;
}
public HttpResponse doIndex(StaplerRequest2 request) {
return HttpResponses.redirectViaContextPath(computation.getUrl());
}
public HttpResponse doConsole(StaplerRequest2 request) {
return HttpResponses.redirectViaContextPath(computation.getUrl() + "console");
}
public HttpResponse doConsoleText(StaplerRequest2 request) {
return HttpResponses.redirectViaContextPath(computation.getUrl() + "consoleText");
}
@Restricted(NoExternalUse.class)
public static final class RunUrl {
private final String base;
public RunUrl(String base) {
this.base = base;
}
public String getBaseUrl() {
return base;
}
/**
* Returns the same page in the next build.
* @return the same page in the next build.
*/
public String getNextBuildUrl() {
return null;
}
/**
* Returns the same page in the previous build.
* @return the same page in the previous build.
*/
public String getPreviousBuildUrl() {
return null;
}
}
}