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
5 changes: 5 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ runs:
java-early-access: ${{ inputs.java-early-access }}
java-toolchain: ${{ inputs.java-toolchain }}
java-version: ${{ inputs.java-version }}
- name: SanityCheck
id: build
if: ${{ inputs.publish == 'false' }}
shell: bash
run: ./gradlew rewriteDryRun -Dorg.gradle.jvmargs=-Xmx8G
- name: Build
id: build
if: ${{ inputs.publish == 'false' }}
Expand Down
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
plugins {
id 'io.freefair.aspectj' version '8.13.1' apply false
// kotlinVersion is managed in gradle.properties
id 'org.jetbrains.kotlin.plugin.serialization' version "${kotlinVersion}" apply false
id 'org.jetbrains.dokka'
id 'com.github.bjornvester.xjc' version '1.8.2' apply false
id 'com.gradleup.shadow' version "9.2.2" apply false
id 'me.champeau.jmh' version '0.7.2' apply false
id 'io.freefair.aspectj' version '8.13.1' apply false
id 'io.spring.nullability' version '0.0.8' apply false
id 'me.champeau.jmh' version '0.7.2' apply false
id 'org.jetbrains.dokka'
id 'org.jetbrains.kotlin.plugin.serialization' version "${kotlinVersion}" apply false // kotlinVersion is managed in gradle.properties
id 'org.openrewrite.rewrite' version '7.20.0' apply false
}

