Skip to content

Commit 52e235c

Browse files
Pankraz76Vincent Potucek
andauthored
[rewrite] Add Java8toJava11 (#3)
Signed-off-by: Vincent Potucek <[email protected]> Changes have been made to spring-webmvc/src/test/java/org/springframework/web/servlet/resource/GzipSupport.java by: org.openrewrite.java.migrate.UpgradeToJava17 org.openrewrite.java.migrate.Java8toJava11 org.openrewrite.java.migrate.nio.file.PathsGetToPathOf org.openrewrite.java.ChangeMethodTargetToStatic: {methodPattern=java.nio.file.Paths get(..), fullyQualifiedTargetTypeName=java.nio.file.Path} org.openrewrite.java.ChangeMethodName: {methodPattern=java.nio.file.Path get(..), newMethodName=of} Changes have been made to spring-webmvc/spring-webmvc.gradle by: org.openrewrite.java.migrate.UpgradeToJava17 org.openrewrite.java.migrate.Java8toJava11 org.openrewrite.java.migrate.javax.AddJaxbDependenciesWithRuntime org.openrewrite.java.migrate.javax.AddJaxbAPIDependencies org.openrewrite.java.dependencies.RemoveDependency: {groupId=com.sun.xml.bind, artifactId=jaxb-core} org.openrewrite.java.migrate.javax.AddJaxbRuntime: {runtime=glassfish} Changes have been made to spring-websocket/src/main/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecorator.java by: org.openrewrite.java.migrate.UpgradeToJava17 org.openrewrite.java.migrate.lang.StringFormatted: {addParentheses=false} Changes have been made to spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java by: org.openrewrite.java.migrate.UpgradeToJava17 org.openrewrite.staticanalysis.AddSerialAnnotationToSerialVersionUID Changes have been made to spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/HtmlFileTransportHandler.java by: org.openrewrite.java.migrate.UpgradeToJava17 org.openrewrite.java.migrate.lang.StringFormatted: {addParentheses=false} Changes have been made to spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/DefaultSockJsFrameFormat.java by: org.openrewrite.java.migrate.UpgradeToJava17 org.openrewrite.java.migrate.lang.StringFormatted: {addParentheses=false} Changes have been made to spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java by: org.openrewrite.java.migrate.UpgradeToJava17 org.openrewrite.java.migrate.lang.StringFormatted: {addParentheses=false} Changes have been made to spring-websocket/src/test/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecoratorTests.java by: org.openrewrite.java.migrate.UpgradeToJava17 org.openrewrite.java.migrate.lang.StringFormatted: {addParentheses=false} Please review and commit the results. Estimate time saved: 6h 14m Co-authored-by: Vincent Potucek <[email protected]>
1 parent e4f8ae0 commit 52e235c

File tree

40 files changed

+312
-81
lines changed

40 files changed

+312
-81
lines changed

.github/actions/build/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ runs:
4242
java-early-access: ${{ inputs.java-early-access }}
4343
java-toolchain: ${{ inputs.java-toolchain }}
4444
java-version: ${{ inputs.java-version }}
45+
- name: SanityCheck
46+
id: build
47+
if: ${{ inputs.publish == 'false' }}
48+
shell: bash
49+
run: ./gradlew rewriteDryRun -Dorg.gradle.jvmargs=-Xmx8G
4550
- name: Build
4651
id: build
4752
if: ${{ inputs.publish == 'false' }}

build.gradle

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
plugins {
2-
id 'io.freefair.aspectj' version '8.13.1' apply false
3-
// kotlinVersion is managed in gradle.properties
4-
id 'org.jetbrains.kotlin.plugin.serialization' version "${kotlinVersion}" apply false
5-
id 'org.jetbrains.dokka'
62
id 'com.github.bjornvester.xjc' version '1.8.2' apply false
73
id 'com.gradleup.shadow' version "9.2.2" apply false
8-
id 'me.champeau.jmh' version '0.7.2' apply false
4+
id 'io.freefair.aspectj' version '8.13.1' apply false
95
id 'io.spring.nullability' version '0.0.8' apply false
6+
id 'me.champeau.jmh' version '0.7.2' apply false
7+
id 'org.jetbrains.dokka'
8+
id 'org.jetbrains.kotlin.plugin.serialization' version "${kotlinVersion}" apply false // kotlinVersion is managed in gradle.properties
9+
id 'org.openrewrite.rewrite' version '7.20.0' apply false
1010
}
1111

1212
ext {
@@ -16,6 +16,8 @@ ext {
1616

1717
description = "Spring Framework"
1818

19+
apply from: "$rootDir/gradle/rewrite.gradle"
20+
1921
configure(allprojects) { project ->
2022
apply plugin: "org.springframework.build.localdev"
2123
group = "org.springframework"

gradle/rewrite.gradle

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
project.apply plugin: 'org.openrewrite.rewrite'
10+
11+
rewrite {
12+
activeRecipe('org.opensearch.openrewrite.SanityCheck')
13+
setExportDatatables(true)
14+
setFailOnDryRunResults(true)
15+
}
16+
17+
dependencies {
18+
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:3.18.0"))
19+
rewrite("org.openrewrite.recipe:rewrite-migrate-java:3.21.1")
20+
rewrite("org.openrewrite.recipe:rewrite-java-security:3.20.0")
21+
rewrite("org.openrewrite.recipe:rewrite-rewrite:0.15.0")
22+
rewrite("org.openrewrite.recipe:rewrite-static-analysis:2.21.0")
23+
rewrite("org.openrewrite.recipe:rewrite-third-party:0.30.0")
24+
}

rewrite.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
type: specs.openrewrite.org/v1beta/recipe
3+
name: org.opensearch.openrewrite.SanityCheck
4+
displayName: Apply all Java & Gradle best practices
5+
description: Comprehensive code quality recipe combining modernization, security, and best practices.
6+
tags:
7+
- java
8+
- gradle
9+
- static-analysis
10+
- cleanup
11+
recipeList:
12+
- org.openrewrite.gradle.EnableGradleBuildCache
13+
- org.openrewrite.gradle.EnableGradleParallelExecution
14+
- org.openrewrite.gradle.GradleBestPractices
15+
- org.openrewrite.java.migrate.Java8toJava11
16+
---

spring-beans/src/main/java/org/springframework/beans/propertyeditors/PathEditor.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.net.URISyntaxException;
2323
import java.nio.file.FileSystemNotFoundException;
2424
import java.nio.file.Path;
25-
import java.nio.file.Paths;
2625

2726
import org.springframework.core.io.Resource;
2827
import org.springframework.core.io.ResourceEditor;
@@ -33,7 +32,7 @@
3332
* Editor for {@code java.nio.file.Path}, to directly populate a Path
3433
* property instead of using a String property as bridge.
3534
*
36-
* <p>Based on {@link Paths#get(URI)}'s resolution algorithm, checking
35+
* <p>Based on {@link Path#of(URI)}'s resolution algorithm, checking
3736
* registered NIO file system providers, including the default file system
3837
* for "file:..." paths. Also supports Spring-style URL notation: any fully
3938
* qualified standard URL and Spring's special "classpath:" pseudo-URL, as
@@ -44,7 +43,7 @@
4443
* @author Juergen Hoeller
4544
* @since 4.3.2
4645
* @see java.nio.file.Path
47-
* @see Paths#get(URI)
46+
* @see Path#of(URI)
4847
* @see ResourceEditor
4948
* @see org.springframework.core.io.ResourceLoader
5049
* @see FileEditor
@@ -83,7 +82,7 @@ public void setAsText(String text) throws IllegalArgumentException {
8382
// No NIO candidate except for "C:" style drive letters
8483
nioPathCandidate = (scheme.length() == 1);
8584
// Let's try NIO file system providers via Paths.get(URI)
86-
setValue(Paths.get(uri).normalize());
85+
setValue(Path.of(uri).normalize());
8786
return;
8887
}
8988
}
@@ -104,7 +103,7 @@ public void setAsText(String text) throws IllegalArgumentException {
104103
setValue(null);
105104
}
106105
else if (nioPathCandidate && (!resource.isFile() || !resource.exists())) {
107-
setValue(Paths.get(text).normalize());
106+
setValue(Path.of(text).normalize());
108107
}
109108
else {
110109
try {

spring-beans/src/test/java/org/springframework/beans/ConcurrentBeanWrapperTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Properties;
2323
import java.util.Set;
2424
import java.util.concurrent.ConcurrentHashMap;
25+
import java.util.concurrent.ThreadLocalRandom;
2526

2627
import org.apache.commons.logging.Log;
2728
import org.apache.commons.logging.LogFactory;
@@ -84,7 +85,7 @@ private static void performSet() {
8485

8586
for (Iterator<?> i = p.entrySet().iterator(); i.hasNext();) {
8687
i.next();
87-
if (Math.random() > 0.9) {
88+
if (ThreadLocalRandom.current().nextDouble() > 0.9) {
8889
i.remove();
8990
}
9091
}

spring-beans/src/test/java/org/springframework/beans/propertyeditors/PathEditorTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.beans.PropertyEditor;
2020
import java.io.File;
2121
import java.nio.file.Path;
22-
import java.nio.file.Paths;
2322

2423
import org.junit.jupiter.api.Test;
2524

@@ -106,7 +105,7 @@ void testCurrentDirectory() {
106105
Object value = pathEditor.getValue();
107106
assertThat(value).isInstanceOf(Path.class);
108107
Path path = (Path) value;
109-
assertThat(path).isEqualTo(Paths.get("."));
108+
assertThat(path).isEqualTo(Path.of("."));
110109
}
111110

112111
@Test

spring-context-indexer/spring-context-indexer.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
description = "Spring Context Indexer"
22

33
dependencies {
4+
compileOnly "jakarta.annotation:jakarta.annotation-api:1.3.5"
5+
46
testImplementation(project(":spring-context"))
57
testImplementation("jakarta.annotation:jakarta.annotation-api")
68
testImplementation("jakarta.inject:jakarta.inject-api")

spring-context/src/test/java/org/springframework/jmx/support/JmxUtilsTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public void dontExposeMe() {
196196
}
197197

198198

199-
public interface FooMBean {
199+
public public interface FooMBean {
200200

201201
String getName();
202202
}
@@ -211,7 +211,7 @@ public String getName() {
211211
}
212212

213213

214-
public interface FooMXBean {
214+
public public interface FooMXBean {
215215

216216
String getName();
217217
}
@@ -234,7 +234,7 @@ public static class Abc extends Bar {
234234
}
235235

236236

237-
private interface JmxInterfaceMBean {
237+
public interface JmxInterfaceMBean {
238238
}
239239

240240

@@ -246,7 +246,7 @@ private interface SpecializedJmxInterface extends JmxInterface {
246246
}
247247

248248

249-
private interface JmxClassMBean {
249+
public interface JmxClassMBean {
250250
}
251251

252252

spring-core-test/spring-core-test.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ description = "Spring Core Test"
22

33
dependencies {
44
api(project(":spring-core"))
5-
optional("org.assertj:assertj-core")
5+
compileOnly "jakarta.annotation:jakarta.annotation-api:1.3.5"
6+
optional("org.assertj:assertj-core")
67
optional("org.junit.jupiter:junit-jupiter-api")
78
compileOnly("org.junit.jupiter:junit-jupiter-params") // Used in CompileWithForkedClassLoaderExtension Javadoc
89
compileOnly("org.junit.platform:junit-platform-launcher") // Used in CompileWithForkedClassLoaderExtension

0 commit comments

Comments
 (0)