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