Skip to content

Commit a96a1aa

Browse files
authored
Merge pull request #1 from bpedersen2/master
Implement workflow support
2 parents 7c1ec95 + 5a8a7ed commit a96a1aa

File tree

20 files changed

+476
-112
lines changed

20 files changed

+476
-112
lines changed

pom.xml

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
<parent>
44
<groupId>org.jenkins-ci.plugins</groupId>
55
<artifactId>plugin</artifactId>
6-
<version>1.424</version>
6+
<version>2.4</version>
77
</parent>
8-
98
<artifactId>port-allocator</artifactId>
109
<packaging>hpi</packaging>
1110
<version>1.9-SNAPSHOT</version>
@@ -31,6 +30,11 @@
3130
</developer>
3231
</developers>
3332

33+
<properties>
34+
<jenkins.version>2.7.1</jenkins.version>
35+
<workflow.version>1.8</workflow.version>
36+
</properties>
37+
3438
<scm>
3539
<connection>scm:git:git://github.com/jenkinsci/port-allocator-plugin.git</connection>
3640
<developerConnection>scm:git:ssh://[email protected]/jenkinsci/port-allocator-plugin.git</developerConnection>
@@ -59,6 +63,50 @@
5963
</pluginRepositories>
6064

6165
<dependencies>
66+
<dependency>
67+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
68+
<artifactId>workflow-job</artifactId>
69+
<version>${workflow.version}</version>
70+
<scope>test</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
74+
<artifactId>workflow-basic-steps</artifactId>
75+
<version>${workflow.version}</version>
76+
<scope>test</scope>
77+
</dependency>
78+
<dependency>
79+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
80+
<artifactId>workflow-cps</artifactId>
81+
<version>${workflow.version}</version>
82+
<scope>test</scope>
83+
</dependency>
84+
<dependency>
85+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
86+
<artifactId>workflow-durable-task-step</artifactId>
87+
<version>${workflow.version}</version>
88+
<scope>test</scope>
89+
</dependency>
90+
<dependency> <!-- StepConfigTester -->
91+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
92+
<artifactId>workflow-step-api</artifactId>
93+
<version>${workflow.version}</version>
94+
<classifier>tests</classifier>
95+
<scope>test</scope>
96+
</dependency>
97+
<dependency> <!-- JenkinsRuleExt -->
98+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
99+
<artifactId>workflow-aggregator</artifactId>
100+
<version>${workflow.version}</version>
101+
<classifier>tests</classifier>
102+
<scope>test</scope>
103+
</dependency>
104+
<dependency>
105+
<groupId>org.jenkins-ci.modules</groupId>
106+
<artifactId>sshd</artifactId>
107+
<version>1.6</version>
108+
<scope>test</scope>
109+
</dependency>
62110
<dependency>
63111
<groupId>org.mockito</groupId>
64112
<artifactId>mockito-all</artifactId>
@@ -67,4 +115,4 @@
67115
<scope>test</scope>
68116
</dependency>
69117
</dependencies>
70-
</project>
118+
</project>

src/main/java/org/jvnet/hudson/plugins/port_allocator/DefaultPortType.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package org.jvnet.hudson.plugins.port_allocator;
22

3-
import hudson.model.AbstractBuild;
43
import hudson.model.BuildListener;
54
import hudson.Launcher;
5+
import hudson.model.Run;
6+
import hudson.model.TaskListener;
67
import net.sf.json.JSONObject;
78
import org.kohsuke.stapler.DataBoundConstructor;
89
import org.kohsuke.stapler.StaplerRequest;
@@ -22,13 +23,15 @@ public DefaultPortType(String name) {
2223
}
2324

