Skip to content

Commit

Permalink
Drop contextSensitive() from JavaTemplate to fix compilation (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek authored Dec 19, 2024
1 parent f49d9e1 commit 8dc20c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
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

0 comments on commit 8dc20c7

Please sign in to comment.