Browse Source

Include Jenkins host name / Code cleanup

The first cut of this review was to inject the jenkins/build
master host name and was then expanded to the following

* Use Jenkins class as Hudson class is being deprecated
* Change instances of Hudson currently named hudson to jenkins
* Remove unused imports
* Remove extra semi-colons

Change-Id: If1715b574952ac4c228501459663956fee55c4a6
tags/0.0.3
Davanum Srinivas 5 years ago
parent
commit
7e2ca62e1c

+ 0
- 7
src/main/java/org/jenkinsci/plugins/ZMQEventPublisher/HudsonNotificationProperty.java View File

@@ -21,17 +21,10 @@ import hudson.model.Job;
21 21
 import hudson.model.JobProperty;
22 22
 import hudson.model.JobPropertyDescriptor;
23 23
 import hudson.model.AbstractProject;
24
-import hudson.util.FormValidation;
25 24
 
26
-import java.util.ArrayList;
27
-import java.util.List;
28
-
29
-import net.sf.json.JSON;
30
-import net.sf.json.JSONArray;
31 25
 import net.sf.json.JSONObject;
32 26
 
33 27
 import org.kohsuke.stapler.DataBoundConstructor;
34
-import org.kohsuke.stapler.QueryParameter;
35 28
 import org.kohsuke.stapler.StaplerRequest;
36 29
 
37 30
 public class HudsonNotificationProperty extends

+ 8
- 9
src/main/java/org/jenkinsci/plugins/ZMQEventPublisher/Phase.java View File

@@ -18,7 +18,6 @@ package org.jenkinsci.plugins.ZMQEventPublisher;
18 18
 
19 19
 import hudson.EnvVars;
20 20
 import hudson.model.AbstractBuild;
21
-import hudson.model.Hudson;
22 21
 import hudson.model.Job;
23 22
 import hudson.model.ParameterValue;
24 23
 import hudson.model.ParametersAction;
@@ -26,28 +25,26 @@ import hudson.model.Run;
26 25
 import hudson.model.Executor;
27 26
 import hudson.model.Computer;
28 27
 import hudson.model.TaskListener;
29
-
30
-import java.io.IOException;
31
-import java.util.List;
28
+import jenkins.model.Jenkins;
32 29
 
33 30
 import com.google.gson.FieldNamingPolicy;
34 31
 import com.google.gson.Gson;
35 32
 import com.google.gson.GsonBuilder;
36 33
 
37
-import org.jenkinsci.plugins.ZMQEventPublisher.model.BuildState;;
38
-import org.jenkinsci.plugins.ZMQEventPublisher.model.JobState;;
34
+import org.jenkinsci.plugins.ZMQEventPublisher.model.BuildState;
35
+import org.jenkinsci.plugins.ZMQEventPublisher.model.JobState;
39 36
 
40 37
 public enum Phase {
41 38
     STARTED, COMPLETED, FINISHED;
42 39
 
43 40
     @SuppressWarnings({ "unchecked", "rawtypes" })
44 41
     public String handlePhase(Run run, String status, TaskListener listener) {
45
-        Hudson hudson = Hudson.getInstance();
42
+        Jenkins jenkins = Jenkins.getInstance();
46 43
         HudsonNotificationProperty property = (HudsonNotificationProperty)
47 44
             run.getParent().getProperty(HudsonNotificationProperty.class);
48 45
         HudsonNotificationProperty.HudsonNotificationPropertyDescriptor globalProperty =
49 46
             (HudsonNotificationProperty.HudsonNotificationPropertyDescriptor)
50
-                hudson.getDescriptor(HudsonNotificationProperty.class);
47
+                jenkins.getDescriptor(HudsonNotificationProperty.class);
51 48
         if ((property != null && property.isEnabled()) ||
52 49
                 (globalProperty != null && globalProperty.isGloballyEnabled())) {
53 50
             return buildMessage(run.getParent(), run, status);
@@ -68,7 +65,8 @@ public enum Phase {
68 65
         buildState.setPhase(this);
69 66
         buildState.setStatus(status);
70 67
 
71
-        String rootUrl = Hudson.getInstance().getRootUrl();
68
+        Jenkins jenkins = Jenkins.getInstance();
69
+        String rootUrl = jenkins.getRootUrl();
72 70
         if (rootUrl != null) {
73 71
             buildState.setFullUrl(rootUrl + run.getUrl());
74 72
         }
@@ -78,6 +76,7 @@ public enum Phase {
78 76
             Computer computer = executor.getOwner();
79 77
             if (computer != null) {
80 78
                 buildState.setNodeName(computer.getName());
79
+                buildState.setHostName(jenkins.getDisplayName());
81 80
             }
82 81
         }
83 82
 

+ 4
- 4
src/main/java/org/jenkinsci/plugins/ZMQEventPublisher/ZMQRunnable.java View File

@@ -16,7 +16,7 @@
16 16
 
17 17
 package org.jenkinsci.plugins.ZMQEventPublisher;
18 18
 
19
-import hudson.model.Hudson;
19
+import jenkins.model.Jenkins;
20 20
 
21 21
 import java.util.concurrent.LinkedBlockingQueue;
22 22
 import java.util.logging.Level;
@@ -42,10 +42,10 @@ public class ZMQRunnable implements Runnable {
42 42
     }
43 43
 
44 44
     private int getPort() {
45
-        Hudson hudson = Hudson.getInstance();
45
+        Jenkins jenkins = Jenkins.getInstance();
46 46
         HudsonNotificationProperty.HudsonNotificationPropertyDescriptor globalProperty =
47 47
             (HudsonNotificationProperty.HudsonNotificationPropertyDescriptor)
48
-                hudson.getDescriptor(HudsonNotificationProperty.class);
48
+                jenkins.getDescriptor(HudsonNotificationProperty.class);
49 49
         if (globalProperty != null) {
50 50
             return globalProperty.getPort();
51 51
         }
@@ -92,7 +92,7 @@ public class ZMQRunnable implements Runnable {
92 92
         String event;
93 93
         while(true) {
94 94
             try {
95
-                event = queue.take();;
95
+                event = queue.take();
96 96
                 bindSocket();
97 97
                 if (publisher != null) {
98 98
                     try {

+ 10
- 0
src/main/java/org/jenkinsci/plugins/ZMQEventPublisher/model/BuildState.java View File

@@ -36,6 +36,8 @@ public class BuildState {
36 36
 
37 37
     private String nodeName;
38 38
 
39
+    private String hostName;
40
+
39 41
     public int getNumber() {
40 42
         return number;
41 43
     }
@@ -91,4 +93,12 @@ public class BuildState {
91 93
     public void setNodeName(String nodeName) {
92 94
         this.nodeName = nodeName;
93 95
     }
96
+
97
+    public String getHostName() {
98
+        return hostName;
99
+    }
100
+
101
+    public void setHostName(String hostName) {
102
+        this.hostName = hostName;
103
+    }
94 104
 }

Loading…
Cancel
Save