Skip to content
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
33 changes: 33 additions & 0 deletions src/main/resources/META-INF/rewrite/java-version-11.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# Copyright 2022 the original author or authors.
# <p>
# 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
# <p>
# https://www.apache.org/licenses/LICENSE-2.0
# <p>
# 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
1 change: 1 addition & 0 deletions src/main/resources/META-INF/rewrite/java8-to-java11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
91 changes: 91 additions & 0 deletions src/test/kotlin/org/openrewrite/java/migrate/JavaVersion11Test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright 2022 the original author or authors.
* <p>
* 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
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 = """
<project>
<modelVersion>4.0.0</modelVersion>

<properties>
<java.version>1.8</java.version>
</properties>

<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
""",
after = """
<project>
<modelVersion>4.0.0</modelVersion>

<properties>
<java.version>11</java.version>
</properties>

<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
"""
)

@Test
fun changeMavenCompiler() = assertChanged(
before = """
<project>
<modelVersion>4.0.0</modelVersion>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
""",
after = """
<project>
<modelVersion>4.0.0</modelVersion>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
"""
)
}