Skip to content

Commit 9b2e7f0

Browse files
committed
Expect upgrade of maven-compiler-plugin for Java 17
1 parent 0cd60eb commit 9b2e7f0

File tree

1 file changed

+48
-99
lines changed

1 file changed

+48
-99
lines changed

src/test/java/org/openrewrite/java/migrate/UpgradeToJava17Test.java

Lines changed: 48 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ void upgradeFromJava8ToJava17() {
5050
"""
5151
<project>
5252
<modelVersion>4.0.0</modelVersion>
53-
53+
5454
<properties>
5555
<java.version>1.8</java.version>
5656
<maven.compiler.source>1.8</maven.compiler.source>
5757
<maven.compiler.target>1.8</maven.compiler.target>
5858
</properties>
59-
59+
6060
<groupId>com.mycompany.app</groupId>
6161
<artifactId>my-app</artifactId>
6262
<version>1</version>
@@ -65,13 +65,13 @@ void upgradeFromJava8ToJava17() {
6565
"""
6666
<project>
6767
<modelVersion>4.0.0</modelVersion>
68-
68+
6969
<properties>
7070
<java.version>17</java.version>
7171
<maven.compiler.source>17</maven.compiler.source>
7272
<maven.compiler.target>17</maven.compiler.target>
7373
</properties>
74-
74+
7575
<groupId>com.mycompany.app</groupId>
7676
<artifactId>my-app</artifactId>
7777
<version>1</version>
@@ -83,7 +83,7 @@ void upgradeFromJava8ToJava17() {
8383
java(
8484
"""
8585
package com.abc;
86-
86+
8787
class A {
8888
public String test() {
8989
return String.format("Hello %s", "world");
@@ -92,7 +92,7 @@ public String test() {
9292
""",
9393
"""
9494
package com.abc;
95-
95+
9696
class A {
9797
public String test() {
9898
return "Hello %s".formatted("world");
@@ -116,13 +116,13 @@ void referenceToJavaVersionProperty() {
116116
"""
117117
<project>
118118
<modelVersion>4.0.0</modelVersion>
119-
119+
120120
<properties>
121121
<java.version>1.8</java.version>
122122
<maven.compiler.source>${java.version}</maven.compiler.source>
123123
<maven.compiler.target>${java.version}</maven.compiler.target>
124124
</properties>
125-
125+
126126
<groupId>com.mycompany.app</groupId>
127127
<artifactId>my-app</artifactId>
128128
<version>1</version>
@@ -131,13 +131,13 @@ void referenceToJavaVersionProperty() {
131131
"""
132132
<project>
133133
<modelVersion>4.0.0</modelVersion>
134-
134+
135135
<properties>
136136
<java.version>17</java.version>
137137
<maven.compiler.source>${java.version}</maven.compiler.source>
138138
<maven.compiler.target>${java.version}</maven.compiler.target>
139139
</properties>
140-
140+
141141
<groupId>com.mycompany.app</groupId>
142142
<artifactId>my-app</artifactId>
143143
<version>1</version>
@@ -149,7 +149,7 @@ void referenceToJavaVersionProperty() {
149149
//language=java
150150
"""
151151
package com.abc;
152-
152+
153153
class A {
154154
public String test() {
155155
return String.format("Hello %s", "world");
@@ -159,7 +159,7 @@ public String test() {
159159
//language=java
160160
"""
161161
package com.abc;
162-
162+
163163
class A {
164164
public String test() {
165165
return "Hello %s".formatted("world");
@@ -186,9 +186,9 @@ void changeJavaxSecurityCertPackage() {
186186
import java.io.FileInputStream;
187187
import java.io.FileNotFoundException;
188188
import java.io.InputStream;
189-
189+
190190
import javax.security.cert.*;
191-
191+
192192
class Test {
193193
void foo() throws CertificateException, FileNotFoundException {
194194
InputStream inStream = new FileInputStream("cert");
@@ -203,9 +203,9 @@ void foo() throws CertificateException, FileNotFoundException {
203203
import java.io.FileInputStream;
204204
import java.io.FileNotFoundException;
205205
import java.io.InputStream;
206-
206+
207207
import java.security.cert.*;
208-
208+
209209
class Test {
210210
void foo() throws CertificateException, FileNotFoundException {
211211
InputStream inStream = new FileInputStream("cert");
@@ -228,33 +228,33 @@ void removedLegacySunJSSEProviderName() {
228228
java(
229229
"""
230230
import javax.net.ssl.SSLContext;
231-
231+
232232
class RemovedLegacySunJSSEProviderName {
233233
String legacyProviderName = "com.sun.net.ssl.internal.ssl.Provider"; //flagged
234234
String newProviderName = "SunJSSE"; //not flagged
235-
235+
236236
void test() throws Exception {
237237
SSLContext.getInstance("TLS", "com.sun.net.ssl.internal.ssl.Provider"); //flagged
238238
SSLContext.getInstance("TLS", "SunJSSE"); //not flagged
239239
}
240-
240+
241241
void test2() throws Exception {
242242
System.out.println("com.sun.net.ssl.internal.ssl.Provider"); //flagged
243243
}
244244
}
245245
""",
246246
"""
247247
import javax.net.ssl.SSLContext;
248-
248+
249249
class RemovedLegacySunJSSEProviderName {
250250
String legacyProviderName = "SunJSSE"; //flagged
251251
String newProviderName = "SunJSSE"; //not flagged
252-
252+
253253
void test() throws Exception {
254254
SSLContext.getInstance("TLS", "SunJSSE"); //flagged
255255
SSLContext.getInstance("TLS", "SunJSSE"); //not flagged
256256
}
257-
257+
258258
void test2() throws Exception {
259259
System.out.println("SunJSSE"); //flagged
260260
}
@@ -272,7 +272,7 @@ void replaceLogRecordSetThreadID() {
272272
java(
273273
"""
274274
import java.util.logging.LogRecord;
275-
275+
276276
class Foo {
277277
void bar(LogRecord record) {
278278
int threadID = record.getThreadID();
@@ -282,7 +282,7 @@ void bar(LogRecord record) {
282282
""",
283283
"""
284284
import java.util.logging.LogRecord;
285-
285+
286286
class Foo {
287287
void bar(LogRecord record) {
288288
long threadID = record.getLongThreadID();
@@ -321,7 +321,7 @@ void needToUpgradeMavenCompilerPluginToSupportReleaseTag() {
321321
</build>
322322
</project>
323323
""",
324-
"""
324+
after -> after.after(pomXml -> """
325325
<project>
326326
<groupId>com.mycompany.app</groupId>
327327
<artifactId>my-app</artifactId>
@@ -331,67 +331,16 @@ void needToUpgradeMavenCompilerPluginToSupportReleaseTag() {
331331
<plugin>
332332
<groupId>org.apache.maven.plugins</groupId>
333333
<artifactId>maven-compiler-plugin</artifactId>
334-
<version>3.6.2</version>
334+
<version>%s</version>
335335
<configuration>
336336
<release>17</release>
337337
</configuration>
338338
</plugin>
339339
</plugins>
340340
</build>
341341
</project>
342-
"""
343-
)
344-
),
345-
8)
346-
);
347-
}
348-
349-
@Test
350-
void notNeedToUpgradeMavenCompilerPluginToSupportReleaseTag() {
351-
rewriteRun(
352-
version(
353-
mavenProject("project",
354-
//language=xml
355-
pomXml(
356-
"""
357-
<project>
358-
<groupId>com.mycompany.app</groupId>
359-
<artifactId>my-app</artifactId>
360-
<version>1</version>
361-
<build>
362-
<plugins>
363-
<plugin>
364-
<groupId>org.apache.maven.plugins</groupId>
365-
<artifactId>maven-compiler-plugin</artifactId>
366-
<version>3.8.0</version>
367-
<configuration>
368-
<source>1.8</source>
369-
<target>1.8</target>
370-
</configuration>
371-
</plugin>
372-
</plugins>
373-
</build>
374-
</project>
375-
""",
376-
"""
377-
<project>
378-
<groupId>com.mycompany.app</groupId>
379-
<artifactId>my-app</artifactId>
380-
<version>1</version>
381-
<build>
382-
<plugins>
383-
<plugin>
384-
<groupId>org.apache.maven.plugins</groupId>
385-
<artifactId>maven-compiler-plugin</artifactId>
386-
<version>3.8.0</version>
387-
<configuration>
388-
<release>17</release>
389-
</configuration>
390-
</plugin>
391-
</plugins>
392-
</build>
393-
</project>
394-
"""
342+
""".formatted(Pattern.compile("<version>(3\\.\\d\\d.*)</version>").matcher(pomXml)
343+
.results().findFirst().orElseThrow().group(1)))
395344
)
396345
),
397346
8)
@@ -406,79 +355,79 @@ void agentMainPreMainPublicApp() {
406355
java(
407356
"""
408357
package com.test;
409-
358+
410359
import java.lang.instrument.Instrumentation;
411-
360+
412361
public class AgentMainPreMainPublicApp {
413-
362+
414363
private static void premain(String agentArgs) {
415364
//This should flag
416365
}
417-
366+
418367
public static void premain(String agentArgs, Instrumentation inst) {
419368
//This shouldn't flag
420369
}
421-
370+
422371
public static void premain(String agentArgs, Instrumentation inst, String foo) {
423372
//This shouldn't flag
424373
}
425-
374+
426375
private static void premain1(String agentArgs) {
427376
//This shouldn't flag
428377
}
429-
378+
430379
protected void agentmain(String agentArgs) {
431380
//This should flag
432381
}
433-
382+
434383
static void agentmain(String agentArgs, Instrumentation inst) {
435384
//This should flag
436385
}
437-
386+
438387
private static void agentmain(String agentArgs, Instrumentation inst, String foo) {
439388
//This shouldn't flag
440389
}
441-
390+
442391
private static void agentmain(String agentArgs, String inst) {
443392
//This shouldn't flag
444393
}
445394
}
446395
""",
447396
"""
448397
package com.test;
449-
398+
450399
import java.lang.instrument.Instrumentation;
451-
400+
452401
public class AgentMainPreMainPublicApp {
453-
402+
454403
public static void premain(String agentArgs) {
455404
//This should flag
456405
}
457-
406+
458407
public static void premain(String agentArgs, Instrumentation inst) {
459408
//This shouldn't flag
460409
}
461-
410+
462411
public static void premain(String agentArgs, Instrumentation inst, String foo) {
463412
//This shouldn't flag
464413
}
465-
414+
466415
private static void premain1(String agentArgs) {
467416
//This shouldn't flag
468417
}
469-
418+
470419
public void agentmain(String agentArgs) {
471420
//This should flag
472421
}
473-
422+
474423
public static void agentmain(String agentArgs, Instrumentation inst) {
475424
//This should flag
476425
}
477-
426+
478427
private static void agentmain(String agentArgs, Instrumentation inst, String foo) {
479428
//This shouldn't flag
480429
}
481-
430+
482431
private static void agentmain(String agentArgs, String inst) {
483432
//This shouldn't flag
484433
}

0 commit comments

Comments
 (0)