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
This commit is contained in:
Davanum Srinivas 2014-01-17 10:31:57 -05:00
parent 36ca349ad1
commit 7e2ca62e1c
4 changed files with 22 additions and 20 deletions

View File

@ -21,17 +21,10 @@ import hudson.model.Job;
import hudson.model.JobProperty;
import hudson.model.JobPropertyDescriptor;
import hudson.model.AbstractProject;
import hudson.util.FormValidation;
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.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
public class HudsonNotificationProperty extends

View File

@ -18,7 +18,6 @@ package org.jenkinsci.plugins.ZMQEventPublisher;
import hudson.EnvVars;
import hudson.model.AbstractBuild;
import hudson.model.Hudson;
import hudson.model.Job;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
@ -26,28 +25,26 @@ import hudson.model.Run;
import hudson.model.Executor;
import hudson.model.Computer;
import hudson.model.TaskListener;
import java.io.IOException;
import java.util.List;
import jenkins.model.Jenkins;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.jenkinsci.plugins.ZMQEventPublisher.model.BuildState;;
import org.jenkinsci.plugins.ZMQEventPublisher.model.JobState;;
import org.jenkinsci.plugins.ZMQEventPublisher.model.BuildState;
import org.jenkinsci.plugins.ZMQEventPublisher.model.JobState;
public enum Phase {
STARTED, COMPLETED, FINISHED;
@SuppressWarnings({ "unchecked", "rawtypes" })
public String handlePhase(Run run, String status, TaskListener listener) {
Hudson hudson = Hudson.getInstance();
Jenkins jenkins = Jenkins.getInstance();
HudsonNotificationProperty property = (HudsonNotificationProperty)
run.getParent().getProperty(HudsonNotificationProperty.class);
HudsonNotificationProperty.HudsonNotificationPropertyDescriptor globalProperty =
(HudsonNotificationProperty.HudsonNotificationPropertyDescriptor)
hudson.getDescriptor(HudsonNotificationProperty.class);
jenkins.getDescriptor(HudsonNotificationProperty.class);
if ((property != null && property.isEnabled()) ||
(globalProperty != null && globalProperty.isGloballyEnabled())) {
return buildMessage(run.getParent(), run, status);
@ -68,7 +65,8 @@ public enum Phase {
buildState.setPhase(this);
buildState.setStatus(status);
String rootUrl = Hudson.getInstance().getRootUrl();
Jenkins jenkins = Jenkins.getInstance();
String rootUrl = jenkins.getRootUrl();
if (rootUrl != null) {
buildState.setFullUrl(rootUrl + run.getUrl());
}
@ -78,6 +76,7 @@ public enum Phase {
Computer computer = executor.getOwner();
if (computer != null) {
buildState.setNodeName(computer.getName());
buildState.setHostName(jenkins.getDisplayName());
}
}

View File

@ -16,7 +16,7 @@
package org.jenkinsci.plugins.ZMQEventPublisher;
import hudson.model.Hudson;
import jenkins.model.Jenkins;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;
@ -42,10 +42,10 @@ public class ZMQRunnable implements Runnable {
}
private int getPort() {
Hudson hudson = Hudson.getInstance();
Jenkins jenkins = Jenkins.getInstance();
HudsonNotificationProperty.HudsonNotificationPropertyDescriptor globalProperty =
(HudsonNotificationProperty.HudsonNotificationPropertyDescriptor)
hudson.getDescriptor(HudsonNotificationProperty.class);
jenkins.getDescriptor(HudsonNotificationProperty.class);
if (globalProperty != null) {
return globalProperty.getPort();
}
@ -92,7 +92,7 @@ public class ZMQRunnable implements Runnable {
String event;
while(true) {
try {
event = queue.take();;
event = queue.take();
bindSocket();
if (publisher != null) {
try {

View File

@ -36,6 +36,8 @@ public class BuildState {
private String nodeName;
private String hostName;
public int getNumber() {
return number;
}
@ -91,4 +93,12 @@ public class BuildState {
public void setNodeName(String nodeName) {
this.nodeName = nodeName;
}
public String getHostName() {
return hostName;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
}