Class NamePatternUtil


  • public class NamePatternUtil
    extends Object
    Helper functions for pattern matching for image and container names.
    • Constructor Detail

      • NamePatternUtil

        public NamePatternUtil()
    • Method Detail

      • convertNamePattern

        public static String convertNamePattern​(String pattern)
        Accepts an Ant-ish or regular expression pattern and compiles to a regular expression. This is similar to SelectorUtils in the Maven codebase, but there the code uses the platform File.separator, while here we always want to work with forward slashes. Also, for a more natural fit with repository tags, both * and ** should stop at the colon that precedes the tag. Like SelectorUtils, wrapping a pattern in %regex[pattern] will create a regex from the pattern provided without translation. Otherwise, or if wrapped in %ant[pattern], then a regular expression will be created that is anchored at beginning and end, converts ? to [^/:], * to ([^/:]|:(?=.*:)) and ** to ([^:]|:(?=.*:))*. If ** is followed by /, the / is converted to a negative lookbehind for anything apart from a slash.
        Returns:
        a regular expression pattern created from the input pattern
      • convertNamePatternList

        public static String convertNamePatternList​(String patternList)
        Take a string that represents a list of patterns, possibly a mixture of regular expressions and Ant-style patterns, and return a single regular expression that matches any of the alternatives. To allow users to target some parts of the filter list to some fields on the object to which the pattern is ultimately applied, it is possible to prefix patterns in the list with fieldName=pattern, and then the pattern can be excluded from use on unrelated fields.
        Parameters:
        patternList - the pattern list specification to convert
        Returns:
        the combined pattern, or null if there is are no patterns for the field.
        Throws:
        PatternSyntaxException - if any of the individual patterns fails to compile as a regular expression.
      • convertNamePatternList

        public static String convertNamePatternList​(String patternList,
                                                    String fieldName,
                                                    boolean includeUnnamed)
        Take a string that represents a list of patterns, possibly a mixture of regular expressions and Ant-style patterns, and return a single regular expression that matches any of the alternatives. To allow users to target some parts of the filter list to some fields on the object to which the pattern is ultimately applied, it is possible to prefix patterns in the list with fieldName=pattern, and then the pattern can be excluded from use on unrelated fields.
        Parameters:
        patternList - the pattern list specification to convert
        fieldName - the field name for which patterns should be selected
        includeUnnamed - if true, include patterns that do not specify a field name
        Returns:
        the combined pattern, or null if there is are no patterns for the field.
        Throws:
        PatternSyntaxException - if any of the individual patterns fails to compile as a regular expression.