1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.eclipse.jetty.maven.plugin;
21
22 import java.io.File;
23 import java.io.IOException;
24
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugin.MojoFailureException;
27 import org.eclipse.jetty.annotations.AnnotationConfiguration;
28 import org.eclipse.jetty.util.IO;
29 import org.eclipse.jetty.util.resource.Resource;
30 import org.eclipse.jetty.util.thread.QueuedThreadPool;
31
32
33
34
35
36
37
38
39
40 public class JettyEffectiveWebXml extends JettyRunMojo
41 {
42
43
44
45
46
47
48
49 protected File target;
50
51
52
53
54
55
56 protected File effectiveWebXml;
57
58
59 protected boolean deleteOnExit = true;
60
61
62
63
64
65 public void execute() throws MojoExecutionException, MojoFailureException
66 {
67 super.execute();
68 }
69
70
71 @Override
72 public void startJetty() throws MojoExecutionException
73 {
74
75
76
77
78
79 if (effectiveWebXml == null)
80 {
81 deleteOnExit = true;
82 effectiveWebXml = new File(target, "effective-web.xml");
83 effectiveWebXml.deleteOnExit();
84 }
85
86 Resource descriptor = Resource.newResource(effectiveWebXml);
87
88 QueuedThreadPool tpool = null;
89
90 try
91 {
92 printSystemProperties();
93
94
95
96 applyJettyXml ();
97
98
99 server.configureHandlers();
100
101
102 configureWebApplication();
103
104
105
106 webApp.setCopyWebDir(false);
107 webApp.setCopyWebInf(false);
108 webApp.setGenerateQuickStart(true);
109
110 if (!effectiveWebXml.getParentFile().exists())
111 effectiveWebXml.getParentFile().mkdirs();
112 if (!effectiveWebXml.exists())
113 effectiveWebXml.createNewFile();
114
115 webApp.setQuickStartWebDescriptor(descriptor);
116
117 server.addWebApplication(webApp);
118
119
120
121 tpool = server.getBean(QueuedThreadPool.class);
122 if (tpool != null)
123 tpool.start();
124 else
125 webApp.setAttribute(AnnotationConfiguration.MULTI_THREADED, Boolean.FALSE.toString());
126
127 webApp.start();
128
129 }
130 catch (Exception e)
131 {
132 throw new MojoExecutionException("Effective web.xml generation failed", e);
133 }
134 finally
135 {
136 try {webApp.stop();}catch (Exception x) {};
137
138 try {if (tpool != null) tpool.stop();} catch (Exception x) {};
139 }
140
141
142 if (deleteOnExit)
143 {
144 try
145 {
146
147 getLog().info(IO.toString(descriptor.getInputStream()));
148 }
149 catch (IOException e)
150 {
151 throw new MojoExecutionException("Unable to output effective web.xml", e);
152 }
153
154 }
155
156 }
157 }