View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
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.log.Log;
27  import org.eclipse.jetty.util.log.Logger;
28  import org.eclipse.jetty.util.resource.Resource;
29  import org.eclipse.jetty.webapp.WebAppClassLoader;
30  import org.eclipse.jetty.webapp.WebAppContext;
31  
32  /**
33   * MavenQuickStartConfiguration
34   *
35   *
36   */
37  public class MavenQuickStartConfiguration extends QuickStartConfiguration
38  {
39      private static final Logger LOG = Log.getLogger(QuickStartConfiguration.class);
40      
41      private Resource _quickStartWebXml;
42  
43  
44      public void setQuickStartWebXml (Resource r)
45      {
46          _quickStartWebXml = r;
47      }
48      
49     
50      
51      @Override
52      public Resource getQuickStartWebXml(WebAppContext context) throws Exception
53      {
54          return _quickStartWebXml;
55      }
56  
57  
58  
59      @Override
60      public void configure(WebAppContext context) throws Exception
61      {
62          
63         JettyWebAppContext jwac = (JettyWebAppContext)context;
64          
65          //put the classes dir and all dependencies into the classpath
66          if (jwac.getClassPathFiles() != null)
67          {
68              if (LOG.isDebugEnabled()) LOG.debug("Setting up classpath ...");
69              Iterator itor = jwac.getClassPathFiles().iterator();
70              while (itor.hasNext())
71                  ((WebAppClassLoader)context.getClassLoader()).addClassPath(((File)itor.next()).getCanonicalPath());
72          }
73          
74          //Set up the quickstart environment for the context
75          super.configure(context);
76          
77          // knock out environmental maven and plexus classes from webAppContext
78          String[] existingServerClasses = context.getServerClasses();
79          String[] newServerClasses = new String[2+(existingServerClasses==null?0:existingServerClasses.length)];
80          newServerClasses[0] = "org.apache.maven.";
81          newServerClasses[1] = "org.codehaus.plexus.";
82          System.arraycopy( existingServerClasses, 0, newServerClasses, 2, existingServerClasses.length );
83          if (LOG.isDebugEnabled())
84          {
85              LOG.debug("Server classes:");
86              for (int i=0;i<newServerClasses.length;i++)
87                  LOG.debug(newServerClasses[i]);
88          }
89          context.setServerClasses( newServerClasses ); 
90      }
91      
92  }