Class DockerFrom.Matcher

java.lang.Object
org.openrewrite.trait.SimpleTraitMatcher<DockerFrom>
org.openrewrite.docker.trait.DockerFrom.Matcher
All Implemented Interfaces:
org.openrewrite.trait.TraitMatcher<DockerFrom>
Enclosing class:
DockerFrom

public static class DockerFrom.Matcher extends org.openrewrite.trait.SimpleTraitMatcher<DockerFrom>
Matcher for DockerImage traits with builder-style configuration.
  • Constructor Details

    • Matcher

      public Matcher()
  • Method Details

    • imageName

      @Contract("_ -> this") public DockerFrom.Matcher imageName(String pattern)
      Only match images with names matching this glob pattern.
      Parameters:
      pattern - The glob pattern for image name
      Returns:
      this matcher for chaining
    • tag

      @Contract("_ -> this") public DockerFrom.Matcher tag(String pattern)
      Only match images with tags matching this glob pattern.
      Parameters:
      pattern - The glob pattern for tag
      Returns:
      this matcher for chaining
    • digest

      @Contract("_ -> this") public DockerFrom.Matcher digest(String pattern)
      Only match images with digests matching this glob pattern.
      Parameters:
      pattern - The glob pattern for digest
      Returns:
      this matcher for chaining
    • platform

      @Contract("_ -> this") public DockerFrom.Matcher platform(String pattern)
      Only match images with platform flags matching this glob pattern.
      Parameters:
      pattern - The glob pattern for platform
      Returns:
      this matcher for chaining
    • excludeScratch

      @Contract("-> this") public DockerFrom.Matcher excludeScratch()
      Exclude the special "scratch" base image from matches.
      Returns:
      this matcher for chaining
    • onlyUnpinned

      @Contract("-> this") public DockerFrom.Matcher onlyUnpinned()
      Only match unpinned images (no tag, "latest" tag, or no digest).
      Returns:
      this matcher for chaining
    • test

      protected @Nullable DockerFrom test(org.openrewrite.Cursor cursor)
      Specified by:
      test in class org.openrewrite.trait.SimpleTraitMatcher<DockerFrom>
    • asVisitor

      public <P> org.openrewrite.TreeVisitor<? extends org.openrewrite.Tree,P> asVisitor(org.openrewrite.trait.VisitFunction2<DockerFrom,P> visitor)
      Specified by:
      asVisitor in interface org.openrewrite.trait.TraitMatcher<DockerFrom>
      Overrides:
      asVisitor in class org.openrewrite.trait.SimpleTraitMatcher<DockerFrom>
    • extractTextForMatching

      protected String extractTextForMatching(Docker.Argument arg)
      Extracts text from a Docker argument, replacing environment variables with wildcards for glob matching purposes.
      Parameters:
      arg - The argument to extract text from
      Returns:
      Text with environment variables replaced by '*'
    • extractText

      @Contract(value="null -> null", pure=true) protected @Nullable String extractText(@Nullable Docker.Argument arg)
      Extracts text from a Docker argument, returning null if the argument contains any environment variables (since the actual value cannot be determined statically).
      Parameters:
      arg - The argument to extract text from, may be null
      Returns:
      The literal text content, or null if the argument is null or contains environment variables
    • extractTextWithVariables

      @Contract(value="null -> null; !null -> !null", pure=true) protected @Nullable String extractTextWithVariables(@Nullable Docker.Argument arg)
      Extracts text from a Docker argument, including environment variable references in their original form (e.g., ${VAR} or $VAR).
      Parameters:
      arg - The argument to extract text from, may be null
      Returns:
      The text content with environment variable references preserved, or null if arg is null
    • hasEnvironmentVariables

      @Contract(value="null -> false", pure=true) protected boolean hasEnvironmentVariables(@Nullable Docker.Argument arg)
      Checks if a Docker argument contains any environment variables.
      Parameters:
      arg - The argument to check, may be null
      Returns:
      true if the argument contains environment variables, false otherwise
    • matchesBidirectional

      protected boolean matchesBidirectional(String text, String pattern, boolean hasEnvVars)
      Performs bidirectional glob matching when environment variables are present. When the text contains wildcards (from env vars), we need to check if either the pattern matches the text OR the text (as a pattern) matches the pattern.
      Parameters:
      text - The text to match (may contain wildcards from env vars)
      pattern - The glob pattern to match against
      hasEnvVars - Whether the original text contained environment variables
      Returns:
      true if there's a match in either direction
    • getQuoteStyle

      protected @Nullable Docker.Literal.QuoteStyle getQuoteStyle(Docker.Argument arg)
      Gets the quote style from a Docker argument, if any literal content is quoted.
      Parameters:
      arg - The argument to check
      Returns:
      The quote style, or null if unquoted