Skip to content

Commit 87d044b

Browse files
committedFeb 10, 2014
Merge branch 'JENKINS-21267'
Conflicts: src/main/resources/hudson/plugins/nextexecutions/NextExecutionsWidget/index.jelly
2 parents 3216065 + fc72ebc commit 87d044b

File tree

7 files changed

+74
-4
lines changed

7 files changed

+74
-4
lines changed
 

‎pom.xml

+7
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,12 @@
4343
<url>http://repo.jenkins-ci.org/public/</url>
4444
</pluginRepository>
4545
</pluginRepositories>
46+
<dependencies>
47+
<dependency>
48+
<groupId>joda-time</groupId>
49+
<artifactId>joda-time</artifactId>
50+
<version>2.3</version>
51+
</dependency>
52+
</dependencies>
4653
</project>
4754

‎src/main/java/hudson/plugins/nextexecutions/NextBuilds.java

+39-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,20 @@
1515

1616
import net.sf.json.JSONObject;
1717

18+
import org.joda.time.DateTime;
19+
import org.joda.time.Period;
20+
import org.joda.time.PeriodType;
21+
import org.joda.time.format.DateTimeFormatter;
22+
import org.joda.time.format.DateTimeFormatterBuilder;
23+
import org.joda.time.format.PeriodFormatter;
24+
import org.joda.time.format.PeriodFormatterBuilder;
1825
import org.kohsuke.stapler.QueryParameter;
1926
import org.kohsuke.stapler.StaplerRequest;
2027

28+
/**
29+
* Provides a way to get the project's next execution date.
30+
*
31+
*/
2132
public class NextBuilds implements Comparable, Describable<NextBuilds>{
2233
private AbstractProject project;
2334
private String name;
@@ -30,13 +41,39 @@ public NextBuilds(AbstractProject project, Calendar date) {
3041
this.date = date;
3142
}
3243

33-
public String getDate() {
44+
private String formatDate(Date d) {
3445
String dateFormat = this.getDescriptor().getDateFormat();
3546
if(dateFormat == null){
3647
dateFormat = this.getDescriptor().getDefault();
3748
}
3849
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
39-
return sdf.format(date.getTime());
50+
return sdf.format(d.getTime());
51+
}
52+
53+
public String getDate() {
54+
return formatDate(date.getTime());
55+
}
56+
57+
public String getTimeToGo() {
58+
DateTime now = new DateTime();
59+
60+
PeriodType periodType = PeriodType.dayTime();
61+
periodType.withMillisRemoved();
62+
Period timeToGo = new Period(now, new DateTime(date.getTimeInMillis()),
63+
periodType);
64+
65+
PeriodFormatter pf = new PeriodFormatterBuilder().
66+
appendDays().
67+
appendSuffix("d").
68+
appendSeparatorIfFieldsBefore(" ").
69+
appendHours().
70+
appendSuffix("h").
71+
appendSeparatorIfFieldsBefore(" ").
72+
appendMinutes().
73+
appendSuffix("m").
74+
toFormatter();
75+
76+
return Messages.TimeToGo(pf.print(timeToGo));
4077
}
4178

4279
public String getName() {

‎src/main/java/hudson/plugins/nextexecutions/NextExecutionsComputerWidget.java

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
import hudson.plugins.nextexecutions.NextBuilds.DescriptorImpl;
1717
import hudson.plugins.nextexecutions.utils.NextExecutionsUtils;
1818

19+
20+
/**
21+
* Widget in the {@link Computer} page's sidebar with a list
22+
* of projects (tied to that Computer) and their next scheduled
23+
* build's date. The list is sorted by date.
24+
*
25+
* @author ialbors
26+
*
27+
*/
1928
@Extension
2029
public class NextExecutionsComputerWidget extends ComputerPanelBox {
2130

‎src/main/java/hudson/plugins/nextexecutions/NextExecutionsWidget.java

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
import hudson.triggers.Trigger;
2525
import hudson.widgets.Widget;
2626

27+
/**
28+
* Widget in the main sidebar with a list
29+
* of projects and their next scheduled
30+
* build's date. The list is sorted by date.
31+
*
32+
* @author ialbors
33+
*
34+
*/
2735
@Extension
2836
public class NextExecutionsWidget extends Widget {
2937
private static final Logger LOGGER = Logger.getLogger(NextExecutionsWidget.class.getName());

‎src/main/java/hudson/plugins/nextexecutions/columns/NextExecutionColumn.java

100644100755
+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
import hudson.plugins.nextexecutions.*;
1414
import hudson.plugins.nextexecutions.utils.NextExecutionsUtils;
1515

16+
/**
17+
*
18+
* Column that shows the next scheduled date for a job.
19+
*
20+
* @author ialbors
21+
*
22+
*/
23+
1624
public class NextExecutionColumn extends ListViewColumn {
1725

1826
@DataBoundConstructor
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Format.Error=The date format pattern is not valid.
1+
Format.Error=The date format pattern is not valid.
2+
TimeToGo=(in {0})

‎src/main/resources/hudson/plugins/nextexecutions/NextExecutionsWidget/index.jelly

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<j:forEach var="w" items="${it.builds}">
44
<tr>
55
<td><a tooltip="${w.name}" href="${w.url}">${w.shortName}</a></td>
6-
<td>${w.date}</td>
6+
<td tooltip="${w.timeToGo}">${w.date}</td>
77
</tr>
88
</j:forEach>
99
</l:pane>

0 commit comments

Comments
 (0)
Please sign in to comment.