Browse Source

Update to Jenkins LTS 1.625.3 and fix function registration

Using a newer Jenkins LTS (ver 1.625.3) did not work with the
gearman-plugin. Gearman function registeration wasn't working
correct because Computer.currentComputer()[1] and getInstance()[2]
methods seemed to always return null on initialization of the
plugin. The Jenkins.getActiveInstance method (introduced in
Jenkins-1.589)[3] works more reliably.

[1] http://javadoc.jenkins-ci.org/hudson/model/Node.html#getNodeName()
[2] http://javadoc.jenkins-ci.org/jenkins/model/Jenkins.html#getActiveInstance()
[3] e6c2e16f7a

Change-Id: I1534beda9c39a9d15da4d7b96f17e7b75699a631
tags/0.2.0^2
Khai Do 3 years ago
parent
commit
a5164d65a4

+ 1
- 1
pom.xml View File

@@ -28,7 +28,7 @@
28 28
     <parent>
29 29
         <groupId>org.jenkins-ci.plugins</groupId>
30 30
         <artifactId>plugin</artifactId>
31
-        <version>1.565.3</version><!-- which version of Jenkins is this plugin built against? -->
31
+        <version>1.625.3</version> <!--which version of Jenkins is this plugin built against? -->
32 32
     </parent>
33 33
 
34 34
     <artifactId>gearman-plugin</artifactId>

+ 1
- 1
src/main/java/hudson/plugins/gearman/ExecutorWorkerThread.java View File

@@ -117,7 +117,7 @@ public class ExecutorWorkerThread extends AbstractWorkerThread{
117 117
         if (!computer.isOffline()) {
118 118
             Node node = computer.getNode();
119 119
 
120
-            List<AbstractProject> allProjects = Jenkins.getInstance().getAllItems(AbstractProject.class);
120
+            List<AbstractProject> allProjects = Jenkins.getActiveInstance().getAllItems(AbstractProject.class);
121 121
             for (AbstractProject<?, ?> project : allProjects) {
122 122
 
123 123
                 if (project.isDisabled()) { // ignore all disabled projects

+ 2
- 2
src/main/java/hudson/plugins/gearman/GearmanPluginUtil.java View File

@@ -51,7 +51,7 @@ public class GearmanPluginUtil {
51 51
      */
52 52
     public static String getRealName(Computer computer) {
53 53
 
54
-        if (Computer.currentComputer() == computer) {
54
+        if (Jenkins.getActiveInstance().getComputer("") == computer) {
55 55
             return "master";
56 56
         } else {
57 57
             return computer.getName();
@@ -70,7 +70,7 @@ public class GearmanPluginUtil {
70 70
      */
71 71
     public static Run<?,?> findBuild(String jobName, int buildNumber) {
72 72
 
73
-        AbstractProject<?,?> project = Jenkins.getInstance().getItemByFullName(jobName, AbstractProject.class);
73
+        AbstractProject<?,?> project = Jenkins.getActiveInstance().getItemByFullName(jobName, AbstractProject.class);
74 74
         if (project != null){
75 75
             Run<?,?> run = project.getBuildByNumber(buildNumber);
76 76
             if (run != null) {

+ 3
- 3
src/main/java/hudson/plugins/gearman/GearmanProxy.java View File

@@ -70,7 +70,7 @@ public class GearmanProxy {
70 70
         String hostname = Constants.GEARMAN_DEFAULT_EXECUTOR_NAME;
71 71
         // query Jenkins for master's name
72 72
         try {
73
-            master = Jenkins.getInstance().getComputer("");
73
+            master = Jenkins.getActiveInstance().getComputer("");
74 74
             hostname = master.getHostName();
75 75
         } catch (Exception e) {
76 76
             logger.warn("Exception while getting hostname", e);
@@ -119,7 +119,7 @@ public class GearmanProxy {
119 119
         // first make sure master is enabled (or has executors)
120 120
         Node masterNode = null;
121 121
         try {
122
-            masterNode = Computer.currentComputer().getNode();
122
+            masterNode = Jenkins.getActiveInstance().getComputer("").getNode();
123 123
         } catch (NullPointerException npe) {
124 124
             logger.info("---- Master is offline");
125 125
         } catch (Exception e) {
@@ -136,7 +136,7 @@ public class GearmanProxy {
136 136
         /*
137 137
          * Spawn executors for the jenkins slaves
138 138
          */
139
-        List<Node> nodes = Jenkins.getInstance().getNodes();
139
+        List<Node> nodes = Jenkins.getActiveInstance().getNodes();
140 140
         if (!nodes.isEmpty()) {
141 141
             for (Node node : nodes) {
142 142
                 Computer computer = node.toComputer();

+ 1
- 1
src/main/java/hudson/plugins/gearman/NodeAvailabilityMonitor.java View File

@@ -38,7 +38,7 @@ public class NodeAvailabilityMonitor implements AvailabilityMonitor {
38 38
     {
39 39
         this.computer = computer;
40 40
         queue = Queue.getInstance();
41
-        jenkins = Jenkins.getInstance();
41
+        jenkins = Jenkins.getActiveInstance();
42 42
     }
43 43
 
44 44
     public Computer getComputer() {

+ 1
- 1
src/test/java/hudson/plugins/gearman/GearmanPluginConfigTest.java View File

@@ -48,7 +48,7 @@ public class GearmanPluginConfigTest {
48 48
     public void setUp() {
49 49
         Jenkins jenkins = mock(Jenkins.class);
50 50
         PowerMockito.mockStatic(Jenkins.class);
51
-        when(Jenkins.getInstance()).thenReturn(jenkins);
51
+        when(Jenkins.getActiveInstance()).thenReturn(jenkins);
52 52
 
53 53
         gpc = new GearmanPluginConfig();
54 54
     }

+ 2
- 1
src/test/java/hudson/plugins/gearman/GearmanPluginUtilTest.java View File

@@ -20,6 +20,7 @@ package hudson.plugins.gearman;
20 20
 
21 21
 import hudson.model.Computer;
22 22
 import hudson.slaves.DumbSlave;
23
+import jenkins.model.Jenkins;
23 24
 
24 25
 import org.junit.Test;
25 26
 import org.jvnet.hudson.test.HudsonTestCase;
@@ -45,7 +46,7 @@ public class GearmanPluginUtilTest extends HudsonTestCase {
45 46
     @Test
46 47
     public void testGetRealNameMaster() throws Exception {
47 48
 
48
-        assertEquals("master", GearmanPluginUtil.getRealName(Computer.currentComputer()));
49
+        assertEquals("master", GearmanPluginUtil.getRealName(Jenkins.getActiveInstance().getComputer("")));
49 50
     }
50 51
 
51 52
 }

Loading…
Cancel
Save