Class BaseHome


  • public class BaseHome
    extends java.lang.Object
    File access for ${jetty.home}, ${jetty.base}, directories.

    By default, both ${jetty.home} and ${jetty.base} are the same directory, but they can point at different directories.

    The ${jetty.home} directory is where the main Jetty binaries and default configuration is housed.

    The ${jetty.base} directory is where the execution specific configuration and webapps are obtained from.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  BaseHome.SearchDir  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String JETTY_BASE  
      static java.lang.String JETTY_HOME  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getBase()  
      java.nio.file.Path getBasePath()  
      java.nio.file.Path getBasePath​(java.lang.String path)
      Create a Path reference to some content in "${jetty.base}"
      ConfigSources getConfigSources()  
      java.lang.String getHome()  
      java.nio.file.Path getHomePath()  
      java.nio.file.Path getPath​(java.lang.String path)
      Get a specific path reference.
      java.util.List<java.nio.file.Path> getPaths​(java.lang.String pattern)
      Get a List of Paths from a provided pattern.
      java.util.List<java.nio.file.Path> getPaths​(java.nio.file.Path dir, int searchDepth, java.lang.String pattern)
      Search specified Path with pattern and return hits
      boolean isBaseDifferent()  
      java.lang.String toShortForm​(java.io.File path)
      Convenience method for toShortForm(file.toPath())
      java.lang.String toShortForm​(java.lang.String path)
      Replace/Shorten arbitrary path with property strings "${jetty.home}" or "${jetty.base}" where appropriate.
      java.lang.String toShortForm​(java.nio.file.Path path)
      Replace/Shorten arbitrary path with property strings "${jetty.home}" or "${jetty.base}" where appropriate.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BaseHome

        public BaseHome()
                 throws java.io.IOException
        Throws:
        java.io.IOException
      • BaseHome

        public BaseHome​(java.lang.String[] cmdLine)
                 throws java.io.IOException
        Throws:
        java.io.IOException
      • BaseHome

        public BaseHome​(CommandLineConfigSource cmdLineSource)
                 throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • getBase

        public java.lang.String getBase()
      • getBasePath

        public java.nio.file.Path getBasePath()
      • getBasePath

        public java.nio.file.Path getBasePath​(java.lang.String path)
        Create a Path reference to some content in "${jetty.base}"
        Parameters:
        path - the path to reference
        Returns:
        the file reference
      • getHome

        public java.lang.String getHome()
      • getHomePath

        public java.nio.file.Path getHomePath()
      • getPath

        public java.nio.file.Path getPath​(java.lang.String path)
        Get a specific path reference.

        Path references are searched based on the config source search order.

        1. If provided path is an absolute reference., and exists, return that reference
        2. If exists relative to ${jetty.base}, return that reference
        3. If exists relative to and include-jetty-dir locations, return that reference
        4. If exists relative to ${jetty.home}, return that reference
        5. Return standard Path reference obtained from FileSystem.getPath(String, String...) (no exists check performed)
        Parameters:
        path - the path to get.
        Returns:
        the path reference.
      • getPaths

        public java.util.List<java.nio.file.Path> getPaths​(java.nio.file.Path dir,
                                                           int searchDepth,
                                                           java.lang.String pattern)
                                                    throws java.io.IOException
        Search specified Path with pattern and return hits
        Parameters:
        dir - the path to a directory to start search from
        searchDepth - the number of directories deep to perform the search
        pattern - the raw pattern to use for the search (must be relative)
        Returns:
        the list of Paths found
        Throws:
        java.io.IOException - if unable to search the path
      • getPaths

        public java.util.List<java.nio.file.Path> getPaths​(java.lang.String pattern)
                                                    throws java.io.IOException
        Get a List of Paths from a provided pattern.

        Resolution Steps:

        1. If the pattern starts with "regex:" or "glob:" then a standard PathMatcher is built using FileSystem.getPathMatcher(String) as a file search.
        2. If pattern starts with a known filesystem root (using information from FileSystem.getRootDirectories()) then this is assumed to be a absolute file system pattern.
        3. All other patterns are treated as relative to BaseHome information:
          1. Search ${jetty.home} first
          2. Search ${jetty.base} for overrides

        Pattern examples:

        lib/logging/*.jar
        Relative pattern, not recursive, search ${jetty.home} then ${jetty.base} for lib/logging/*.jar content
        lib/**/*-dev.jar
        Relative pattern, recursive search ${jetty.home} then ${jetty.base} for files under lib ending in -dev.jar
        etc/jetty.xml
        Relative pattern, no glob, search for ${jetty.home}/etc/jetty.xml then ${jetty.base}/etc/jetty.xml
        glob:/opt/app/common/*-corp.jar
        PathMapper pattern, glob, search /opt/app/common/ for *-corp.jar

        Notes:

        • FileSystem case sensitivity is implementation specific (eg: linux is case-sensitive, windows is case-insensitive).
          See FileSystem.getPathMatcher(String) for more details
        • Pattern slashes are implementation neutral (use '/' always and you'll be fine)
        • Recursive searching is limited to 30 levels deep (not configurable)
        • File System loops are detected and skipped
        Parameters:
        pattern - the pattern to search.
        Returns:
        the collection of paths found
        Throws:
        java.io.IOException - if error during search operation
      • isBaseDifferent

        public boolean isBaseDifferent()
      • toShortForm

        public java.lang.String toShortForm​(java.io.File path)
        Convenience method for toShortForm(file.toPath())
        Parameters:
        path - the path to shorten
        Returns:
        the short form of the path as a String
      • toShortForm

        public java.lang.String toShortForm​(java.nio.file.Path path)
        Replace/Shorten arbitrary path with property strings "${jetty.home}" or "${jetty.base}" where appropriate.
        Parameters:
        path - the path to shorten
        Returns:
        the potentially shortened path
      • toShortForm

        public java.lang.String toShortForm​(java.lang.String path)
        Replace/Shorten arbitrary path with property strings "${jetty.home}" or "${jetty.base}" where appropriate.
        Parameters:
        path - the path to shorten
        Returns:
        the potentially shortened path