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 Java 11 requirement brought in by misk #13

Merged
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
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
Loading