1 package org.apache.tomcat.maven.plugin.tomcat7.run;
2 /*
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 */
20
21 import org.apache.catalina.Context;
22 import org.apache.catalina.Host;
23 import org.apache.catalina.core.StandardContext;
24 import org.apache.catalina.startup.ContextConfig;
25 import org.apache.catalina.startup.Tomcat;
26
27 import java.io.File;
28
29 /**
30 * @author Olivier Lamy
31 * @since 2.0
32 */
33 public class ExtendedTomcat
34 extends Tomcat
35 {
36
37 private File configurationDir;
38
39 public ExtendedTomcat( File configurationDir )
40 {
41 super();
42 this.configurationDir = configurationDir;
43 }
44
45 public Context addWebapp( Host host, String url, String name, String path )
46 {
47
48 Context ctx = new StandardContext();
49 ctx.setName( name );
50 ctx.setPath( url );
51 ctx.setDocBase( path );
52
53 ContextConfig ctxCfg = new ContextConfig();
54 ctx.addLifecycleListener( ctxCfg );
55
56 ctxCfg.setDefaultWebXml( new File( configurationDir, "conf/web.xml" ).getAbsolutePath() );
57
58 if ( host == null )
59 {
60 getHost().addChild( ctx );
61 }
62 else
63 {
64 host.addChild( ctx );
65 }
66
67 return ctx;
68 }
69 }