← All recipes
Moderne licensed

Adds a TimeUnit argument to the matched method invocations

Recipe IDorg.openrewrite.apache.httpclient5.AddTimeUnitArgumentArtifactorg.openrewrite.recipe:rewrite-apache

In Apache Http Client 5.x migration, an extra TimeUnit argument is required in the timeout and duration methods. Previously in 4.x, all these methods were implicitly having the timeout or duration expressed in milliseconds, but in 5.x the unit of the timeout or duration is required. So, by default this recipe adds TimeUnit.MILLISECONDS, it is possible to specify this as a parameter. Since all affected methods of the Apache Http Client 5.x migration only have one integer/long argument, the recipe applies with matched method invocations of exactly one parameter.

Single recipeMSAL

Add to your build

Get a download tokenThis recipe is Moderne licensed, so the token must belong to a Moderne customer. It replaces YOUR_DOWNLOAD_TOKEN below.

~/.gradle/gradle.properties

codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN

build.gradle.kts

plugins {
    id("org.openrewrite.rewrite") version("latest.release")
}

rewrite {
    activeRecipe("org.openrewrite.apache.httpclient5.AddTimeUnitArgument")
}

repositories {
    mavenCentral()
    maven {
        url = uri("https://artifacts.codegenomeproject.org/maven")
        credentials {
            username = providers.gradleProperty("codeGenomeUsername").get()
            password = providers.gradleProperty("codeGenomeToken").get()
        }
    }
}

dependencies {
    rewrite("org.openrewrite.recipe:rewrite-apache:2.33.0")
}

Then run

./gradlew rewriteRun

This recipe has required options, which a build sets in a rewrite.yml recipe that you activate instead.

Usage

You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.apache.httpclient5.AddTimeUnitArgument --recipe-option "methodPattern=org.apache.http.client.config.RequestConfig.Builder setConnectionRequestTimeout(int)"

If the recipe isn’t available locally, install it with:

mod config recipes jar install org.openrewrite.recipe:rewrite-apache:RELEASE

Options

NameTypeDescription
methodPatternrequiredStringA method pattern that is used to find matching method invocations.
e.g. org.apache.http.client.config.RequestConfig.Builder setConnectionRequestTimeout(int)
timeUnitTimeUnitThe TimeUnit enum value we want to add to the method invocation. Defaults to MILLISECONDS.
e.g. MILLISECONDS

Data tables

Structured output this recipe can produce.

  • Source files that had resultsSource files that were modified by the recipe run.org.openrewrite.table.SourcesFileResults
  • Source files that had search resultsSearch results that were found during the recipe run.org.openrewrite.table.SearchResults
  • Source files that errored on a recipeThe details of all errors produced by a recipe run.org.openrewrite.table.SourcesFileErrors
  • Recipe performanceStatistics used in analyzing the performance of recipes.org.openrewrite.table.RecipeRunStats