Skip to content

Commit

Permalink
Merge branch 'JENKINS-21267'
Browse files Browse the repository at this point in the history
Conflicts:
	src/main/resources/hudson/plugins/nextexecutions/NextExecutionsWidget/index.jelly
  • Loading branch information
ialbors-pfc committed Feb 10, 2014
2 parents 3216065 + fc72ebc commit 87d044b
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 4 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Expand Up @@ -43,5 +43,12 @@
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
</project>

41 changes: 39 additions & 2 deletions src/main/java/hudson/plugins/nextexecutions/NextBuilds.java
Expand Up @@ -15,9 +15,20 @@

import net.sf.json.JSONObject;

import org.joda.time.DateTime;
import org.joda.time.Period;
import org.joda.time.PeriodType;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormatterBuilder;
import org.joda.time.format.PeriodFormatter;
import org.joda.time.format.PeriodFormatterBuilder;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

/**
* Provides a way to get the project's next execution date.
*
*/
public class NextBuilds implements Comparable, Describable<NextBuilds>{
private AbstractProject project;
private String name;
Expand All @@ -30,13 +41,39 @@ public NextBuilds(AbstractProject project, Calendar date) {
this.date = date;
}

public String getDate() {
private String formatDate(Date d) {
String dateFormat = this.getDescriptor().getDateFormat();
if(dateFormat == null){
dateFormat = this.getDescriptor().getDefault();
}
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
return sdf.format(date.getTime());
return sdf.format(d.getTime());
}

public String getDate() {
return formatDate(date.getTime());
}

public String getTimeToGo() {
DateTime now = new DateTime();

PeriodType periodType = PeriodType.dayTime();
periodType.withMillisRemoved();
Period timeToGo = new Period(now, new DateTime(date.getTimeInMillis()),
periodType);

PeriodFormatter pf = new PeriodFormatterBuilder().
appendDays().
appendSuffix("d").
appendSeparatorIfFieldsBefore(" ").
appendHours().
appendSuffix("h").
appendSeparatorIfFieldsBefore(" ").
appendMinutes().
appendSuffix("m").
toFormatter();

return Messages.TimeToGo(pf.print(timeToGo));
}

public String getName() {
Expand Down
Expand Up @@ -16,6 +16,15 @@
import hudson.plugins.nextexecutions.NextBuilds.DescriptorImpl;
import hudson.plugins.nextexecutions.utils.NextExecutionsUtils;


/**
* Widget in the {@link Computer} page's sidebar with a list
* of projects (tied to that Computer) and their next scheduled
* build's date. The list is sorted by date.
*
* @author ialbors
*
*/
@Extension
public class NextExecutionsComputerWidget extends ComputerPanelBox {

Expand Down
Expand Up @@ -24,6 +24,14 @@
import hudson.triggers.Trigger;
import hudson.widgets.Widget;

/**
* Widget in the main sidebar with a list
* of projects and their next scheduled
* build's date. The list is sorted by date.
*
* @author ialbors
*
*/
@Extension
public class NextExecutionsWidget extends Widget {
private static final Logger LOGGER = Logger.getLogger(NextExecutionsWidget.class.getName());
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/hudson/plugins/nextexecutions/columns/NextExecutionColumn.java 100644 → 100755
Expand Up @@ -13,6 +13,14 @@
import hudson.plugins.nextexecutions.*;
import hudson.plugins.nextexecutions.utils.NextExecutionsUtils;

/**
*
* Column that shows the next scheduled date for a job.
*
* @author ialbors
*
*/

public class NextExecutionColumn extends ListViewColumn {

@DataBoundConstructor
Expand Down
@@ -1 +1,2 @@
Format.Error=The date format pattern is not valid.
Format.Error=The date format pattern is not valid.
TimeToGo=(in {0})
Expand Up @@ -3,7 +3,7 @@
<j:forEach var="w" items="${it.builds}">
<tr>
<td><a tooltip="${w.name}" href="${w.url}">${w.shortName}</a></td>
<td>${w.date}</td>
<td tooltip="${w.timeToGo}">${w.date}</td>
</tr>
</j:forEach>
</l:pane>
Expand Down

0 comments on commit 87d044b

Please sign in to comment.