diff --git a/pom.xml b/pom.xml index 6b1c2cb..290a542 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,14 @@ com.google.guava guava 15.0 - + + + org.jenkins-ci.plugins + dashboard-view + 2.8 + jar + true + diff --git a/src/main/java/hudson/plugins/sitemonitor/DashboardSupport.java b/src/main/java/hudson/plugins/sitemonitor/DashboardSupport.java new file mode 100644 index 0000000..8544bcd --- /dev/null +++ b/src/main/java/hudson/plugins/sitemonitor/DashboardSupport.java @@ -0,0 +1,64 @@ +package hudson.plugins.sitemonitor; + +import hudson.Extension; +import hudson.model.AbstractProject; +import hudson.model.Action; +import hudson.model.Descriptor; +import hudson.model.TopLevelItem; +import hudson.plugins.sitemonitor.model.Result; +import hudson.plugins.view.dashboard.DashboardPortlet; +import jenkins.model.Jenkins; +import org.kohsuke.stapler.DataBoundConstructor; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +public class DashboardSupport extends DashboardPortlet { + private String jobName; + + public String getJobName() { + return jobName; + } + + public String getText() { + StringBuilder result = new StringBuilder(); + for (Result r: getResults()) { + result.append(String.format("site=%s, code=%s, status=%s", r.getSite().getUrl(), r.getResponseCode(), r.getStatus())); + } + return result.toString(); + } + + public List getResults() { + TopLevelItem item = Jenkins.getInstance().getItem(jobName); + AbstractProject project = (AbstractProject) item; + for (Action action: project.getLastBuild().getActions()) { + if (action instanceof SiteMonitorRootAction) { + return ((SiteMonitorRootAction) action).getResults(); + } + } + return new LinkedList(); + } + + @DataBoundConstructor + public DashboardSupport(String name, String jobName ) { + super(name); + this.jobName = jobName; + } + + public boolean showDescription() { + return new SiteMonitorDescriptor().getShowDescription(); + } + + public static Collection getAllJobNames() { + return Jenkins.getInstance().getJobNames(); + } + + @Extension + public static class DescriptorImpl extends Descriptor { + @Override + public String getDisplayName() { + return Messages.SiteMonitor_DisplayName(); + } + } +} diff --git a/src/main/java/hudson/plugins/sitemonitor/SiteMonitorDescriptor.java b/src/main/java/hudson/plugins/sitemonitor/SiteMonitorDescriptor.java index e1dcac5..a63fd6f 100644 --- a/src/main/java/hudson/plugins/sitemonitor/SiteMonitorDescriptor.java +++ b/src/main/java/hudson/plugins/sitemonitor/SiteMonitorDescriptor.java @@ -21,15 +21,6 @@ */ package hudson.plugins.sitemonitor; -import java.net.HttpURLConnection; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; - -import org.apache.commons.lang.StringUtils; -import org.kohsuke.stapler.QueryParameter; -import org.kohsuke.stapler.StaplerRequest; - import hudson.Extension; import hudson.model.AbstractProject; import hudson.plugins.sitemonitor.mapper.JsonToSiteMapper; @@ -41,6 +32,14 @@ import hudson.util.FormValidation; import net.sf.json.JSONArray; import net.sf.json.JSONObject; +import org.apache.commons.lang.StringUtils; +import org.kohsuke.stapler.QueryParameter; +import org.kohsuke.stapler.StaplerRequest; + +import java.net.HttpURLConnection; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; /** * Handles the global and job configuration management. @@ -77,6 +76,11 @@ public class SiteMonitorDescriptor extends BuildStepDescriptor { */ private Integer mTimeout; + /** + * Indicates that description is shown in result. + */ + private boolean mShowDescription; + /** * Constructs {@link SiteMonitorDescriptor}. */ @@ -121,8 +125,7 @@ public final List getSuccessResponseCodes() { * @return the success response codes in comma-separated value format */ public final String getSuccessResponseCodesCsv() { - - return SuccessCodeListToCvString.INSTANCE.apply(mSuccessResponseCodes); + return SuccessCodeListToCvString.INSTANCE.apply(getSuccessResponseCodes()); } /** @@ -135,6 +138,13 @@ public final Integer getTimeout() { return mTimeout; } + /** + * @return status of show description + */ + public final boolean getShowDescription() { + return mShowDescription; + } + /** * Handles SiteMonitor configuration for each job. Changes to the values are * repercuted to the view-model once save button is clicked @@ -200,6 +210,7 @@ public final boolean configure(final StaplerRequest request, } mTimeout = json.getInt("timeout"); + mShowDescription = json.getBoolean("showDescription"); save(); return true; } diff --git a/src/main/java/hudson/plugins/sitemonitor/SiteMonitorRootAction.java b/src/main/java/hudson/plugins/sitemonitor/SiteMonitorRootAction.java index f65b90f..14288e1 100644 --- a/src/main/java/hudson/plugins/sitemonitor/SiteMonitorRootAction.java +++ b/src/main/java/hudson/plugins/sitemonitor/SiteMonitorRootAction.java @@ -48,6 +48,10 @@ public SiteMonitorRootAction(final List results) { mResults = results; } + public boolean showDescription() { + return new SiteMonitorDescriptor().getShowDescription(); + } + /** * @return the text of site monitor link on the left menu on build page. */ diff --git a/src/main/java/hudson/plugins/sitemonitor/mapper/JsonToSiteMapper.java b/src/main/java/hudson/plugins/sitemonitor/mapper/JsonToSiteMapper.java index 1161944..fe16f84 100644 --- a/src/main/java/hudson/plugins/sitemonitor/mapper/JsonToSiteMapper.java +++ b/src/main/java/hudson/plugins/sitemonitor/mapper/JsonToSiteMapper.java @@ -52,8 +52,9 @@ public Site apply(JSONObject json) { if (!StringUtils.isBlank(json.getString("timeout")) && NumberUtils.isDigits(json.getString("timeout"))) { siteBuilder.timeout(((JSONObject) json).getInt("timeout")); } - + siteBuilder.successResponseCodes(JsonToSuccessResponseList.INSTANCE.apply((JSONObject) json)); + siteBuilder.description(((JSONObject) json).getString("description")); return siteBuilder.build(); } diff --git a/src/main/java/hudson/plugins/sitemonitor/model/Site.java b/src/main/java/hudson/plugins/sitemonitor/model/Site.java index db4dac5..61fb4bf 100644 --- a/src/main/java/hudson/plugins/sitemonitor/model/Site.java +++ b/src/main/java/hudson/plugins/sitemonitor/model/Site.java @@ -49,6 +49,8 @@ public class Site { */ private List successResponseCodes; + private String description; + /** * Constructs a Site with specified details. * @param url @@ -64,6 +66,7 @@ private Site(SiteBuilder builder) { this.mUrl = builder.url; this.timeout = builder.timeout; this.successResponseCodes = builder.successResponseCodes; + this.description = builder.description; } /** @@ -86,6 +89,10 @@ public Integer getTimeout() { public List getSuccessResponseCodes() { return successResponseCodes; } + + public String getDescription() { + return description; + } /** * @return the success response codes in comma-separated value format, used by jelly @@ -112,6 +119,8 @@ public static class SiteBuilder { private Integer timeout; private List successResponseCodes; + + private String description; private SiteBuilder(String url) { this.url = url; @@ -119,15 +128,18 @@ private SiteBuilder(String url) { public SiteBuilder timeout(int timeout) { this.timeout = timeout; - return this; } public SiteBuilder successResponseCodes(List successResponseCodes) { this.successResponseCodes = successResponseCodes; - return this; } + + public SiteBuilder description(String value) { + this.description = value; + return this; + } public Site build() { return new Site(this); diff --git a/src/main/resources/hudson/plugins/sitemonitor/DashboardSupport/config.jelly b/src/main/resources/hudson/plugins/sitemonitor/DashboardSupport/config.jelly new file mode 100644 index 0000000..5fa8f77 --- /dev/null +++ b/src/main/resources/hudson/plugins/sitemonitor/DashboardSupport/config.jelly @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/hudson/plugins/sitemonitor/DashboardSupport/config.properties b/src/main/resources/hudson/plugins/sitemonitor/DashboardSupport/config.properties new file mode 100644 index 0000000..5f8b262 --- /dev/null +++ b/src/main/resources/hudson/plugins/sitemonitor/DashboardSupport/config.properties @@ -0,0 +1,2 @@ +site.text.displayName=Display name +site.text.jobName=Job name diff --git a/src/main/resources/hudson/plugins/sitemonitor/DashboardSupport/portlet.jelly b/src/main/resources/hudson/plugins/sitemonitor/DashboardSupport/portlet.jelly new file mode 100644 index 0000000..e573fb2 --- /dev/null +++ b/src/main/resources/hudson/plugins/sitemonitor/DashboardSupport/portlet.jelly @@ -0,0 +1,35 @@ + + + +
${descriptor.showDescription}
+
+ + + + + + + + + + + + + + + + + + + + + +
${%URL}${%Description}${%Response Code}${%Status}
${result.site.url}${result.site.description}${result.responseCode} +
+ +
+
+
+ +
+
diff --git a/src/main/resources/hudson/plugins/sitemonitor/SiteMonitorRecorder/config.jelly b/src/main/resources/hudson/plugins/sitemonitor/SiteMonitorRecorder/config.jelly index e9628a9..ec5a891 100644 --- a/src/main/resources/hudson/plugins/sitemonitor/SiteMonitorRecorder/config.jelly +++ b/src/main/resources/hudson/plugins/sitemonitor/SiteMonitorRecorder/config.jelly @@ -11,6 +11,9 @@ + + +
diff --git a/src/main/resources/hudson/plugins/sitemonitor/SiteMonitorRecorder/global.jelly b/src/main/resources/hudson/plugins/sitemonitor/SiteMonitorRecorder/global.jelly index b53b2fc..1056235 100644 --- a/src/main/resources/hudson/plugins/sitemonitor/SiteMonitorRecorder/global.jelly +++ b/src/main/resources/hudson/plugins/sitemonitor/SiteMonitorRecorder/global.jelly @@ -10,5 +10,8 @@ + + + \ No newline at end of file diff --git a/src/main/resources/hudson/plugins/sitemonitor/SiteMonitorRootAction/index.jelly b/src/main/resources/hudson/plugins/sitemonitor/SiteMonitorRootAction/index.jelly index 48d6eeb..4aaf9ed 100644 --- a/src/main/resources/hudson/plugins/sitemonitor/SiteMonitorRootAction/index.jelly +++ b/src/main/resources/hudson/plugins/sitemonitor/SiteMonitorRootAction/index.jelly @@ -11,6 +11,9 @@ + + + @@ -18,6 +21,9 @@ + + +
${%URL}${%Description} ${%Response Code} ${%Status}
${result.site.url}${result.site.description} ${result.responseCode}