Skip to content

Commit

Permalink
Expect upgrade of maven-compiler-plugin for Java 17
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Sep 8, 2024
1 parent 0cd60eb commit 9b2e7f0
Showing 1 changed file with 48 additions and 99 deletions.
147 changes: 48 additions & 99 deletions src/test/java/org/openrewrite/java/migrate/UpgradeToJava17Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ void upgradeFromJava8ToJava17() {
"""
<project>
<modelVersion>4.0.0</modelVersion>
<properties>
<java.version>1.8</java.version>
<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>
Expand All @@ -65,13 +65,13 @@ void upgradeFromJava8ToJava17() {
"""
<project>
<modelVersion>4.0.0</modelVersion>
<properties>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
Expand All @@ -83,7 +83,7 @@ void upgradeFromJava8ToJava17() {
java(
"""
package com.abc;
class A {
public String test() {
return String.format("Hello %s", "world");
Expand All @@ -92,7 +92,7 @@ public String test() {
""",
"""
package com.abc;
class A {
public String test() {
return "Hello %s".formatted("world");
Expand All @@ -116,13 +116,13 @@ void referenceToJavaVersionProperty() {
"""
<project>
<modelVersion>4.0.0</modelVersion>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
Expand All @@ -131,13 +131,13 @@ void referenceToJavaVersionProperty() {
"""
<project>
<modelVersion>4.0.0</modelVersion>
<properties>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
Expand All @@ -149,7 +149,7 @@ void referenceToJavaVersionProperty() {
//language=java
"""
package com.abc;
class A {
public String test() {
return String.format("Hello %s", "world");
Expand All @@ -159,7 +159,7 @@ public String test() {
//language=java
"""
package com.abc;
class A {
public String test() {
return "Hello %s".formatted("world");
Expand All @@ -186,9 +186,9 @@ void changeJavaxSecurityCertPackage() {
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import javax.security.cert.*;
class Test {
void foo() throws CertificateException, FileNotFoundException {
InputStream inStream = new FileInputStream("cert");
Expand All @@ -203,9 +203,9 @@ void foo() throws CertificateException, FileNotFoundException {
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.security.cert.*;
class Test {
void foo() throws CertificateException, FileNotFoundException {
InputStream inStream = new FileInputStream("cert");
Expand All @@ -228,33 +228,33 @@ void removedLegacySunJSSEProviderName() {
java(
"""
import javax.net.ssl.SSLContext;
class RemovedLegacySunJSSEProviderName {
String legacyProviderName = "com.sun.net.ssl.internal.ssl.Provider"; //flagged
String newProviderName = "SunJSSE"; //not flagged
void test() throws Exception {
SSLContext.getInstance("TLS", "com.sun.net.ssl.internal.ssl.Provider"); //flagged
SSLContext.getInstance("TLS", "SunJSSE"); //not flagged
}
void test2() throws Exception {
System.out.println("com.sun.net.ssl.internal.ssl.Provider"); //flagged
}
}
""",
"""
import javax.net.ssl.SSLContext;
class RemovedLegacySunJSSEProviderName {
String legacyProviderName = "SunJSSE"; //flagged
String newProviderName = "SunJSSE"; //not flagged
void test() throws Exception {
SSLContext.getInstance("TLS", "SunJSSE"); //flagged
SSLContext.getInstance("TLS", "SunJSSE"); //not flagged
}
void test2() throws Exception {
System.out.println("SunJSSE"); //flagged
}
Expand All @@ -272,7 +272,7 @@ void replaceLogRecordSetThreadID() {
java(
"""
import java.util.logging.LogRecord;
class Foo {
void bar(LogRecord record) {
int threadID = record.getThreadID();
Expand All @@ -282,7 +282,7 @@ void bar(LogRecord record) {
""",
"""
import java.util.logging.LogRecord;
class Foo {
void bar(LogRecord record) {
long threadID = record.getLongThreadID();
Expand Down Expand Up @@ -321,7 +321,7 @@ void needToUpgradeMavenCompilerPluginToSupportReleaseTag() {
</build>
</project>
""",
"""
after -> after.after(pomXml -> """
<project>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
Expand All @@ -331,67 +331,16 @@ void needToUpgradeMavenCompilerPluginToSupportReleaseTag() {
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version>
<version>%s</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
"""
)
),
8)
);
}

@Test
void notNeedToUpgradeMavenCompilerPluginToSupportReleaseTag() {
rewriteRun(
version(
mavenProject("project",
//language=xml
pomXml(
"""
<project>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
""",
"""
<project>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
"""
""".formatted(Pattern.compile("<version>(3\\.\\d\\d.*)</version>").matcher(pomXml)
.results().findFirst().orElseThrow().group(1)))
)
),
8)
Expand All @@ -406,79 +355,79 @@ void agentMainPreMainPublicApp() {
java(
"""
package com.test;
import java.lang.instrument.Instrumentation;
public class AgentMainPreMainPublicApp {
private static void premain(String agentArgs) {
//This should flag
}
public static void premain(String agentArgs, Instrumentation inst) {
//This shouldn't flag
}
public static void premain(String agentArgs, Instrumentation inst, String foo) {
//This shouldn't flag
}
private static void premain1(String agentArgs) {
//This shouldn't flag
}
protected void agentmain(String agentArgs) {
//This should flag
}
static void agentmain(String agentArgs, Instrumentation inst) {
//This should flag
}
private static void agentmain(String agentArgs, Instrumentation inst, String foo) {
//This shouldn't flag
}
private static void agentmain(String agentArgs, String inst) {
//This shouldn't flag
}
}
""",
"""
package com.test;
import java.lang.instrument.Instrumentation;
public class AgentMainPreMainPublicApp {
public static void premain(String agentArgs) {
//This should flag
}
public static void premain(String agentArgs, Instrumentation inst) {
//This shouldn't flag
}
public static void premain(String agentArgs, Instrumentation inst, String foo) {
//This shouldn't flag
}
private static void premain1(String agentArgs) {
//This shouldn't flag
}
public void agentmain(String agentArgs) {
//This should flag
}
public static void agentmain(String agentArgs, Instrumentation inst) {
//This should flag
}
private static void agentmain(String agentArgs, Instrumentation inst, String foo) {
//This shouldn't flag
}
private static void agentmain(String agentArgs, String inst) {
//This shouldn't flag
}
Expand Down

0 comments on commit 9b2e7f0

Please sign in to comment.