Skip to content

Commit

Permalink
Drop Java 11 requirement brought in my misk (#13)
Browse files Browse the repository at this point in the history
- Fixes #12
  • Loading branch information
timtebeek authored Aug 12, 2024
1 parent 3688b88 commit cc5a723
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 23 deletions.
6 changes: 0 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ plugins {
group = "org.openrewrite.recipe"
description = "Micrometer Migration"

tasks.getByName<JavaCompile>("compileJava") {
// minimum required for misk use in refaster-style templates
options.release.set(11)
}

val rewriteVersion = rewriteRecipe.rewriteVersion.get()
val micrometerVersion = "1.12.+"
dependencies {
Expand All @@ -27,7 +22,6 @@ dependencies {

compileOnly("org.jetbrains.kotlin:kotlin-stdlib-common:1.9.0")
compileOnly("org.jetbrains.kotlin:kotlin-reflect:1.9.0")
compileOnly("com.squareup.misk:misk-metrics:2023.09.27.194750-c3aa143")
compileOnly("io.micrometer:micrometer-core:${micrometerVersion}")
compileOnly("io.prometheus:simpleclient:latest.release")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
MethodMatcher counter = new MethodMatcher("com.codahale.metrics.MetricRegistry counter(..)");
MethodMatcher gauge = new MethodMatcher("com.codahale.metrics.MetricRegistry gauge(..)");

return new JavaIsoVisitor<>() {
return new JavaIsoVisitor<ExecutionContext>() {
@Override
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
if (counter.matches(method) || gauge.matches(method)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ public List<Recipe> getRecipeList() {

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return Preconditions.check(new UsesType<>("misk.metrics.v2.Metrics", true), new JavaIsoVisitor<>() {
return Preconditions.check(new UsesType<>("misk.metrics.v2.Metrics", true), new JavaIsoVisitor<ExecutionContext>() {
final MethodMatcher miskCounter = new MethodMatcher("misk.metrics.v2.Metrics counter(..)");
final MethodMatcher listOf = new MethodMatcher("kotlin.collections.CollectionsKt listOf()", true);

@Override
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,19 @@
*/
package org.openrewrite.micrometer.misk;

import misk.metrics.v2.Metrics;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.TypeUtils;

import java.util.Arrays;
import java.util.List;

import static kotlin.collections.CollectionsKt.listOf;
import static org.openrewrite.java.template.Semantics.expression;

public class NoExplicitEmptyLabelList extends Recipe {

@Override
Expand All @@ -46,15 +43,20 @@ public String getDescription() {
@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {

return new JavaIsoVisitor<>() {
return new JavaIsoVisitor<ExecutionContext>() {
final List<JavaTemplate> hasEmptyLabel = Arrays.asList(
expression(this, "emptyLabelCounter",
(Metrics m, String s, String s1) -> m.counter(s, s1, listOf())).build(),
expression(this, "emptyLabelGauge",
(Metrics m, String s, String s1) -> m.gauge(s, s1, listOf())).build(),
expression(this, "emptyLabelPeakGauge",
(Metrics m, String s, String s1) -> m.peakGauge(s, s1, listOf())).build()
);
JavaTemplate.builder("#{m:any(misk.metrics.v2.Metrics)}.counter(#{s:any(java.lang.String)}, #{s1:any(java.lang.String)}, listOf())")
.staticImports("kotlin.collections.CollectionsKt.listOf")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build(),
JavaTemplate.builder("#{m:any(misk.metrics.v2.Metrics)}.gauge(#{s:any(java.lang.String)}, #{s1:any(java.lang.String)}, listOf())")
.staticImports("kotlin.collections.CollectionsKt.listOf")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build(),
JavaTemplate.builder("#{m:any(misk.metrics.v2.Metrics)}.peakGauge(#{s:any(java.lang.String)}, #{s1:any(java.lang.String)}, listOf())")
.staticImports("kotlin.collections.CollectionsKt.listOf")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build());

@Override
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void emptyLabel() {
"""
import misk.metrics.v2.Metrics;
import static kotlin.collections.CollectionsKt.listOf;
class Test {
void test(Metrics metrics) {
metrics.counter("counter", "description", listOf());
Expand All @@ -55,7 +55,7 @@ void test(Metrics metrics) {
"""
import misk.metrics.v2.Metrics;
import static kotlin.collections.CollectionsKt.listOf;
class Test {
void test(Metrics metrics) {
metrics.counter("counter", "description");
Expand Down

0 comments on commit cc5a723

Please sign in to comment.