View | Details | Raw Unified | Return to bug 50205
Collapse All | Expand All

(-)java/org/apache/catalina/core/StandardHost.java (+62 lines)
Lines 20-28 Link Here
20
20
21
21
22
import java.util.ArrayList;
22
import java.util.ArrayList;
23
import java.util.Arrays;
23
import java.util.List;
24
import java.util.List;
25
import java.util.ListIterator;
24
import java.util.Map;
26
import java.util.Map;
25
import java.util.WeakHashMap;
27
import java.util.WeakHashMap;
28
import java.util.regex.Pattern;
26
29
27
import javax.management.MBeanServer;
30
import javax.management.MBeanServer;
28
import javax.management.ObjectName;
31
import javax.management.ObjectName;
Lines 114-119 Link Here
114
117
115
118
116
    /**
119
    /**
120
     * The ignored deploy paths for this Host.
121
     */
122
    private String deployIgnorePaths = "";
123
124
125
    /**
126
     * The ignored deploy path Patterns for this Host.
127
     */
128
    private ArrayList<Pattern> deployIgnorePathPatterns = new ArrayList<Pattern>();
129
130
131
    /**
117
     * The deploy on startup flag for this Host.
132
     * The deploy on startup flag for this Host.
118
     */
133
     */
119
    private boolean deployOnStartup = true;
134
    private boolean deployOnStartup = true;
Lines 290-295 Link Here
290
305
291
306
292
    /**
307
    /**
308
     * Return the list of regular expressions for files/directories
309
     * excluded from automatic deployment.
310
     */
311
    public String getDeployIgnorePaths() {
312
313
        return (this.deployIgnorePaths);
314
315
    }
316
317
318
    /**
319
     * Set the list of regular expressions for files/directories
320
     * excluded from automatic deployment.
321
     *
322
     * @param ignorePaths A comma-separated list of regular
323
     *        expression strings.
324
     */
325
    public void setDeployIgnorePaths(String ignorePaths) {
326
327
        String oldDeployIgnorePaths = this.deployIgnorePaths;
328
        List<String> newPaths = Arrays.asList(ignorePaths.split("\\s*,\\s*"));
329
        ArrayList<Pattern> newPatterns = new ArrayList<Pattern>(newPaths.size());
330
331
        for (ListIterator<String> i = newPaths.listIterator(); i.hasNext(); ) {
332
            newPatterns.add(Pattern.compile(i.next()));
333
        }
334
335
        this.deployIgnorePaths = ignorePaths;
336
        this.deployIgnorePathPatterns = newPatterns;
337
        support.firePropertyChange("deployIgnorePaths", oldDeployIgnorePaths,
338
                                   this.deployIgnorePaths);
339
340
    }
341
342
343
    /**
344
     * Return the list of Patterns for files/directories excluded from
345
     * automatic deployment.
346
     */
347
    public ArrayList<Pattern> getDeployIgnorePathPatterns() {
348
349
        return (this.deployIgnorePathPatterns);
350
351
    }
352
353
354
    /**
293
     * Return the value of the deploy on startup flag.  If true, it indicates 
355
     * Return the value of the deploy on startup flag.  If true, it indicates 
294
     * that this host's child webapps should be discovred and automatically 
356
     * that this host's child webapps should be discovred and automatically 
295
     * deployed at startup time.
357
     * deployed at startup time.
(-)java/org/apache/catalina/core/mbeans-descriptors.xml (+4 lines)
Lines 466-471 Link Here
466
               description="The configuration class for contexts"
466
               description="The configuration class for contexts"
467
               type="java.lang.String"/>
467
               type="java.lang.String"/>
468
      
468
      
469
    <attribute name="deployIgnorePaths"
470
               description="Paths within appBase ignored for deployment"
471
               type="java.lang.String"/>
472
469
    <attribute name="deployOnStartup"
473
    <attribute name="deployOnStartup"
470
               description="The deploy on startup flag for this Host"
474
               description="The deploy on startup flag for this Host"
471
               type="boolean"/>
475
               type="boolean"/>
(-)java/org/apache/catalina/startup/HostConfig.java (-2 / +53 lines)
Lines 27-38 Link Here
27
import java.io.InputStream;
27
import java.io.InputStream;
28
import java.io.OutputStream;
28
import java.io.OutputStream;
29
import java.util.ArrayList;
29
import java.util.ArrayList;
30
import java.util.Arrays;
30
import java.util.HashMap;
31
import java.util.HashMap;
31
import java.util.HashSet;
32
import java.util.HashSet;
32
import java.util.LinkedHashMap;
33
import java.util.LinkedHashMap;
34
import java.util.ListIterator;
33
import java.util.Set;
35
import java.util.Set;
34
import java.util.jar.JarEntry;
36
import java.util.jar.JarEntry;
35
import java.util.jar.JarFile;
37
import java.util.jar.JarFile;
38
import java.util.regex.Pattern;
36
39
37
import javax.management.ObjectName;
40
import javax.management.ObjectName;
38
41
Lines 494-510 Link Here
494
497
495
        File appBase = appBase();
498
        File appBase = appBase();
496
        File configBase = configBase();
499
        File configBase = configBase();
500
        String[] fileList = validAppPaths(appBase.list());
497
        // Deploy XML descriptors from configBase
501
        // Deploy XML descriptors from configBase
498
        deployDescriptors(configBase, configBase.list());
502
        deployDescriptors(configBase, configBase.list());
499
        // Deploy WARs, and loop if additional descriptors are found
503
        // Deploy WARs, and loop if additional descriptors are found
500
        deployWARs(appBase, appBase.list());
504
        deployWARs(appBase, fileList);
501
        // Deploy expanded folders
505
        // Deploy expanded folders
502
        deployDirectories(appBase, appBase.list());
506
        deployDirectories(appBase, fileList);
503
        
507
        
504
    }
508
    }
505
509
506
510
507
    /**
511
    /**
512
     * Return the provided array of paths after removing those matching regular
513
     * expressions configured via the Host's deployIgnorePaths.
514
     *
515
     * @param paths The file paths to be checked, presumably those within
516
     *              appBase.
517
     * @return A String array containing the path list after excluding ignored
518
     *         paths.
519
     */
520
    protected String[] validAppPaths(String[] paths) {
521
522
        if (!(host instanceof StandardHost)) {
523
            return paths;
524
        }
525
526
        ArrayList<Pattern> ignorePatterns = ((StandardHost) host).getDeployIgnorePathPatterns();
527
528
        if ((ignorePatterns == null) || (ignorePatterns.size() == 0)) {
529
            return paths;
530
        }
531
532
        ArrayList<String> goodPaths = new ArrayList<String>(Arrays.asList(paths));
533
534
        for (ListIterator<String> i = goodPaths.listIterator(); i.hasNext(); ) {
535
            String path = i.next();
536
537
            for (ListIterator<Pattern> j = ignorePatterns.listIterator(); j.hasNext(); ) {
538
                Pattern ignorePattern = j.next();
539
540
                if (ignorePattern.matcher(path).matches()) {
541
                    if(log.isDebugEnabled()) {
542
                        log.debug("Ignoring application path \""
543
                                + path + "\" (matches pattern \""
544
                                + ignorePattern.pattern() + "\").");
545
                    }
546
547
                    i.remove();
548
                    break;
549
                }
550
            }
551
        }
552
553
        return goodPaths.toArray(new String[0]);
554
555
    }
556
557
558
    /**
508
     * Deploy applications for any directories or WAR files that are found
559
     * Deploy applications for any directories or WAR files that are found
509
     * in our "application root" directory.
560
     * in our "application root" directory.
510
     */
561
     */
(-)webapps/docs/config/host.xml (-19 / +43 lines)
Lines 158-163 Link Here
158
158
159
    <attributes>
159
    <attributes>
160
160
161
      <attribute name="deployIgnorePaths" required="false">
162
        <p>A comma-separated list of regular expressions of paths to
163
        <em>ignore</em> for <code>autoDeploy</code> and
164
        <code>deployOnStartup</code>. This allows you to keep your configuration
165
        in a version control system, for example, and not deploy a .svn or CVS
166
        folder that happens to be in <code>appBase</code>.</p>
167
        <p>These regular expressions are relative to <code>appBase</code>. They
168
        are also <em>anchored</em>, meaning the match is performed against the
169
        entire file/directory name. So, <code>foo</code> matches only a file or
170
        directory named <code>foo</code> but not <code>foo.war</code>,
171
        <code>foobar</code>, or <code>myfooapp</code>. To match anything with
172
        &quot;foo&quot;, you would use something like <code>.*foo.*</code>.</p>
173
        <p>From a performance standpoint, a single regular expression using
174
        alternation will be more efficient than separate regular expressions.
175
        For example, <code>deployIgnorePaths</code> set to
176
        <code>foo\.war|bar</code> has the same effect as
177
        <code>foo\.war,bar</code>, but the former is more efficient.</p>
178
        <p>See <a href="#Automatic Application Deployment">Automatic Application
179
        Deployment</a> for more information.</p>
180
      </attribute>
181
161
      <attribute name="deployXML" required="false">
182
      <attribute name="deployXML" required="false">
162
        <p>Set to <code>false</code> if you want to disable parsing the context
183
        <p>Set to <code>false</code> if you want to disable parsing the context
163
        XML descriptor embedded inside the application (located at
184
        XML descriptor embedded inside the application (located at
Lines 306-319 Link Here
306
        <code>ROOT.xml</code>.</li>
327
        <code>ROOT.xml</code>.</li>
307
    <li>Any web application archive file within the Host's <code>appBase</code>
328
    <li>Any web application archive file within the Host's <code>appBase</code>
308
        directory that has not already been deployed as a result of a context
329
        directory that has not already been deployed as a result of a context
309
        XML descriptor and does not have a corresponding directory of the same
330
        XML descriptor, does not have a corresponding directory of the same
310
        name (without the ".war" extension) will be deployed next. The context
331
        name (without the ".war" extension), and is not excluded by
311
        path used will be a slash character ("/") followed by the web
332
        <code>deployIgnorePaths</code> will be deployed next. The context path
312
        application archive name less the ".war" extension. The one exception to
333
        used will be a slash character ("/") followed by the web application
313
        this rule is that a web application archive named "ROOT.war" will be
334
        archive name less the ".war" extension. The one exception to this rule
314
        deployed with a context path of <code>/</code>. Multi-level contexts may
335
        is that a web application archive named "ROOT.war" will be deployed with
315
        be defined by using #, e.g. use a WAR named <code>foo#bar.war</code> for
336
        a context path of <code>/</code>. Multi-level contexts may be defined by
316
        a context path of <code>/foo/bar</code>.<br/>
337
        using #, e.g. use a WAR named <code>foo#bar.war</code> for a context
338
        path of <code>/foo/bar</code>.<br/>
317
        If the <code>unpackWARs</code> attribute is <code>true</code>, the web
339
        If the <code>unpackWARs</code> attribute is <code>true</code>, the web
318
        application archive file will be expanded to a directory of the same
340
        application archive file will be expanded to a directory of the same
319
        name (without the ".war" extension".<br/>
341
        name (without the ".war" extension".<br/>
Lines 333-343 Link Here
333
        </li>
355
        </li>
334
    <li>Finally, any sub-directory within the Host's <code>appBase</code> that
356
    <li>Finally, any sub-directory within the Host's <code>appBase</code> that
335
        has not already been deployed as a result of a context XML descriptor
357
        has not already been deployed as a result of a context XML descriptor
336
        will be deployed. The context path used will be a slash character
358
        and is not excluded by <code>deployIgnorePaths</code> will be deployed.
337
        ("/") followed by the directory name, unless the directory name is ROOT,
359
        The context path used will be a slash character ("/") followed by the
338
        in which case the context path will <code>/</code>. Multi-level contexts
360
        directory name, unless the directory name is ROOT, in which case the
339
        may be defined by using #, e.g. use a directory named
361
        context path will <code>/</code>. Multi-level contexts may be defined by
340
        <code>foo#bar</code> for a context path of <code>/foo/bar</code>.<br/>
362
        using #, e.g. use a directory named <code>foo#bar</code> for a context
363
        path of <code>/foo/bar</code>.<br/>
341
        Any directory within the Hosts's <code>appBase</code> directory that
364
        Any directory within the Hosts's <code>appBase</code> directory that
342
        does not have a corresponding context XML descriptor in
365
        does not have a corresponding context XML descriptor in
343
        <code>$CATALINA_BASE/conf/[engine_name]/[host_name]</code> will be
366
        <code>$CATALINA_BASE/conf/[engine_name]/[host_name]</code> will be
Lines 390-404 Link Here
390
413
391
    <p>When using automatic deployment, the <code>docBase</code> defined by
414
    <p>When using automatic deployment, the <code>docBase</code> defined by
392
    an XML <a href="context.html">Context</a> file should be outside of the
415
    an XML <a href="context.html">Context</a> file should be outside of the
393
    <code>appBase</code> directory. If this is not the case difficulties
416
    <code>appBase</code> directory. If this is not the case, difficulties
394
    may be experienced deploying the web application or the application may
417
    may be experienced deploying the web application or the application may
395
    be deployed twice.</p>
418
    be deployed twice. The <code>deployIgnorePaths</code> attribute can be used
419
    to avoid this situation.</p>
396
420
397
    <p>Finally, note that if you are defining contexts explicitly in server.xml,
421
    <p>Finally, note that if you are defining contexts explicitly in server.xml,
398
    you should probably turn off automatic application deployment.  Otherwise,
422
    you should probably turn off automatic application deployment or specify
399
    the web applications will each be deployed twice, and that may cause
423
    <code>deployIgnorePaths</code> carefully. Otherwise, the web applications
400
    problems for the applications.
424
    will each be deployed twice, and that may cause problems for the
401
    </p>
425
    applications.</p>
402
426
403
  </subsection>
427
  </subsection>
404
428

Return to bug 50205