From 7305d5ce99975c4b816bc28581244a9a187aa3c1 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Tue, 5 Apr 2022 21:37:01 +0200 Subject: [PATCH] Change Maven property java.version to 11 (#82) * Add SpringBootJavaVersion11 Closes #66 * Add SpringBootJavaVersion11Test * Drop Spring from recipe name * Update test to match recipe package * Update src/test/kotlin/org/openrewrite/java/migrate/SpringBootJavaVersion11Test.kt * Also change maven.compile.source & target * Drop Spring from JavaVersion11 displayName & description --- .../META-INF/rewrite/java-version-11.yml | 33 +++++++ .../META-INF/rewrite/java8-to-java11.yml | 1 + .../java/migrate/JavaVersion11Test.kt | 91 +++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 src/main/resources/META-INF/rewrite/java-version-11.yml create mode 100644 src/test/kotlin/org/openrewrite/java/migrate/JavaVersion11Test.kt diff --git a/src/main/resources/META-INF/rewrite/java-version-11.yml b/src/main/resources/META-INF/rewrite/java-version-11.yml new file mode 100644 index 0000000000..0e3efea673 --- /dev/null +++ b/src/main/resources/META-INF/rewrite/java-version-11.yml @@ -0,0 +1,33 @@ +# +# Copyright 2022 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.java.migrate.JavaVersion11 +displayName: Change Maven Java version property values to 11 +description: Change maven.compiler.source and maven.compiler.target values to 11. +recipeList: + - org.openrewrite.maven.ChangePropertyValue: + key: java.version + newValue: 11 + addIfMissing: false + - org.openrewrite.maven.ChangePropertyValue: + key: maven.compiler.source + newValue: 11 + addIfMissing: false + - org.openrewrite.maven.ChangePropertyValue: + key: maven.compiler.target + newValue: 11 + addIfMissing: false diff --git a/src/main/resources/META-INF/rewrite/java8-to-java11.yml b/src/main/resources/META-INF/rewrite/java8-to-java11.yml index bc772c0209..13a6437d74 100644 --- a/src/main/resources/META-INF/rewrite/java8-to-java11.yml +++ b/src/main/resources/META-INF/rewrite/java8-to-java11.yml @@ -45,3 +45,4 @@ recipeList: - org.openrewrite.java.migrate.javax.JavaxXmlStreamAPIs - org.openrewrite.java.migrate.wro4j.UpgradeWro4jMavenPluginVersion - org.openrewrite.java.migrate.jacoco.UpgradeJaCoCoMavenPluginVersion + - org.openrewrite.java.migrate.JavaVersion11 diff --git a/src/test/kotlin/org/openrewrite/java/migrate/JavaVersion11Test.kt b/src/test/kotlin/org/openrewrite/java/migrate/JavaVersion11Test.kt new file mode 100644 index 0000000000..d4bf29e25a --- /dev/null +++ b/src/test/kotlin/org/openrewrite/java/migrate/JavaVersion11Test.kt @@ -0,0 +1,91 @@ +/* + * Copyright 2022 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.java.migrate + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.openrewrite.Recipe +import org.openrewrite.config.Environment +import org.openrewrite.maven.MavenRecipeTest + +class JavaVersion11Test : MavenRecipeTest { + override val recipe: Recipe = Environment.builder() + .scanRuntimeClasspath("org.openrewrite.java.migrate") + .build() + .activateRecipes("org.openrewrite.java.migrate.JavaVersion11") + + @Test + fun changeJavaVersion() = assertChanged( + before = """ + + 4.0.0 + + + 1.8 + + + com.mycompany.app + my-app + 1 + + """, + after = """ + + 4.0.0 + + + 11 + + + com.mycompany.app + my-app + 1 + + """ + ) + + @Test + fun changeMavenCompiler() = assertChanged( + before = """ + + 4.0.0 + + + 1.8 + 1.8 + + + com.mycompany.app + my-app + 1 + + """, + after = """ + + 4.0.0 + + + 11 + 11 + + + com.mycompany.app + my-app + 1 + + """ + ) +} \ No newline at end of file