Permalink
Browse files

.

  • Loading branch information...
1 parent 5ffbbb8 commit 1690a0ec181854ff887fd94aabf5449aa1943a60 @mark2b mark2b committed Dec 29, 2010
@@ -9,22 +9,24 @@
import java.util.ArrayList;
import java.util.List;
+import net.sf.json.JSON;
+import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import com.thoughtworks.xstream.annotations.XStreamAlias;
-public class HudsonNotifierProperty extends JobProperty<AbstractProject<?, ?>> {
+public class HudsonNotificationProperty extends JobProperty<AbstractProject<?, ?>> {
+
+ private List<Target> targets = new ArrayList<Target>();
@DataBoundConstructor
- public HudsonNotifierProperty() {
+ public HudsonNotificationProperty() {
super();
}
- private List<Target> targets = new ArrayList<Target>();
-
public List<Target> getTargets() {
return targets;
}
@@ -67,8 +69,17 @@ public void setUrl(String url) {
@Extension
public static final class DescriptorImpl extends JobPropertyDescriptor {
+ public DescriptorImpl() {
+ super(HudsonNotificationProperty.class);
+ load();
+ }
+
private List<Target> targets = new ArrayList<Target>();
+ public boolean isEnabled() {
+ return !targets.isEmpty();
+ }
+
public List<Target> getTargets() {
return targets;
}
@@ -77,30 +88,33 @@ public void setTargets(List<Target> targets) {
this.targets = targets;
}
- public DescriptorImpl() {
- super(HudsonNotifierProperty.class);
- load();
- }
-
@Override
public boolean isApplicable(@SuppressWarnings("rawtypes") Class<? extends Job> jobType) {
return true;
}
public String getDisplayName() {
- return "Hudson Notifier";
+ return "Hudson Job Notification";
}
@Override
- public HudsonNotifierProperty newInstance(StaplerRequest req, JSONObject formData) throws FormException {
- HudsonNotifierProperty notifierProperty = new HudsonNotifierProperty();
+ public HudsonNotificationProperty newInstance(StaplerRequest req, JSONObject formData) throws FormException {
+ System.out.println(formData.toString(0));
+
+ HudsonNotificationProperty notificationProperty = new HudsonNotificationProperty();
if (formData != null && !formData.isNullObject()) {
- JSONObject targetsData = (JSONObject) formData.get("targets");
- if (targetsData != null && !targetsData.isNullObject()) {
- notifierProperty.setTargets(req.bindJSONToList(Target.class, targetsData));
+ JSON targetsData = (JSON) formData.get("targets");
+ if (targetsData != null && !targetsData.isEmpty()) {
+ if (targetsData.isArray()) {
+ JSONArray targetsArrayData = (JSONArray) targetsData;
+ notificationProperty.setTargets(req.bindJSONToList(Target.class, targetsArrayData));
+ } else {
+ JSONObject targetsObjectData = (JSONObject) targetsData;
+ notificationProperty.getTargets().add(req.bindJSON(Target.class, targetsObjectData));
+ }
}
}
- return notifierProperty;
+ return notificationProperty;
}
@Override
@@ -4,14 +4,14 @@
import java.util.List;
-import com.tikal.hudson.plugins.notification.HudsonNotifierProperty.Target;
+import com.tikal.hudson.plugins.notification.HudsonNotificationProperty.Target;
public enum Phase {
STARTED, COMPLETED, FINISHED;
@SuppressWarnings({ "unchecked", "rawtypes" })
public void handlePhase(Run run, String status) {
- HudsonNotifierProperty property = (HudsonNotifierProperty) run.getParent().getProperty(HudsonNotifierProperty.class);
+ HudsonNotificationProperty property = (HudsonNotificationProperty) run.getParent().getProperty(HudsonNotificationProperty.class);
if (property != null) {
List<Target> targets = property.getTargets();
for (Target target : targets) {
@@ -1,46 +0,0 @@
-package hudson.plugins.notifier.model;
-
-import com.tikal.hudson.plugins.notification.Phase;
-
-public class BuildState {
-
- private int number;
-
- private Phase phase;
-
- private String status;
-
- private String url;
-
- public int getNumber() {
- return number;
- }
-
- public void setNumber(int number) {
- this.number = number;
- }
-
- public Phase getPhase() {
- return phase;
- }
-
- public void setPhase(Phase phase) {
- this.phase = phase;
- }
-
- public String getStatus() {
- return status;
- }
-
- public void setStatus(String status) {
- this.status = status;
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-}
@@ -1,34 +0,0 @@
-package hudson.plugins.notifier.model;
-
-public class JobState {
-
- private String name;
-
- private String url;
-
- private BuildState build;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
- public BuildState getBuild() {
- return build;
- }
-
- public void setBuild(BuildState build) {
- this.build = build;
- }
-}
@@ -0,0 +1,41 @@
+<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
+ xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
+
+ <f:section title="Job Notifications">
+ <f:entry title="Notification Targets">
+ <f:repeatable name="targets" var="target" items="${instance.targets}"
+ add="${%Add Target}">
+ <table class="center-align">
+ <f:entry title="">
+ <table>
+ <tr>
+ <td>
+ <f:entry title="Protocol" description="">
+ <select class="setting-input" name="protocol">
+ <f:option value="UDP" selected="${target.protocol=='UDP'}">UDP</f:option>
+ <f:option value="TCP" selected="${target.protocol=='TCP'}">TCP</f:option>
+ <f:option value="HTTP" selected="${target.protocol=='HTTP'}">HTTP</f:option>
+ </select>
+ </f:entry>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <f:entry title="URL" description="Whether to send messages">
+ <f:textbox name="url" value="${target.url}" />
+ </f:entry>
+ </td>
+ </tr>
+ <tr class="group-row">
+ <td rowspan="1" valign="middle" class="pane">
+ <input type="button" value="${%Delete}" class="repeatable-delete"
+ style="margin-left: 1em;" />
+ </td>
+ </tr>
+ </table>
+ </f:entry>
+ </table>
+ </f:repeatable>
+ </f:entry>
+ </f:section>
+</j:jelly>
File renamed without changes.
@@ -1,35 +0,0 @@
-<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
- <f:entry title="Notification Targets">
- <f:repeatable name="targets" var="target" items="${instance.targets}" add="${%Add Target}">
- <table class="center-align">
- <f:entry title="">
- <table>
- <tr class="group-row">
- <td rowspan="1" valign="middle" class="pane">
- <input type="button" value="${%Delete}" class="repeatable-delete" style="margin-left: 1em;" />
- </td>
- </tr>
- <tr>
- <td>
- <f:entry title="Protocol" description="">
- <select class="setting-input" name="protocol">
- <f:option value="UDP" selected="${target.protocol=='UDP'}">UDP</f:option>
- <f:option value="TCP" selected="${target.protocol=='TCP'}">TCP</f:option>
- <f:option value="HTTP" selected="${target.protocol=='HTTP'}">HTTP</f:option>
- </select>
- </f:entry>
- </td>
- </tr>
- <tr>
- <td>
- <f:entry title="URL" description="Whether to send notifications">
- <f:textbox name="url" value="${target.url}" />
- </f:entry>
- </td>
- </tr>
- </table>
- </f:entry>
- </table>
- </f:repeatable>
- </f:entry>
-</j:jelly>

0 comments on commit 1690a0e

Please sign in to comment.