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 QueuedThreadPool tpool = null;
79
80 try
81 {
82 printSystemProperties();
83
84
85
86 applyJettyXml ();
87
88 ServerSupport.configureHandlers(server, null);
89
90
91 configureWebApplication();
92
93
94
95 webApp.setCopyWebDir(false);
96 webApp.setCopyWebInf(false);
97 webApp.setGenerateQuickStart(true);
98
99
100
101 if (webApp.getQuickStartWebDescriptor() == null)
102 {
103 if (effectiveWebXml == null)
104 {
105 deleteOnExit = true;
106 effectiveWebXml = new File(target, "effective-web.xml");
107 effectiveWebXml.deleteOnExit();
108 }
109
110 Resource descriptor = Resource.newResource(effectiveWebXml);
111
112 if (!effectiveWebXml.getParentFile().exists())
113 effectiveWebXml.getParentFile().mkdirs();
114 if (!effectiveWebXml.exists())
115 effectiveWebXml.createNewFile();
116
117 webApp.setQuickStartWebDescriptor(descriptor);
118 }
119
120 ServerSupport.addWebApplication(server, webApp);
121
122
123
124 tpool = server.getBean(QueuedThreadPool.class);
125 if (tpool != null)
126 tpool.start();
127 else
128 webApp.setAttribute(AnnotationConfiguration.MULTI_THREADED, Boolean.FALSE.toString());
129
130 webApp.start();
131
132 }
133 catch (Exception e)
134 {
135 throw new MojoExecutionException("Effective web.xml generation failed", e);
136 }
137 finally
138 {
139 try {webApp.stop();}catch (Exception x) {};
140
141 try {if (tpool != null) tpool.stop();} catch (Exception x) {};
142 }
143
144
145 if (deleteOnExit)
146 {
147 try
148 {
149
150 getLog().info(IO.toString(webApp.getQuickStartWebDescriptor().getInputStream()));
151 }
152 catch (IOException e)
153 {
154 throw new MojoExecutionException("Unable to output effective web.xml", e);
155 }
156
157 }
158
159 }
160 }