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