Package org.openrewrite.docker.trait
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
Matcher for DockerImage traits with builder-style configuration.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<P> org.openrewrite.TreeVisitor<? extends org.openrewrite.Tree, P> asVisitor(org.openrewrite.trait.VisitFunction2<DockerFrom, P> visitor) Only match images with digests matching this glob pattern.Exclude the special "scratch" base image from matches.protected @Nullable StringextractText(@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).protected StringExtracts text from a Docker argument, replacing environment variables with wildcards for glob matching purposes.protected @Nullable StringextractTextWithVariables(@Nullable Docker.Argument arg) Extracts text from a Docker argument, including environment variable references in their original form (e.g., ${VAR} or $VAR).protected @Nullable Docker.Literal.QuoteStyleGets the quote style from a Docker argument, if any literal content is quoted.protected booleanhasEnvironmentVariables(@Nullable Docker.Argument arg) Checks if a Docker argument contains any environment variables.Only match images with names matching this glob pattern.protected booleanmatchesBidirectional(String text, String pattern, boolean hasEnvVars) Performs bidirectional glob matching when environment variables are present.Only match unpinned images (no tag, "latest" tag, or no digest).Only match images with platform flags matching this glob pattern.Only match images with tags matching this glob pattern.protected @Nullable DockerFromtest(org.openrewrite.Cursor cursor) Methods inherited from class org.openrewrite.trait.SimpleTraitMatcher
get, higher, lowerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.openrewrite.trait.TraitMatcher
asVisitor, get, lower, require, require
-
Constructor Details
-
Matcher
public Matcher()
-
-
Method Details
-
imageName
Only match images with names matching this glob pattern.- Parameters:
pattern- The glob pattern for image name- Returns:
- this matcher for chaining
-
tag
Only match images with tags matching this glob pattern.- Parameters:
pattern- The glob pattern for tag- Returns:
- this matcher for chaining
-
digest
Only match images with digests matching this glob pattern.- Parameters:
pattern- The glob pattern for digest- Returns:
- this matcher for chaining
-
platform
Only match images with platform flags matching this glob pattern.- Parameters:
pattern- The glob pattern for platform- Returns:
- this matcher for chaining
-
excludeScratch
Exclude the special "scratch" base image from matches.- Returns:
- this matcher for chaining
-
onlyUnpinned
Only match unpinned images (no tag, "latest" tag, or no digest).- Returns:
- this matcher for chaining
-
test
- Specified by:
testin classorg.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:
asVisitorin interfaceorg.openrewrite.trait.TraitMatcher<DockerFrom>- Overrides:
asVisitorin classorg.openrewrite.trait.SimpleTraitMatcher<DockerFrom>
-
extractTextForMatching
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
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 againsthasEnvVars- Whether the original text contained environment variables- Returns:
- true if there's a match in either direction
-
getQuoteStyle
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
-