ext {
Expand All @@ -16,6 +16,8 @@ ext {

description = "Spring Framework"

apply from: "$rootDir/gradle/rewrite.gradle"

configure(allprojects) { project ->
apply plugin: "org.springframework.build.localdev"
group = "org.springframework"
Expand Down
24 changes: 24 additions & 0 deletions gradle/rewrite.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

project.apply plugin: 'org.openrewrite.rewrite'

rewrite {
activeRecipe('org.opensearch.openrewrite.SanityCheck')
setExportDatatables(true)
setFailOnDryRunResults(true)
}

dependencies {
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:3.18.0"))
rewrite("org.openrewrite.recipe:rewrite-migrate-java:3.21.1")
rewrite("org.openrewrite.recipe:rewrite-java-security:3.20.0")
rewrite("org.openrewrite.recipe:rewrite-rewrite:0.15.0")
rewrite("org.openrewrite.recipe:rewrite-static-analysis:2.21.0")
rewrite("org.openrewrite.recipe:rewrite-third-party:0.30.0")
}
16 changes: 16 additions & 0 deletions rewrite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
type: specs.openrewrite.org/v1beta/recipe
name: org.opensearch.openrewrite.SanityCheck
displayName: Apply all Java & Gradle best practices
description: Comprehensive code quality recipe combining modernization, security, and best practices.
tags:
- java
- gradle
- static-analysis
- cleanup
recipeList:
- org.openrewrite.gradle.EnableGradleBuildCache
- org.openrewrite.gradle.EnableGradleParallelExecution
- org.openrewrite.gradle.GradleBestPractices
- org.openrewrite.java.migrate.Java8toJava11
---
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.net.URISyntaxException;
import java.nio.file.FileSystemNotFoundException;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceEditor;
Expand All @@ -33,7 +32,7 @@
* Editor for {@code java.nio.file.Path}, to directly populate a Path
* property instead of using a String property as bridge.
*
* <p>Based on {@link Paths#get(URI)}'s resolution algorithm, checking
* <p>Based on {@link Path#of(URI)}'s resolution algorithm, checking
* registered NIO file system providers, including the default file system
* for "file:..." paths. Also supports Spring-style URL notation: any fully
* qualified standard URL and Spring's special "classpath:" pseudo-URL, as
Expand All @@ -44,7 +43,7 @@
* @author Juergen Hoeller
* @since 4.3.2
* @see java.nio.file.Path
* @see Paths#get(URI)
* @see Path#of(URI)
* @see ResourceEditor
* @see org.springframework.core.io.ResourceLoader
* @see FileEditor
Expand Down Expand Up @@ -83,7 +82,7 @@ public void setAsText(String text) throws IllegalArgumentException {
// No NIO candidate except for "C:" style drive letters
nioPathCandidate = (scheme.length() == 1);
// Let's try NIO file system providers via Paths.get(URI)
setValue(Paths.get(uri).normalize());
setValue(Path.of(uri).normalize());
return;
}
}
Expand All @@ -104,7 +103,7 @@ public void setAsText(String text) throws IllegalArgumentException {
setValue(null);
}
else if (nioPathCandidate && (!resource.isFile() || !resource.exists())) {
setValue(Paths.get(text).normalize());
setValue(Path.of(text).normalize());
}
else {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -84,7 +85,7 @@ private static void performSet() {

for (Iterator<?> i = p.entrySet().iterator(); i.hasNext();) {
i.next();
if (Math.random() > 0.9) {
if (ThreadLocalRandom.current().nextDouble() > 0.9) {
i.remove();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.beans.PropertyEditor;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -106,7 +105,7 @@ void testCurrentDirectory() {
Object value = pathEditor.getValue();
assertThat(value).isInstanceOf(Path.class);
Path path = (Path) value;
assertThat(path).isEqualTo(Paths.get("."));
assertThat(path).isEqualTo(Path.of("."));
}

@Test
Expand Down
2 changes: 2 additions & 0 deletions spring-context-indexer/spring-context-indexer.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
description = "Spring Context Indexer"

dependencies {
compileOnly "jakarta.annotation:jakarta.annotation-api:1.3.5"

testImplementation(project(":spring-context"))
testImplementation("jakarta.annotation:jakarta.annotation-api")
testImplementation("jakarta.inject:jakarta.inject-api")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void dontExposeMe() {
}


public interface FooMBean {
public public interface FooMBean {

String getName();
}
Expand All @@ -211,7 +211,7 @@ public String getName() {
}


public interface FooMXBean {
public public interface FooMXBean {

String getName();
}
Expand All @@ -234,7 +234,7 @@ public static class Abc extends Bar {
}


private interface JmxInterfaceMBean {
public interface JmxInterfaceMBean {
}


Expand All @@ -246,7 +246,7 @@ private interface SpecializedJmxInterface extends JmxInterface {
}


private interface JmxClassMBean {
public interface JmxClassMBean {
}


Expand Down
3 changes: 2 additions & 1 deletion spring-core-test/spring-core-test.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ description = "Spring Core Test"

dependencies {
api(project(":spring-core"))
optional("org.assertj:assertj-core")
compileOnly "jakarta.annotation:jakarta.annotation-api:1.3.5"
optional("org.assertj:assertj-core")
optional("org.junit.jupiter:junit-jupiter-api")
compileOnly("org.junit.jupiter:junit-jupiter-params") // Used in CompileWithForkedClassLoaderExtension Javadoc
compileOnly("org.junit.platform:junit-platform-launcher") // Used in CompileWithForkedClassLoaderExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.nio.file.NoSuchFileException;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

import org.jspecify.annotations.Nullable;
Expand Down Expand Up @@ -82,11 +81,11 @@ public PathResource(Path path) {
* via {@link #createRelative}, the relative path will be built <i>underneath</i>
* the given root: for example, Paths.get("C:/dir1/"), relative path "dir2" &rarr; "C:/dir1/dir2"!
* @param path a path
* @see java.nio.file.Paths#get(String, String...)
* @see Path#of(String, String...)
*/
public PathResource(String path) {
Assert.notNull(path, "Path must not be null");
this.path = Paths.get(path).normalize();
this.path = Path.of(path).normalize();
}

/**
Expand All @@ -95,11 +94,11 @@ public PathResource(String path) {
* via {@link #createRelative}, the relative path will be built <i>underneath</i>
* the given root: for example, Paths.get("C:/dir1/"), relative path "dir2" &rarr; "C:/dir1/dir2"!
* @param uri a path URI
* @see java.nio.file.Paths#get(URI)
* @see Path#of(URI)
*/
public PathResource(URI uri) {
Assert.notNull(uri, "URI must not be null");
this.path = Paths.get(uri).normalize();
this.path = Path.of(uri).normalize();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.util.backoff;

import java.util.StringJoiner;
import java.util.concurrent.ThreadLocalRandom;

import org.springframework.util.Assert;

Expand Down Expand Up @@ -308,7 +309,7 @@ private long applyJitter(long interval) {
long applicableJitter = jitter * (interval / initialInterval);
long min = Math.max(interval - applicableJitter, initialInterval);
long max = Math.min(interval + applicableJitter, getMaxInterval());
return min + (long) (Math.random() * (max - min));
return min + (long) (ThreadLocalRandom.current().nextDouble() * (max - min));
}
return interval;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.nio.file.AccessDeniedException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -88,7 +87,7 @@ void nullUri() {

@Test
void createFromPath() {
Path path = Paths.get(TEST_FILE);
Path path = Path.of(TEST_FILE);
PathResource resource = new PathResource(path);
assertThat(resource.getPath()).isEqualTo(TEST_FILE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Stream;
Expand Down Expand Up @@ -132,7 +131,7 @@ void resourceCreateRelativeUnknown(Resource resource) throws Exception {

private static Stream<Arguments> resource() throws URISyntaxException {
URL resourceClass = ResourceTests.class.getResource("ResourceTests.class");
Path resourceClassFilePath = Paths.get(resourceClass.toURI());
Path resourceClassFilePath = Path.of(resourceClass.toURI());
return Stream.of(
argumentSet("ClassPathResource", new ClassPathResource("org/springframework/core/io/ResourceTests.class")),
argumentSet("ClassPathResource with ClassLoader", new ClassPathResource("org/springframework/core/io/ResourceTests.class", ResourceTests.class.getClassLoader())),
Expand Down Expand Up @@ -252,7 +251,7 @@ void sameResourceFromFileIsEqual() {

@Test
void sameResourceFromFilePathIsEqual() throws Exception {
Path filePath = Paths.get(getClass().getResource("ResourceTests.class").toURI());
Path filePath = Path.of(getClass().getResource("ResourceTests.class").toURI());
Resource resource = new FileSystemResource(filePath);
assertThat(resource).isEqualTo(new FileSystemResource(filePath));
}
Expand Down
Loading