diff --git a/src/main/resources/META-INF/rewrite/okhttp-4.yml b/src/main/resources/META-INF/rewrite/okhttp-4.yml new file mode 100644 index 0000000..478f6c3 --- /dev/null +++ b/src/main/resources/META-INF/rewrite/okhttp-4.yml @@ -0,0 +1,36 @@ +# +# Copyright 2023 the original author or authors. +#

+# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +#

+# https://www.apache.org/licenses/LICENSE-2.0 +#

+# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.okhttp.UpgradeOkHttp4 +displayName: Migrate to OkHttp 4.x +description: This recipe will apply changes commonly needed when migrating to OkHttp 4.x. +recipeList: + # https://square.github.io/okhttp/changelogs/upgrading_to_okhttp_4/ + - org.openrewrite.okhttp.UpgradeOkHttp4Dependencies + - org.openrewrite.okio.UpgradeOkio3 + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.okhttp.UpgradeOkHttp4Dependencies +displayName: Migrate OkHttp dependencies to 4.x +description: Migrate OkHttp dependencies to 4.x. +recipeList: + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: com.squareup.okhttp3 + oldArtifactId: okhttp + newVersion: 4.x \ No newline at end of file diff --git a/src/main/resources/META-INF/rewrite/okhttp-5.yml b/src/main/resources/META-INF/rewrite/okhttp-5.yml index 4931bf8..c91f141 100644 --- a/src/main/resources/META-INF/rewrite/okhttp-5.yml +++ b/src/main/resources/META-INF/rewrite/okhttp-5.yml @@ -21,9 +21,9 @@ displayName: Migrate to OkHttp 5.x description: This recipe will apply changes commonly needed when migrating to OkHttp 5.x. recipeList: # https://square.github.io/okhttp/changelogs/changelog/ + - org.openrewrite.okhttp.UpgradeOkHttp4 - org.openrewrite.okhttp.UpgradeOkHttp5Dependencies - org.openrewrite.okhttp.ReorderRequestBodyCreateArguments - - org.openrewrite.okio.UpgradeOkio3 --- type: specs.openrewrite.org/v1beta/recipe diff --git a/src/test/java/org/openrewrite/okhttp/MigrateToOkHttp4Test.java b/src/test/java/org/openrewrite/okhttp/MigrateToOkHttp4Test.java new file mode 100644 index 0000000..a1d2df6 --- /dev/null +++ b/src/test/java/org/openrewrite/okhttp/MigrateToOkHttp4Test.java @@ -0,0 +1,87 @@ +/* + * Copyright 2023 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.okhttp; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.openrewrite.maven.Assertions.pomXml; + +class MigrateToOkHttp4Test implements RewriteTest { + + public void defaults(RecipeSpec spec) { + spec.recipeFromResources("org.openrewrite.okhttp.UpgradeOkHttp4"); + } + + @Nested + class Dependencies { + @Test + @DocumentExample + void mavenDependency4x() { + rewriteRun( + //language=xml + pomXml( + """ + + + 4.0.0 + com.example + demo + 0.0.1-SNAPSHOT + + + com.squareup.okhttp3 + okhttp + 3.14.9 + + + + """, + spec -> spec.after(actual -> { + Matcher matcher = Pattern.compile("(4\\.\\d+\\.\\d+(-(alpha|beta)\\.\\d+)?)").matcher(actual); + assertTrue(matcher.find(), actual); + return """ + + + 4.0.0 + com.example + demo + 0.0.1-SNAPSHOT + + + com.squareup.okhttp3 + okhttp + %s + + + + """.formatted(matcher.group(1)); + } + ) + ) + ); + } + } +} \ No newline at end of file