|
16 | 16 | package org.openrewrite.maven; |
17 | 17 |
|
18 | 18 | import org.junit.jupiter.api.Test; |
| 19 | +import org.junit.jupiter.params.ParameterizedTest; |
| 20 | +import org.junit.jupiter.params.provider.Arguments; |
| 21 | +import org.junit.jupiter.params.provider.MethodSource; |
19 | 22 | import org.openrewrite.DocumentExample; |
20 | 23 | import org.openrewrite.Issue; |
21 | 24 | import org.openrewrite.test.RecipeSpec; |
22 | 25 | import org.openrewrite.test.RewriteTest; |
23 | 26 |
|
| 27 | +import java.util.stream.Stream; |
| 28 | + |
24 | 29 | import static org.openrewrite.java.Assertions.mavenProject; |
25 | 30 | import static org.openrewrite.maven.Assertions.pomXml; |
26 | 31 |
|
@@ -621,4 +626,86 @@ void replacesSourceAndTargetConfig_InProfileSection() { |
621 | 626 | ) |
622 | 627 | ); |
623 | 628 | } |
| 629 | + |
| 630 | + @ParameterizedTest |
| 631 | + @MethodSource("mavenCompilerPluginConfig") |
| 632 | + void skipsUpdateIfExistingMavenCompilerPluginConfigIsNewerThanRequestedJavaVersion(String mavenCompilerPluginConfig) { |
| 633 | + rewriteRun( |
| 634 | + //language=xml |
| 635 | + pomXml( |
| 636 | + """ |
| 637 | + <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| 638 | + <modelVersion>4.0.0</modelVersion> |
| 639 | + <groupId>org.sample</groupId> |
| 640 | + <artifactId>sample</artifactId> |
| 641 | + <version>1.0.0</version> |
| 642 | + """ + mavenCompilerPluginConfig + |
| 643 | + """ |
| 644 | + </project> |
| 645 | + """ |
| 646 | + ) |
| 647 | + ); |
| 648 | + } |
| 649 | + |
| 650 | + private static Stream<Arguments> mavenCompilerPluginConfig() { |
| 651 | + return Stream.of( |
| 652 | + Arguments.of(""" |
| 653 | + <build> |
| 654 | + <plugins> |
| 655 | + <plugin> |
| 656 | + <groupId>org.apache.maven.plugins</groupId> |
| 657 | + <artifactId>maven-compiler-plugin</artifactId> |
| 658 | + <version>3.8.0</version> |
| 659 | + <configuration> |
| 660 | + <source>17</source> |
| 661 | + </configuration> |
| 662 | + </plugin> |
| 663 | + </plugins> |
| 664 | + </build> |
| 665 | + """), |
| 666 | + Arguments.of(""" |
| 667 | + <build> |
| 668 | + <plugins> |
| 669 | + <plugin> |
| 670 | + <groupId>org.apache.maven.plugins</groupId> |
| 671 | + <artifactId>maven-compiler-plugin</artifactId> |
| 672 | + <version>3.8.0</version> |
| 673 | + <configuration> |
| 674 | + <target>17</target> |
| 675 | + </configuration> |
| 676 | + </plugin> |
| 677 | + </plugins> |
| 678 | + </build> |
| 679 | + """), |
| 680 | + Arguments.of(""" |
| 681 | + <build> |
| 682 | + <plugins> |
| 683 | + <plugin> |
| 684 | + <groupId>org.apache.maven.plugins</groupId> |
| 685 | + <artifactId>maven-compiler-plugin</artifactId> |
| 686 | + <version>3.8.0</version> |
| 687 | + <configuration> |
| 688 | + <source>17</source> |
| 689 | + <target>17</target> |
| 690 | + </configuration> |
| 691 | + </plugin> |
| 692 | + </plugins> |
| 693 | + </build> |
| 694 | + """), |
| 695 | + Arguments.of(""" |
| 696 | + <build> |
| 697 | + <plugins> |
| 698 | + <plugin> |
| 699 | + <groupId>org.apache.maven.plugins</groupId> |
| 700 | + <artifactId>maven-compiler-plugin</artifactId> |
| 701 | + <version>3.8.0</version> |
| 702 | + <configuration> |
| 703 | + <release>17</release> |
| 704 | + </configuration> |
| 705 | + </plugin> |
| 706 | + </plugins> |
| 707 | + </build> |
| 708 | + """) |
| 709 | + ); |
| 710 | + } |
624 | 711 | } |
0 commit comments