Advertisement
Guest User

MTOMCAT-100

a guest
Jun 1st, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.26 KB | None | 0 0
  1. Index: tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/AbstractRunMojo.java
  2. ===================================================================
  3. --- tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/AbstractRunMojo.java  (revision 1345248)
  4. +++ tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/AbstractRunMojo.java  (working copy)
  5. @@ -60,13 +60,14 @@
  6.  import java.net.InetAddress;
  7.  import java.net.MalformedURLException;
  8.  import java.net.URL;
  9. -import java.security.Principal;
  10.  import java.util.ArrayList;
  11.  import java.util.Collection;
  12. +import java.util.Hashtable;
  13.  import java.util.Iterator;
  14.  import java.util.List;
  15.  import java.util.Map;
  16.  import java.util.Set;
  17. +import org.apache.naming.resources.FileDirContext;
  18.  
  19.  /**
  20.   * Abstract goal that provides common configuration for embedded Tomcat goals.
  21. @@ -433,6 +434,7 @@
  22.       *
  23.       * @return the webapp context path
  24.       */
  25. +    @Override
  26.      protected String getPath()
  27.      {
  28.          return path;
  29. @@ -465,6 +467,12 @@
  30.              webappLoader.setLoaderClass( classLoaderClass );
  31.          }
  32.  
  33. +        MultipleDirContext dc = this.getFileDirContext();
  34. +        if (dc != null)
  35. +        {
  36. +            context.setResources(dc);
  37. +        }
  38. +
  39.          context.setLoader( webappLoader );
  40.          File contextFile = getContextFile();
  41.          if ( contextFile != null )
  42. @@ -615,7 +623,7 @@
  43.                  {
  44.                      throw new MojoExecutionException( " tomcatWebXml " + tomcatWebXml.getPath() + " not exists" );
  45.                  }
  46. -                //MTOMCAT-42  here it's a real file resources not a one coming with the mojo
  47. +                //MTOMCAT-42  here it's a real file resources not a one coming with the mojo
  48.                  FileUtils.copyFile( tomcatWebXml, new File( confDir, "web.xml" ) );
  49.                  //copyFile( tomcatWebXml.getPath(), new File( confDir, "web.xml" ) );
  50.              }
  51. @@ -1003,4 +1011,122 @@
  52.              host.addChild( staticContext );
  53.          }
  54.      }
  55. +
  56. +    /**
  57. +     * Scan ${project.build.dir}/apache-tomcat-maven-plugin for directories. Every directory found
  58. +     * is assumed to be a WAR overlay and is added to a MultipleDirContext
  59. +     *
  60. +     * @return
  61. +     */
  62. +    private MultipleDirContext getFileDirContext()
  63. +    {
  64. +        MultipleDirContext ret = null;
  65. +
  66. +        File f = new File(project.getBuild().getDirectory(), "apache-tomcat-maven-plugin");
  67. +        if (f.isDirectory())
  68. +        {
  69. +            ret = new MultipleDirContext();
  70. +            for (final File overlayRoot : f.listFiles())
  71. +            {
  72. +                if (overlayRoot.isDirectory())
  73. +                {
  74. +                    ret.addVirtualDocBase(overlayRoot.getPath());
  75. +                }
  76. +            }
  77. +        }
  78. +
  79. +        return ret;
  80. +    }
  81. +
  82. +    /**
  83. +     * WAR overlays can contain other resources besides classes. This class overlays the extracted
  84. +     * WAR overlay directory over the docBase; if a file is not found in the docBase then the WAR
  85. +     * overlays are searched
  86. +     *
  87. +     * See http://blog.bazoud.com/post/2009-05-12-multiples-docbases-avec-tomcat.html
  88. +     */
  89. +    private static class MultipleDirContext extends FileDirContext
  90. +    {
  91. +        private final ArrayList<FileDirContextAdapter> virtualContexts = new ArrayList<FileDirContextAdapter>();
  92. +
  93. +        public MultipleDirContext()
  94. +        {
  95. +           super();
  96. +        }
  97. +
  98. +        public MultipleDirContext(Hashtable env)
  99. +        {
  100. +           super(env);
  101. +        }
  102. +
  103. +        public void addVirtualDocBase(final String virtualDocBase)
  104. +        {
  105. +           FileDirContextAdapter x = new FileDirContextAdapter();
  106. +           x.setDocBase(virtualDocBase);
  107. +           virtualContexts.add(x);
  108. +        }
  109. +
  110. +        @Override
  111. +        public void allocate()
  112. +        {
  113. +            super.allocate();
  114. +
  115. +            for (final FileDirContextAdapter x : virtualContexts)
  116. +            {
  117. +                x.allocate();
  118. +            }
  119. +        }
  120. +
  121. +        @Override
  122. +        public void release()
  123. +        {
  124. +            super.release();
  125. +            for (final FileDirContextAdapter x : virtualContexts)
  126. +            {
  127. +                x.release();
  128. +            }
  129. +        }
  130. +
  131. +        @Override
  132. +        protected File file(String name)
  133. +        {
  134. +            File ret = super.file(name);
  135. +
  136. +            if (ret == null)
  137. +            {
  138. +                for (final FileDirContextAdapter x : virtualContexts)
  139. +                {
  140. +                    ret = x.file(name);
  141. +                    if (ret != null)
  142. +                    {
  143. +                        break;
  144. +                    }
  145. +                }
  146. +            }
  147. +
  148. +            return ret;
  149. +        }
  150. +    }
  151. +
  152. +    /**
  153. +     * Used to make {@link FileDirContext#file(java.lang.String)} accessible from this context
  154. +     */
  155. +    private static class FileDirContextAdapter extends FileDirContext
  156. +    {
  157. +        FileDirContextAdapter()
  158. +        {
  159. +            super();
  160. +        }
  161. +
  162. +        FileDirContextAdapter(Hashtable env)
  163. +        {
  164. +            super(env);
  165. +        }
  166. +
  167. +        @Override
  168. +        protected File file(String name)
  169. +        {
  170. +            return super.file(name);
  171. +        }
  172. +    }
  173.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement