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

(-)java/org/apache/catalina/core/StandardHost.java (+62 lines)
Lines 18-27 Link Here
18
18
19
19
20
import java.util.ArrayList;
20
import java.util.ArrayList;
21
import java.util.Arrays;
21
import java.util.List;
22
import java.util.List;
23
import java.util.ListIterator;
22
import java.util.Locale;
24
import java.util.Locale;
23
import java.util.Map;
25
import java.util.Map;
24
import java.util.WeakHashMap;
26
import java.util.WeakHashMap;
27
import java.util.regex.Pattern;
25
28
26
import org.apache.catalina.Container;
29
import org.apache.catalina.Container;
27
import org.apache.catalina.Context;
30
import org.apache.catalina.Context;
Lines 110-115 Link Here
110
113
111
114
112
    /**
115
    /**
116
     * The ignored deploy paths for this Host.
117
     */
118
    private String deployIgnorePaths = "";
119
120
121
    /**
122
     * The ignored deploy path Patterns for this Host.
123
     */
124
    private ArrayList<Pattern> deployIgnorePathPatterns = new ArrayList<Pattern>();
125
126
127
    /**
113
     * The deploy on startup flag for this Host.
128
     * The deploy on startup flag for this Host.
114
     */
129
     */
115
    private boolean deployOnStartup = true;
130
    private boolean deployOnStartup = true;
Lines 327-332 Link Here
327
342
328
343
329
    /**
344
    /**
345
     * Return the list of regular expressions for files/directories
346
     * excluded from automatic deployment.
347
     */
348
    public String getDeployIgnorePaths() {
349
350
        return (this.deployIgnorePaths);
351
352
    }
353
354
355
    /**
356
     * Set the list of regular expressions for files/directories
357
     * excluded from automatic deployment.
358
     *
359
     * @param ignorePaths A comma-separated list of regular
360
     *        expression strings.
361
     */
362
    public void setDeployIgnorePaths(String ignorePaths) {
363
364
        String oldDeployIgnorePaths = this.deployIgnorePaths;
365
        List<String> newPaths = Arrays.asList(ignorePaths.split("\\s*,\\s*"));
366
        ArrayList<Pattern> newPatterns = new ArrayList<Pattern>(newPaths.size());
367
368
        for (ListIterator<String> i = newPaths.listIterator(); i.hasNext(); ) {
369
            newPatterns.add(Pattern.compile(i.next()));
370
        }
371
372
        this.deployIgnorePaths = ignorePaths;
373
        this.deployIgnorePathPatterns = newPatterns;
374
        support.firePropertyChange("deployIgnorePaths", oldDeployIgnorePaths,
375
                                   this.deployIgnorePaths);
376
377
    }
378
379
380
    /**
381
     * Return the list of Patterns for files/directories excluded from
382
     * automatic deployment.
383
     */
384
    public ArrayList<Pattern> getDeployIgnorePathPatterns() {
385
386
        return (this.deployIgnorePathPatterns);
387
388
    }
389
390
391
    /**
330
     * Return the value of the deploy on startup flag.  If true, it indicates 
392
     * Return the value of the deploy on startup flag.  If true, it indicates 
331
     * that this host's child webapps should be discovered and automatically 
393
     * that this host's child webapps should be discovered and automatically 
332
     * deployed at startup time.
394
     * deployed at startup time.
(-)java/org/apache/catalina/core/mbeans-descriptors.xml (+4 lines)
Lines 1160-1165 Link Here
1160
               description="Should we create directories upon startup for appBase and xmlBase? "
1160
               description="Should we create directories upon startup for appBase and xmlBase? "
1161
               type="boolean"/>
1161
               type="boolean"/>
1162
      
1162
      
1163
    <attribute name="deployIgnorePaths"
1164
               description="Paths within appBase ignored for deployment"
1165
               type="java.lang.String"/>
1166
    
1163
    <attribute name="deployOnStartup"
1167
    <attribute name="deployOnStartup"
1164
               description="The deploy on startup flag for this Host"
1168
               description="The deploy on startup flag for this Host"
1165
               type="boolean"/>
1169
               type="boolean"/>
(-)java/org/apache/catalina/startup/HostConfig.java (-2 / +53 lines)
Lines 28-40 Link Here
28
import java.io.OutputStream;
28
import java.io.OutputStream;
29
import java.net.URL;
29
import java.net.URL;
30
import java.util.ArrayList;
30
import java.util.ArrayList;
31
import java.util.Arrays;
31
import java.util.HashMap;
32
import java.util.HashMap;
32
import java.util.HashSet;
33
import java.util.HashSet;
33
import java.util.LinkedHashMap;
34
import java.util.LinkedHashMap;
35
import java.util.ListIterator;
34
import java.util.Locale;
36
import java.util.Locale;
35
import java.util.Set;
37
import java.util.Set;
36
import java.util.jar.JarEntry;
38
import java.util.jar.JarEntry;
37
import java.util.jar.JarFile;
39
import java.util.jar.JarFile;
40
import java.util.regex.Pattern;
38
41
39
import javax.management.ObjectName;
42
import javax.management.ObjectName;
40
43
Lines 460-476 Link Here
460
463
461
        File appBase = appBase();
464
        File appBase = appBase();
462
        File configBase = configBase();
465
        File configBase = configBase();
466
        String[] fileList = validAppPaths(appBase.list());
463
        // Deploy XML descriptors from configBase
467
        // Deploy XML descriptors from configBase
464
        deployDescriptors(configBase, configBase.list());
468
        deployDescriptors(configBase, configBase.list());
465
        // Deploy WARs, and loop if additional descriptors are found
469
        // Deploy WARs, and loop if additional descriptors are found
466
        deployWARs(appBase, appBase.list());
470
        deployWARs(appBase, fileList);
467
        // Deploy expanded folders
471
        // Deploy expanded folders
468
        deployDirectories(appBase, appBase.list());
472
        deployDirectories(appBase, fileList);
469
        
473
        
470
    }
474
    }
471
475
472
476
473
    /**
477
    /**
478
     * Return the provided array of paths after removing those matching regular
479
     * expressions configured via the Host's deployIgnorePaths.
480
     *
481
     * @param paths The file paths to be checked, presumably those within
482
     *              appBase.
483
     * @return A String array containing the path list after excluding ignored
484
     *         paths.
485
     */
486
    protected String[] validAppPaths(String[] paths) {
487
488
        if (!(host instanceof StandardHost)) {
489
            return paths;
490
        }
491
492
        ArrayList<Pattern> ignorePatterns = ((StandardHost) host).getDeployIgnorePathPatterns();
493
494
        if ((ignorePatterns == null) || (ignorePatterns.size() == 0)) {
495
            return paths;
496
        }
497
498
        ArrayList<String> goodPaths = new ArrayList<String>(Arrays.asList(paths));
499
500
        for (ListIterator<String> i = goodPaths.listIterator(); i.hasNext(); ) {
501
            String path = i.next();
502
503
            for (ListIterator<Pattern> j = ignorePatterns.listIterator(); j.hasNext(); ) {
504
                Pattern ignorePattern = j.next();
505
506
                if (ignorePattern.matcher(path).matches()) {
507
                    if(log.isDebugEnabled()) {
508
                        log.debug("Ignoring application path \""
509
                                + path + "\" (matches pattern \""
510
                                + ignorePattern.pattern() + "\").");
511
                    }
512
513
                    i.remove();
514
                    break;
515
                }
516
            }
517
        }
518
519
        return goodPaths.toArray(new String[0]);
520
521
    }
522
523
524
    /**
474
     * Deploy applications for any directories or WAR files that are found
525
     * Deploy applications for any directories or WAR files that are found
475
     * in our "application root" directory.
526
     * in our "application root" directory.
476
     */
527
     */
(-)webapps/docs/config/host.xml (-19 / +43 lines)
Lines 189-194 Link Here
189
        is <code>false</code>, this attribute will have no effect.</p>
189
        is <code>false</code>, this attribute will have no effect.</p>
190
      </attribute>
190
      </attribute>
191
191
192
      <attribute name="deployIgnorePaths" required="false">
193
        <p>A comma-separated list of regular expressions of paths to
194
        <em>ignore</em> for <code>autoDeploy</code> and
195
        <code>deployOnStartup</code>. This allows you to keep your configuration
196
        in a version control system, for example, and not deploy a .svn or CVS
197
        folder that happens to be in <code>appBase</code>.</p>
198
        <p>These regular expressions are relative to <code>appBase</code>. They
199
        are also <em>anchored</em>, meaning the match is performed against the
200
        entire file/directory name. So, <code>foo</code> matches only a file or
201
        directory named <code>foo</code> but not <code>foo.war</code>,
202
        <code>foobar</code>, or <code>myfooapp</code>. To match anything with
203
        &quot;foo&quot;, you would use something like <code>.*foo.*</code>.</p>
204
        <p>From a performance standpoint, a single regular expression using
205
        alternation will be more efficient than separate regular expressions.
206
        For example, <code>deployIgnorePaths</code> set to
207
        <code>foo\.war|bar</code> has the same effect as
208
        <code>foo\.war,bar</code>, but the former is more efficient.</p>
209
        <p>See <a href="#Automatic Application Deployment">Automatic Application
210
        Deployment</a> for more information.</p>
211
      </attribute>
212
192
      <attribute name="deployXML" required="false">
213
      <attribute name="deployXML" required="false">
193
        <p>Set to <code>false</code> if you want to disable parsing the context
214
        <p>Set to <code>false</code> if you want to disable parsing the context
194
        XML descriptor embedded inside the application (located at
215
        XML descriptor embedded inside the application (located at
Lines 337-350 Link Here
337
        <code>ROOT.xml</code>.</li>
358
        <code>ROOT.xml</code>.</li>
338
    <li>Any web application archive file within the Host's <code>appBase</code>
359
    <li>Any web application archive file within the Host's <code>appBase</code>
339
        directory that has not already been deployed as a result of a context
360
        directory that has not already been deployed as a result of a context
340
        XML descriptor and does not have a corresponding directory of the same
361
        XML descriptor, does not have a corresponding directory of the same
341
        name (without the ".war" extension) will be deployed next. The context
362
        name (without the ".war" extension), and is not excluded by
342
        path used will be a slash character ("/") followed by the web
363
        <code>deployIgnorePaths</code> will be deployed next. The context path
343
        application archive name less the ".war" extension. The one exception to
364
        used will be a slash character ("/") followed by the web application
344
        this rule is that a web application archive named "ROOT.war" will be
365
        archive name less the ".war" extension. The one exception to this rule
345
        deployed with a context path of <code>/</code>. Multi-level contexts may
366
        is that a web application archive named "ROOT.war" will be deployed with
346
        be defined by using #, e.g. use a WAR named <code>foo#bar.war</code> for
367
        a context path of <code>/</code>. Multi-level contexts may be defined by
347
        a context path of <code>/foo/bar</code>.<br/>
368
        using #, e.g. use a WAR named <code>foo#bar.war</code> for a context
369
        path of <code>/foo/bar</code>.<br/>
348
        If the <code>unpackWARs</code> attribute is <code>true</code>, the web
370
        If the <code>unpackWARs</code> attribute is <code>true</code>, the web
349
        application archive file will be expanded to a directory of the same
371
        application archive file will be expanded to a directory of the same
350
        name (without the ".war" extension".<br/>
372
        name (without the ".war" extension".<br/>
Lines 363-373 Link Here
363
        </li>
385
        </li>
364
    <li>Finally, any sub-directory within the Host's <code>appBase</code> that
386
    <li>Finally, any sub-directory within the Host's <code>appBase</code> that
365
        has not already been deployed as a result of a context XML descriptor
387
        has not already been deployed as a result of a context XML descriptor
366
        will be deployed. The context path used will be a slash character
388
        and is not excluded by <code>deployIgnorePaths</code> will be deployed.
367
        ("/") followed by the directory name, unless the directory name is ROOT,
389
        The context path used will be a slash character ("/") followed by the
368
        in which case the context path will <code>/</code>. Multi-level contexts
390
        directory name, unless the directory name is ROOT, in which case the
369
        may be defined by using #, e.g. use a directory named
391
        context path will <code>/</code>. Multi-level contexts may be defined by
370
        <code>foo#bar</code> for a context path of <code>/foo/bar</code>.<br/>
392
        using #, e.g. use a directory named <code>foo#bar</code> for a context
393
        path of <code>/foo/bar</code>.<br/>
371
        If <code>copyXml</code> is <code>true</code> (it is <code>false</code>
394
        If <code>copyXml</code> is <code>true</code> (it is <code>false</code>
372
        by default), any directory within the Hosts's <code>appBase</code>
395
        by default), any directory within the Hosts's <code>appBase</code>
373
        directory that does not have a corresponding context XML descriptor in
396
        directory that does not have a corresponding context XML descriptor in
Lines 420-434 Link Here
420
443
421
    <p>When using automatic deployment, the <code>docBase</code> defined by
444
    <p>When using automatic deployment, the <code>docBase</code> defined by
422
    an XML <a href="context.html">Context</a> file should be outside of the
445
    an XML <a href="context.html">Context</a> file should be outside of the
423
    <code>appBase</code> directory. If this is not the case difficulties
446
    <code>appBase</code> directory. If this is not the case, difficulties
424
    may be experienced deploying the web application or the application may
447
    may be experienced deploying the web application or the application may
425
    be deployed twice.</p>
448
    be deployed twice. The <code>deployIgnorePaths</code> attribute can be used
449
    to avoid this situation.</p>
426
450
427
    <p>Finally, note that if you are defining contexts explicitly in server.xml,
451
    <p>Finally, note that if you are defining contexts explicitly in server.xml,
428
    you should probably turn off automatic application deployment.  Otherwise,
452
    you should probably turn off automatic application deployment or specify
429
    the web applications will each be deployed twice, and that may cause
453
    <code>deployIgnorePaths</code> carefully. Otherwise, the web applications
430
    problems for the applications.
454
    will each be deployed twice, and that may cause problems for the
431
    </p>
455
    applications.</p>
432
456
433
  </subsection>
457
  </subsection>
434
458

Return to bug 50205