1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mortbay.jetty.plugin;
17
18 import java.io.File;
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.apache.maven.plugin.MojoExecutionException;
23 import org.apache.maven.plugin.MojoFailureException;
24 import org.mortbay.util.Scanner;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 public class Jetty6RunWar extends AbstractJetty6Mojo
51 {
52
53
54
55
56
57
58 private File webApp;
59
60
61
62
63
64
65 public void execute() throws MojoExecutionException, MojoFailureException
66 {
67 super.execute();
68 }
69
70
71
72 public void configureWebApplication () throws Exception
73 {
74 super.configureWebApplication();
75
76 webAppConfig.setWar(webApp.getCanonicalPath());
77 webAppConfig.configure();
78 }
79
80
81
82
83
84
85 public void checkPomConfiguration() throws MojoExecutionException
86 {
87 return;
88 }
89
90
91
92
93
94
95 public void configureScanner() throws MojoExecutionException
96 {
97 final ArrayList scanList = new ArrayList();
98 scanList.add(getProject().getFile());
99 scanList.add(webApp);
100 setScanList(scanList);
101
102 ArrayList listeners = new ArrayList();
103 listeners.add(new Scanner.BulkListener()
104 {
105 public void filesChanged(List changes)
106 {
107 try
108 {
109 boolean reconfigure = changes.contains(getProject().getFile().getCanonicalPath());
110 restartWebApp(reconfigure);
111 }
112 catch (Exception e)
113 {
114 getLog().error("Error reconfiguring/restarting webapp after change in watched files",e);
115 }
116 }
117 });
118 setScannerListeners(listeners);
119
120 }
121
122
123
124
125 public void restartWebApp(boolean reconfigureScanner) throws Exception
126 {
127 getLog().info("Restarting webapp ...");
128 getLog().debug("Stopping webapp ...");
129 webAppConfig.stop();
130 getLog().debug("Reconfiguring webapp ...");
131
132 checkPomConfiguration();
133
134
135
136 if (reconfigureScanner)
137 {
138 getLog().info("Reconfiguring scanner after change to pom.xml ...");
139 ArrayList scanList = getScanList();
140 scanList.clear();
141 scanList.add(getProject().getFile());
142 scanList.add(webApp);
143 setScanList(scanList);
144 getScanner().setScanDirs(scanList);
145 }
146
147 getLog().debug("Restarting webapp ...");
148 webAppConfig.start();
149 getLog().info("Restart completed.");
150 }
151
152
153
154
155
156 public void finishConfigurationBeforeStart()
157 {
158 return;
159 }
160
161
162
163
164 }