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 public class Jetty6RunWarExploded extends AbstractJetty6Mojo
48 {
49
50
51
52
53
54
55
56
57 private File webApp;
58
59
60
61
62
63
64
65
66
67
68 public void checkPomConfiguration() throws MojoExecutionException
69 {
70 return;
71 }
72
73
74
75
76 public void configureScanner() throws MojoExecutionException
77 {
78 final ArrayList scanList = new ArrayList();
79 scanList.add(getProject().getFile());
80 File webInfDir = new File(webApp,"WEB-INF");
81 scanList.add(new File(webInfDir, "web.xml"));
82 File jettyWebXmlFile = findJettyWebXmlFile(webInfDir);
83 if (jettyWebXmlFile != null)
84 scanList.add(jettyWebXmlFile);
85 File jettyEnvXmlFile = new File(webInfDir, "jetty-env.xml");
86 if (jettyEnvXmlFile.exists())
87 scanList.add(jettyEnvXmlFile);
88 scanList.add(new File(webInfDir, "classes"));
89 scanList.add(new File(webInfDir, "lib"));
90 setScanList(scanList);
91
92 ArrayList listeners = new ArrayList();
93 listeners.add(new Scanner.BulkListener()
94 {
95 public void filesChanged(List changes)
96 {
97 try
98 {
99 boolean reconfigure = changes.contains(getProject().getFile().getCanonicalPath());
100 restartWebApp(reconfigure);
101 }
102 catch (Exception e)
103 {
104 getLog().error("Error reconfiguring/restarting webapp after change in watched files",e);
105 }
106 }
107 });
108 setScannerListeners(listeners);
109 }
110
111
112
113
114 public void restartWebApp(boolean reconfigureScanner) throws Exception
115 {
116 getLog().info("Restarting webapp");
117 getLog().debug("Stopping webapp ...");
118 webAppConfig.stop();
119 getLog().debug("Reconfiguring webapp ...");
120
121 checkPomConfiguration();
122
123
124
125 if (reconfigureScanner)
126 {
127 getLog().info("Reconfiguring scanner after change to pom.xml ...");
128 ArrayList scanList = getScanList();
129 scanList.clear();
130 scanList.add(getProject().getFile());
131 File webInfDir = new File(webApp,"WEB-INF");
132 scanList.add(new File(webInfDir, "web.xml"));
133 File jettyWebXmlFile = findJettyWebXmlFile(webInfDir);
134 if (jettyWebXmlFile != null)
135 scanList.add(jettyWebXmlFile);
136 File jettyEnvXmlFile = new File(webInfDir, "jetty-env.xml");
137 if (jettyEnvXmlFile.exists())
138 scanList.add(jettyEnvXmlFile);
139 scanList.add(new File(webInfDir, "classes"));
140 scanList.add(new File(webInfDir, "lib"));
141 setScanList(scanList);
142 getScanner().setScanDirs(scanList);
143 }
144
145 getLog().debug("Restarting webapp ...");
146 webAppConfig.start();
147 getLog().info("Restart completed.");
148 }
149
150
151
152
153
154 public void finishConfigurationBeforeStart() throws Exception
155 {
156 return;
157 }
158
159
160
161 public void configureWebApplication () throws Exception
162 {
163 super.configureWebApplication();
164 webAppConfig.setWar(webApp.getCanonicalPath());
165 webAppConfig.configure();
166 }
167
168 public void execute () throws MojoExecutionException, MojoFailureException
169 {
170 super.execute();
171 }
172
173 }