Skip to content

Commit a90a9c2

Browse files
author
kaiqianyang
committed
upgrade to be compatible
1 parent d96e462 commit a90a9c2

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

src/main/java/com/azure/spring/migration/openrewrite/xml/AddConsoleCommentInLog4j.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.openrewrite.ExecutionContext;
2525
import org.openrewrite.HasSourcePath;
2626
import org.openrewrite.Option;
27+
import org.openrewrite.Preconditions;
2728
import org.openrewrite.Recipe;
2829
import org.openrewrite.TreeVisitor;
2930
import org.openrewrite.internal.lang.NonNull;
@@ -63,11 +64,6 @@ public class AddConsoleCommentInLog4j extends Recipe {
6364
return "Adds a comment in a `XML` tag of matched attribute.";
6465
}
6566

66-
@Override
67-
protected TreeVisitor<?, ExecutionContext> getSingleSourceApplicableTest() {
68-
return new HasSourcePath<>(fileMatcher);
69-
}
70-
7167
public boolean checkLog4j1HasConsole(Xml.Tag tag) {
7268
AttributeToFind log4j1KeyAttribute = ATTRIBUTE_MAP.get("log4j1");
7369
return !XmlUtil.searchChildTag(tag, APPENDER_TAG_NAME) || XmlUtil.searchChildAttribute(tag, APPENDER_TAG_NAME, log4j1KeyAttribute.attributeName, log4j1KeyAttribute.attributeValueKeyword);
@@ -81,7 +77,7 @@ public boolean checkLog4j2HasConsole(Xml.Tag tag) {
8177

8278
@Override
8379
public @NonNull TreeVisitor<?, ExecutionContext> getVisitor() {
84-
return new XmlVisitor<ExecutionContext>() {
80+
return Preconditions.check(fileMatcher != null ? new HasSourcePath<>(fileMatcher) : TreeVisitor.noop(), new XmlVisitor<ExecutionContext>() {
8581
final CaseInsensitiveXPathMatcher log4j2AppendersTagMatcher = new CaseInsensitiveXPathMatcher(LOG4J2_APPENDERS_XPATH);
8682
final CaseInsensitiveXPathMatcher log4jConfigurationTagMatcher = new CaseInsensitiveXPathMatcher(LOG4J_CONFIGURATION_XPATH);
8783

@@ -99,6 +95,6 @@ public boolean checkLog4j2HasConsole(Xml.Tag tag) {
9995
}
10096
return t;
10197
}
102-
};
98+
});
10399
}
104100
}

src/main/java/com/azure/spring/migration/openrewrite/xml/AddConsoleCommentInLogback.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.openrewrite.ExecutionContext;
2222
import org.openrewrite.HasSourcePath;
2323
import org.openrewrite.Option;
24+
import org.openrewrite.Preconditions;
2425
import org.openrewrite.Recipe;
2526
import org.openrewrite.TreeVisitor;
2627
import org.openrewrite.internal.lang.NonNull;
@@ -55,19 +56,14 @@ public class AddConsoleCommentInLogback extends Recipe {
5556
return "Adds a comment in a `XML` tag of matched attribute.";
5657
}
5758

58-
@Override
59-
protected @NonNull TreeVisitor<?, ExecutionContext> getSingleSourceApplicableTest() {
60-
return new HasSourcePath<>(fileMatcher);
61-
}
62-
6359
private boolean checkLogbackHasConsole(Xml.Tag tag) {
6460
return !XmlUtil.searchChildTag(tag, APPENDER_TAG_NAME) || XmlUtil.searchChildAttribute(tag, APPENDER_TAG_NAME, KEY_ATTRIBUTE.attributeName,
6561
KEY_ATTRIBUTE.attributeValueKeyword);
6662
}
6763

6864
@Override
6965
public @NonNull TreeVisitor<?, ExecutionContext> getVisitor() {
70-
return new XmlVisitor<ExecutionContext>() {
66+
return Preconditions.check(fileMatcher != null ? new HasSourcePath<>(fileMatcher) : TreeVisitor.noop(), new XmlVisitor<ExecutionContext>() {
7167
final CaseInsensitiveXPathMatcher configurationTagMatcher = new CaseInsensitiveXPathMatcher(CONFIGURATION_XPATH);
7268

7369
@Override
@@ -80,6 +76,6 @@ private boolean checkLogbackHasConsole(Xml.Tag tag) {
8076
}
8177
return t;
8278
}
83-
};
79+
});
8480
}
8581
}

0 commit comments

Comments
 (0)