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