Skip to content
Permalink
Browse files

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 bb75b6fb13133c10e0f3f113e995ad269bd0c3e9
@@ -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;
@@ -48,6 +51,7 @@ private String formatDate(Date d) {
return sdf.format(d.getTime());
}

@Exported
public String getDate() {
return formatDate(date.getTime());
}
@@ -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();
}
@@ -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;
@@ -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
@@ -35,6 +38,7 @@
* @author ialbors
*
*/
@ExportedBean
@Extension
public class NextExecutionsWidget extends Widget {
private static final Logger LOGGER = Logger.getLogger(NextExecutionsWidget.class.getName());
@@ -43,7 +47,10 @@
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>();

0 comments on commit bb75b6f

Please sign in to comment.
You can’t perform that action at this time.