Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Expose widget data through API.
The URL pattern to view this info is:

* <jenkins_url>/widgets/n/api/[json/xml...]
* <jenkins_url>/view/<view_name>/widgets/n/api/[json/xml...]

n - the order in which the widget appears in the sidebar being 0 (zero) the
first widget.

Fixes JENKINS-36210
  • Loading branch information
ialbors-pfc committed Sep 20, 2016
1 parent fea6f92 commit bb75b6f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/main/java/hudson/plugins/nextexecutions/NextBuilds.java
Expand Up @@ -22,11 +22,14 @@
import org.kohsuke.stapler.StaplerRequest;
import hudson.Util;
import jenkins.model.ParameterizedJobMixIn;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

/**
* Provides a way to get the project's next execution date.
*
*/
@ExportedBean(defaultVisibility = 2)
public class NextBuilds implements Comparable, Describable<NextBuilds>{
private ParameterizedJobMixIn.ParameterizedJob project;
private String name;
Expand All @@ -48,6 +51,7 @@ private String formatDate(Date d) {
return sdf.format(d.getTime());
}

@Exported
public String getDate() {
return formatDate(date.getTime());
}
Expand All @@ -74,10 +78,12 @@ public String getTimeToGo() {
return Messages.TimeToGo(pf.print(timeToGo));
}

@Exported
public String getName() {
return name;
}

@Exported
public String getUrl(){
return Jenkins.getInstance().getRootUrl() + project.getUrl();
}
Expand Down
Expand Up @@ -12,6 +12,7 @@
import org.kohsuke.stapler.Stapler;

import hudson.Extension;
import hudson.model.Api;
import hudson.model.Queue;
import hudson.model.Queue.Item;
import hudson.model.Queue.WaitingItem;
Expand All @@ -23,6 +24,8 @@
import hudson.triggers.TimerTrigger;
import hudson.widgets.Widget;
import jenkins.model.ParameterizedJobMixIn;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

/**
* Widget in the main sidebar with a list
Expand All @@ -35,6 +38,7 @@
* @author ialbors
*
*/
@ExportedBean
@Extension
public class NextExecutionsWidget extends Widget {
private static final Logger LOGGER = Logger.getLogger(NextExecutionsWidget.class.getName());
Expand All @@ -43,7 +47,10 @@ public class NextExecutionsWidget extends Widget {
public NextExecutionsWidget() {
triggerClass = TimerTrigger.class;
}


public Api getApi() { return new Api(this); }

@Exported(name = "next_executions")
public List<NextBuilds> getBuilds() {
List<NextBuilds> nblist = new Vector<NextBuilds>();

Expand Down

0 comments on commit bb75b6f

Please sign in to comment.