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.util.Iterator;
24
25 import org.eclipse.jetty.quickstart.QuickStartConfiguration;
26 import org.eclipse.jetty.util.IO;
27 import org.eclipse.jetty.util.log.Log;
28 import org.eclipse.jetty.util.log.Logger;
29 import org.eclipse.jetty.util.resource.Resource;
30 import org.eclipse.jetty.util.resource.ResourceCollection;
31 import org.eclipse.jetty.webapp.WebAppClassLoader;
32 import org.eclipse.jetty.webapp.WebAppContext;
33
34
35
36
37
38
39 public class MavenQuickStartConfiguration extends QuickStartConfiguration
40 {
41 private static final Logger LOG = Log.getLogger(QuickStartConfiguration.class);
42
43 private Resource _quickStartWebXml;
44
45
46 public void setQuickStartWebXml (Resource r)
47 {
48 _quickStartWebXml = r;
49 }
50
51
52
53 @Override
54 public Resource getQuickStartWebXml(WebAppContext context) throws Exception
55 {
56 return _quickStartWebXml;
57 }
58
59 @Override
60 public void preConfigure(WebAppContext context) throws Exception
61 {
62
63 if (context.getBaseResource() == null)
64 throw new IllegalStateException ("No location for webapp");
65
66
67
68 Resource quickStartWebXml = getQuickStartWebXml(context);
69 LOG.debug("quickStartWebXml={}",quickStartWebXml);
70
71 context.getMetaData().setWebXml(quickStartWebXml);
72 }
73
74
75 @Override
76 public void configure(WebAppContext context) throws Exception
77 {
78
79 JettyWebAppContext jwac = (JettyWebAppContext)context;
80
81
82 if (jwac.getClassPathFiles() != null)
83 {
84 if (LOG.isDebugEnabled()) LOG.debug("Setting up classpath ...");
85 Iterator itor = jwac.getClassPathFiles().iterator();
86 while (itor.hasNext())
87 ((WebAppClassLoader)context.getClassLoader()).addClassPath(((File)itor.next()).getCanonicalPath());
88 }
89
90
91 super.configure(context);
92
93
94 String[] existingServerClasses = context.getServerClasses();
95 String[] newServerClasses = new String[2+(existingServerClasses==null?0:existingServerClasses.length)];
96 newServerClasses[0] = "org.apache.maven.";
97 newServerClasses[1] = "org.codehaus.plexus.";
98 System.arraycopy( existingServerClasses, 0, newServerClasses, 2, existingServerClasses.length );
99 if (LOG.isDebugEnabled())
100 {
101 LOG.debug("Server classes:");
102 for (int i=0;i<newServerClasses.length;i++)
103 LOG.debug(newServerClasses[i]);
104 }
105 context.setServerClasses( newServerClasses );
106 }
107
108 @Override
109 public void deconfigure(WebAppContext context) throws Exception
110 {
111
112 if (!context.isPersistTempDirectory())
113 {
114 Resource originalBases = (Resource)context.getAttribute("org.eclipse.jetty.resources.originalBases");
115 String originalBaseStr = originalBases.toString();
116
117
118
119 Resource res = context.getBaseResource();
120 if (res instanceof ResourceCollection)
121 {
122 for (Resource r:((ResourceCollection)res).getResources())
123 {
124 if (originalBaseStr.contains(r.toString()))
125 continue;
126 IO.delete(r.getFile());
127 }
128 }
129 }
130 }
131
132 }