1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.maven.plugin;
20
21 import java.io.OutputStream;
22 import java.net.ConnectException;
23 import java.net.InetAddress;
24 import java.net.Socket;
25
26 import org.apache.maven.plugin.AbstractMojo;
27 import org.apache.maven.plugin.MojoExecutionException;
28 import org.apache.maven.plugin.MojoFailureException;
29
30
31
32
33
34
35
36
37
38
39
40 public class JettyStopMojo extends AbstractMojo
41 {
42
43
44
45
46
47
48 protected int stopPort;
49
50
51
52
53
54
55
56 protected String stopKey;
57
58 public void execute() throws MojoExecutionException, MojoFailureException
59 {
60 if (stopPort <= 0)
61 throw new MojoExecutionException("Please specify a valid port");
62 if (stopKey == null)
63 throw new MojoExecutionException("Please specify a valid stopKey");
64
65 try
66 {
67 Socket s=new Socket(InetAddress.getByName("127.0.0.1"),stopPort);
68 s.setSoLinger(false, 0);
69
70 OutputStream out=s.getOutputStream();
71 out.write((stopKey+"\r\nstop\r\n").getBytes());
72 out.flush();
73 s.close();
74 }
75 catch (ConnectException e)
76 {
77 getLog().info("Jetty not running!");
78 }
79 catch (Exception e)
80 {
81 getLog().error(e);
82 }
83 }
84
85 public int getStopPort() {
86 return stopPort;
87 }
88
89 public void setStopPort(int stopPort) {
90 this.stopPort = stopPort;
91 }
92
93 public String getStopKey() {
94 return stopKey;
95 }
96
97 public void setStopKey(String stopKey) {
98 this.stopKey = stopKey;
99 }
100 }