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.File;
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugin.MojoFailureException;
27 import org.eclipse.jetty.util.Scanner;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 public class JettyRunWarExplodedMojo extends AbstractJettyMojo
48 {
49
50
51
52
53
54
55
56
57
58 private File war;
59
60
61
62
63
64
65
66
67 public void execute () throws MojoExecutionException, MojoFailureException
68 {
69 super.execute();
70 }
71
72
73
74 @Override
75 public void finishConfigurationBeforeStart() throws Exception
76 {
77 server.setStopAtShutdown(true);
78 super.finishConfigurationBeforeStart();
79 }
80
81
82
83
84
85
86 public void checkPomConfiguration() throws MojoExecutionException
87 {
88 return;
89 }
90
91
92
93
94
95
96
97 public void configureScanner() throws MojoExecutionException
98 {
99 scanList = new ArrayList<File>();
100 scanList.add(project.getFile());
101 File webInfDir = new File(war,"WEB-INF");
102 scanList.add(new File(webInfDir, "web.xml"));
103 File jettyWebXmlFile = findJettyWebXmlFile(webInfDir);
104 if (jettyWebXmlFile != null)
105 scanList.add(jettyWebXmlFile);
106 File jettyEnvXmlFile = new File(webInfDir, "jetty-env.xml");
107 if (jettyEnvXmlFile.exists())
108 scanList.add(jettyEnvXmlFile);
109 scanList.add(new File(webInfDir, "classes"));
110 scanList.add(new File(webInfDir, "lib"));
111
112 scannerListeners = new ArrayList<Scanner.BulkListener>();
113 scannerListeners.add(new Scanner.BulkListener()
114 {
115 public void filesChanged(List changes)
116 {
117 try
118 {
119 boolean reconfigure = changes.contains(project.getFile().getCanonicalPath());
120 restartWebApp(reconfigure);
121 }
122 catch (Exception e)
123 {
124 getLog().error("Error reconfiguring/restarting webapp after change in watched files",e);
125 }
126 }
127 });
128 }
129
130
131
132
133
134
135
136 public void restartWebApp(boolean reconfigureScanner) throws Exception
137 {
138 getLog().info("Restarting webapp");
139 getLog().debug("Stopping webapp ...");
140 webApp.stop();
141 getLog().debug("Reconfiguring webapp ...");
142
143 checkPomConfiguration();
144
145
146
147 if (reconfigureScanner)
148 {
149 getLog().info("Reconfiguring scanner after change to pom.xml ...");
150 scanList.clear();
151 scanList.add(project.getFile());
152 File webInfDir = new File(war,"WEB-INF");
153 scanList.add(new File(webInfDir, "web.xml"));
154 File jettyWebXmlFile = findJettyWebXmlFile(webInfDir);
155 if (jettyWebXmlFile != null)
156 scanList.add(jettyWebXmlFile);
157 File jettyEnvXmlFile = new File(webInfDir, "jetty-env.xml");
158 if (jettyEnvXmlFile.exists())
159 scanList.add(jettyEnvXmlFile);
160 scanList.add(new File(webInfDir, "classes"));
161 scanList.add(new File(webInfDir, "lib"));
162 scanner.setScanDirs(scanList);
163 }
164
165 getLog().debug("Restarting webapp ...");
166 webApp.start();
167 getLog().info("Restart completed.");
168 }
169
170
171
172
173
174
175
176 public void configureWebApplication () throws Exception
177 {
178 super.configureWebApplication();
179 webApp.setWar(war.getCanonicalPath());
180 }
181 }