Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop contextSensitive() from JavaTemplate to fix compilation #203

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/main/java/org/openrewrite/java/logging/LoggingFramework.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,28 @@ public JavaTemplate getErrorTemplate(String message, ExecutionContext ctx) {
case SLF4J:
return JavaTemplate
.builder("#{any(org.slf4j.Logger)}.error(" + message + ", #{any(java.lang.Throwable)})")
.contextSensitive()
.javaParser(JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "slf4j-api-2.1"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "slf4j-api-2.1"))
.build();
case Log4J1:
return JavaTemplate
.builder("#{any(org.apache.log4j.Category)}.error(" + message + ", #{any(java.lang.Throwable)})")
.contextSensitive()
.javaParser(JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "log4j-1.2"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "log4j-1.2"))
.build();

case Log4J2:
return JavaTemplate
.builder("#{any(org.apache.logging.log4j.Logger)}.error(" + message + ", #{any(java.lang.Throwable)})")
.contextSensitive()
.javaParser(JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "log4j-api-2.23"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "log4j-api-2.23"))
.build();
case COMMONS:
return JavaTemplate
.builder("#{any(org.apache.commons.logging.Log)}.error(" + message + ", #{any(java.lang.Throwable)})")
.contextSensitive()
.javaParser(JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "commons-logging-1.3"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "commons-logging-1.3"))
.build();
case JUL:
default:
return JavaTemplate
.builder("#{any(java.util.logging.Logger)}.log(Level.SEVERE, " + message + ", #{any(java.lang.Throwable)})")
.contextSensitive()
.imports("java.util.logging.Level")
.build();
}
Expand Down
21 changes: 7 additions & 14 deletions src/main/java/org/openrewrite/java/logging/SystemErrToLogging.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,31 +193,24 @@ public JavaTemplate getErrorTemplateNoException(ExecutionContext ctx) {
switch (framework) {
case SLF4J:
return JavaTemplate
.builder("#{any(org.slf4j.Logger)}.error(#{any(String)})")
.contextSensitive()
.javaParser(JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "slf4j-api-2.1"))
.builder("#{any(org.slf4j.Logger)}.error(#{any(String)});")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "slf4j-api-2.1"))
.build();
case Log4J1:
return JavaTemplate
.builder("#{any(org.apache.log4j.Category)}.error(#{any(String)})")
.contextSensitive()
.javaParser(JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "log4j-1.2"))
.builder("#{any(org.apache.log4j.Category)}.error(#{any(String)});")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "log4j-1.2"))
.build();

case Log4J2:
return JavaTemplate
.builder("#{any(org.apache.logging.log4j.Logger)}.error(#{any(String)})")
.contextSensitive()
.javaParser(JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "log4j-api-2.23"))
.builder("#{any(org.apache.logging.log4j.Logger)}.error(#{any(String)});")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "log4j-api-2.23"))
.build();
case JUL:
default:
return JavaTemplate
.builder("#{any(java.util.logging.Logger)}.log(Level.SEVERE, #{any(String)})")
.contextSensitive()
.builder("#{any(java.util.logging.Logger)}.log(Level.SEVERE, #{any(String)});")
.imports("java.util.logging.Level")
.build();
}
Expand Down
Loading