Package org.openrewrite.docker.trait
Class DockerCopyFrom.Matcher
java.lang.Object
org.openrewrite.trait.SimpleTraitMatcher<DockerCopyFrom>
org.openrewrite.docker.trait.DockerCopyFrom.Matcher
- All Implemented Interfaces:
org.openrewrite.trait.TraitMatcher<DockerCopyFrom>
- Enclosing class:
DockerCopyFrom
public static class DockerCopyFrom.Matcher
extends org.openrewrite.trait.SimpleTraitMatcher<DockerCopyFrom>
Matcher for
DockerCopyFrom 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<DockerCopyFrom, P> visitor) Only match images with digests matching this glob pattern.Exclude--fromvalues that reference an earlier build stage, matching only external image references.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 images with tags matching this glob pattern.protected @Nullable DockerCopyFromtest(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. -
tag
Only match images with tags matching this glob pattern. -
digest
Only match images with digests matching this glob pattern. -
excludeStageReferences
Exclude--fromvalues that reference an earlier build stage, matching only external image references. -
test
- Specified by:
testin classorg.openrewrite.trait.SimpleTraitMatcher<DockerCopyFrom>
-
asVisitor
public <P> org.openrewrite.TreeVisitor<? extends org.openrewrite.Tree,P> asVisitor(org.openrewrite.trait.VisitFunction2<DockerCopyFrom, P> visitor) - Specified by:
asVisitorin interfaceorg.openrewrite.trait.TraitMatcher<DockerCopyFrom>- Overrides:
asVisitorin classorg.openrewrite.trait.SimpleTraitMatcher<DockerCopyFrom>
-
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
-