2425
@Override
25-
public Port allocate(AbstractBuild<?, ?> build, final PortAllocationManager manager, int prefPort, Launcher launcher, BuildListener buildListener) throws IOException, InterruptedException {
26+
public Port allocate(Run<?, ?> run, final PortAllocationManager manager, int prefPort, Launcher launcher, TaskListener taskListener)
27+
throws IOException, InterruptedException
28+
{
2629
final int n;
2730
if(isFixedPort())
28-
n = manager.allocate(build, getFixedPort());
31+
n = manager.allocate(run, getFixedPort());
2932
else
30-
n = manager.allocateRandom(build, prefPort);
31-
33+
n = manager.allocateRandom(run, prefPort);
34+
3235
return new Port(this) {
3336
public int get() {
3437
return n;

src/main/java/org/jvnet/hudson/plugins/port_allocator/GlassFishJmxPortType.java

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package org.jvnet.hudson.plugins.port_allocator;
22

33
import hudson.Launcher;
4-
import hudson.model.AbstractBuild;
5-
import hudson.model.BuildListener;
4+
import hudson.model.Run;
5+
import hudson.model.TaskListener;
66
import hudson.remoting.Callable;
77
import net.sf.json.JSONObject;
8+
import org.jenkinsci.remoting.RoleChecker;
89
import org.kohsuke.stapler.DataBoundConstructor;
910
import org.kohsuke.stapler.StaplerRequest;
1011

@@ -24,12 +25,14 @@
2425
import java.rmi.UnmarshalException;
2526
import java.util.HashMap;
2627
import java.util.Map;
28+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2729

2830
/**
2931
* GlassFish JMX port so that runaway GF instance can be terminated.
30-
*
32+
*
3133
* @author Kohsuke Kawaguchi
3234
*/
35+
@SuppressFBWarnings(value="SE_INNER_CLASS")
3336
public class GlassFishJmxPortType extends PortType {
3437
/**
3538
* GlassFish admin user name.
@@ -47,22 +50,25 @@ public GlassFishJmxPortType(String name, String userName, String password) {
4750
this.password = password;
4851
}
4952

53+
5054
@Override
51-
public Port allocate(AbstractBuild<?, ?> build, final PortAllocationManager manager, int prefPort, final Launcher launcher, final BuildListener buildListener) throws IOException, InterruptedException {
55+
public Port allocate(Run<?, ?> run, final PortAllocationManager manager, int prefPort, final Launcher launcher, final TaskListener taskListener)
56+
throws IOException, InterruptedException
57+
{
5258
final int n;
5359
if(isFixedPort())
54-
n = manager.allocate(build, getFixedPort());
60+
n = manager.allocate(run, getFixedPort());
5561
else
56-
n = manager.allocateRandom(build, prefPort);
62+
n = manager.allocateRandom(run, prefPort);
5763

5864
/**
5965
* Cleans up GlassFish instance.
6066
*/
61-
final class GlassFishCleanUpTask implements Callable<Void,IOException>, Serializable {
62-
private final BuildListener buildListener;
67+
class GlassFishCleanUpTask implements Callable<Void,IOException>, Serializable {
68+
private final TaskListener taskListener;
6369

64-
public GlassFishCleanUpTask(BuildListener buildListener) {
65-
this.buildListener = buildListener;
70+
public GlassFishCleanUpTask(TaskListener taskListener) {
71+
this.taskListener = taskListener;
6672
}
6773

6874
public Void call() throws IOException {
@@ -87,23 +93,27 @@ public Void call() throws IOException {
8793
} catch (UnmarshalException e) {
8894
if(e.getCause() instanceof SocketException || e.getCause() instanceof IOException) {
8995
// to be expected, as the above would shut down the server.
90-
buildListener.getLogger().println("GlassFish was shut down");
96+
taskListener.getLogger().println("GlassFish was shut down");
9197
} else {
9298
throw e;
9399
}
94100
} catch (MalformedObjectNameException e) {
95101
throw new AssertionError(e); // impossible
96102
} catch (InstanceNotFoundException e) {
97-
e.printStackTrace(buildListener.error("Unable to find J2EEServer mbean"));
103+
e.printStackTrace(taskListener.error("Unable to find J2EEServer mbean"));
98104
} catch (ReflectionException e) {
99-
e.printStackTrace(buildListener.error("Unable to access J2EEServer mbean"));
105+
e.printStackTrace(taskListener.error("Unable to access J2EEServer mbean"));
100106
} catch (MBeanException e) {
101-
e.printStackTrace(buildListener.error("Unable to call J2EEServer mbean"));
107+
e.printStackTrace(taskListener.error("Unable to call J2EEServer mbean"));
102108
}
103109
return null;
104110
}
105111

106112
private static final long serialVersionUID = 1L;
113+
114+
@Override
115+
public void checkRoles(RoleChecker roleChecker) throws SecurityException {
116+
}
107117
}
108118

109119
return new Port(this) {
@@ -113,7 +123,7 @@ public int get() {
113123

114124
public void cleanUp() throws IOException, InterruptedException {
115125
manager.free(n);
116-
launcher.getChannel().call(new GlassFishCleanUpTask(buildListener));
126+
launcher.getChannel().call(new GlassFishCleanUpTask(taskListener));
117127
}
118128
};
119129
}

src/main/java/org/jvnet/hudson/plugins/port_allocator/PoolNotDefinedException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
/**
44
* @author pepov
55
*/
6-
public class PoolNotDefinedException extends Throwable {
6+
public class PoolNotDefinedException extends Exception {
77
}

src/main/java/org/jvnet/hudson/plugins/port_allocator/PooledPortType.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import hudson.Extension;
44
import hudson.Launcher;
5-
import hudson.model.AbstractBuild;
65
import hudson.model.BuildListener;
6+
import hudson.model.Run;
7+
import hudson.model.TaskListener;
78
import hudson.util.ListBoxModel;
89
import net.sf.json.JSONObject;
910
import org.kohsuke.stapler.DataBoundConstructor;
@@ -30,23 +31,14 @@ public PooledPortType(String name) {
3031
* Wait for a short period if no free port is available, then try again.
3132
*/
3233
@Override
33-
public Port allocate(
34-
AbstractBuild<?, ?> build,
35-
final PortAllocationManager manager,
36-
int prefPort,
37-
Launcher launcher,
38-
BuildListener buildListener
39-
) throws IOException, InterruptedException {
40-
34+
public Port allocate(Run<?, ?> run, PortAllocationManager manager, int prefPort, Launcher launcher, TaskListener taskListener) throws IOException, InterruptedException {
4135
try {
4236
while (true) {
43-
4437
Pool pool = PortAllocator.DESCRIPTOR.getPoolByName(name);
45-
4638
synchronized (pool) {
4739
for (int port : pool.getPortsAsInt()) {
4840
if (manager.isFree(port)) {
49-
manager.allocate(build, port);
41+
manager.allocate(run, port);
5042
return new PooledPort(this, port, manager);
5143
}
5244
}

src/main/java/org/jvnet/hudson/plugins/port_allocator/Port.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package org.jvnet.hudson.plugins.port_allocator;
22

33
import java.io.IOException;
4+
import java.io.Serializable;
45

56
/**
67
* Represents an assigned TCP port and encapsulates how it should be cleaned up.
78
*
89
* @author Kohsuke Kawaguchi
910
*/
10-
public abstract class Port {
11+
public abstract class Port implements Serializable {
1112
/**
1213
* {@link PortType} that created this port.
1314
*/

0 commit comments

Comments
 (0)