Skip to content

Commit

Permalink
Merge branch 'main' into feat/JLL/url-equals-hashcode
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek authored Nov 29, 2024
2 parents c3f647d + 0d8d873 commit 3d04f96
Show file tree
Hide file tree
Showing 222 changed files with 7,986 additions and 2,417 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
insert_final_newline = true
trim_trailing_whitespace = true

[src/test*/java/**.java]
indent_size = 4
ij_continuation_indent_size = 2
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ jobs:
uses: openrewrite/gh-automation/.github/workflows/ci-gradle.yml@main
secrets:
gradle_enterprise_access_key: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
gradle_enterprise_cache_username: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USERNAME }}
gradle_enterprise_cache_password: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }}
ossrh_username: ${{ secrets.OSSRH_USERNAME }}
ossrh_token: ${{ secrets.OSSRH_TOKEN }}
ossrh_signing_key: ${{ secrets.OSSRH_SIGNING_KEY }}
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/comment-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: comment-pr

# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow
on:
workflow_run:
workflows: ["receive-pr"]
types:
- completed

# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
# Since this pull request has write permissions on the target repo, we should **NOT** execute any untrusted code.
jobs:
post-suggestions:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: openrewrite/gh-automation/.github/workflows/comment-pr.yml@main
17 changes: 17 additions & 0 deletions .github/workflows/receive-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: receive-pr

on:
pull_request:
types: [opened, synchronize]
branches:
- main

concurrency:
group: '${{ github.workflow }} @ ${{ github.ref }}'
cancel-in-progress: true

# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
# Since this pull request receives untrusted code, we should **NOT** have any secrets in the environment.
jobs:
upload-patch:
uses: openrewrite/gh-automation/.github/workflows/receive-pr.yml@main
6 changes: 4 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ dependencies {
implementation("org.openrewrite:rewrite-java")
implementation("org.openrewrite:rewrite-groovy:${rewriteVersion}")
implementation("org.openrewrite:rewrite-kotlin:${rewriteVersion}")
implementation("org.openrewrite:rewrite-csharp:${rewriteVersion}")
implementation("org.openrewrite.meta:rewrite-analysis:${rewriteVersion}")
implementation("org.apache.commons:commons-text:latest.release")

annotationProcessor("org.openrewrite:rewrite-templating:${rewriteVersion}")
implementation("org.openrewrite:rewrite-templating:${rewriteVersion}")
compileOnly("com.google.errorprone:error_prone_core:2.19.1:with-dependencies") {
compileOnly("com.google.errorprone:error_prone_core:2.+:with-dependencies") {
exclude("com.google.auto.service", "auto-service-annotations")
}

testImplementation("org.jetbrains:annotations:24.+")
testImplementation("org.openrewrite:rewrite-groovy")
testImplementation("org.junit-pioneer:junit-pioneer:2.0.1")
testImplementation("org.openrewrite:rewrite-test")
testImplementation("org.junit-pioneer:junit-pioneer:2.+")
testImplementation("junit:junit:4.13.2")

testImplementation("com.google.code.gson:gson:latest.release")
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionSha256Sum=9d926787066a081739e8200858338b4a69e837c3a821a33aca9db09dd4a41026
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
distributionSha256Sum=f397b287023acdba1e9f6fc5ea72d22dd63669d59ed4a289a29b1a76eee151c6
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 4 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
22 changes: 12 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
34 changes: 15 additions & 19 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,34 @@ pluginManagement {
}

plugins {
id("com.gradle.enterprise") version "latest.release"
id("com.gradle.develocity") version "latest.release"
id("com.gradle.common-custom-user-data-gradle-plugin") version "latest.release"
}

gradleEnterprise {
val isCiServer = System.getenv("CI")?.equals("true") ?: false
develocity {
server = "https://ge.openrewrite.org/"
val gradleCacheRemoteUsername: String? = System.getenv("GRADLE_ENTERPRISE_CACHE_USERNAME")
val gradleCacheRemotePassword: String? = System.getenv("GRADLE_ENTERPRISE_CACHE_PASSWORD")

val isCiServer = System.getenv("CI")?.equals("true") ?: false
val accessKey = System.getenv("GRADLE_ENTERPRISE_ACCESS_KEY")
val authenticated = !accessKey.isNullOrBlank()
buildCache {
remote(HttpBuildCache::class) {
url = uri("https://ge.openrewrite.org/cache/")
isPush = isCiServer
if (!gradleCacheRemoteUsername.isNullOrBlank() && !gradleCacheRemotePassword.isNullOrBlank()) {
credentials {
username = gradleCacheRemoteUsername
password = gradleCacheRemotePassword
}
}
remote(develocity.buildCache) {
isEnabled = true
isPush = isCiServer && authenticated
}
}

buildScan {
capture {
isTaskInputFiles = true
fileFingerprints = true
}

isUploadInBackground = !isCiServer
publishing {
onlyIf {
authenticated
}
}

publishAlways()
this as com.gradle.enterprise.gradleplugin.internal.extension.BuildScanExtensionWithHiddenFeatures
publishIfAuthenticated()
uploadInBackground = !isCiServer
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.staticanalysis;

import org.jspecify.annotations.NonNull;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.search.FindAnnotations;
import org.openrewrite.java.search.UsesJavaVersion;
import org.openrewrite.java.search.UsesType;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JavaType;
import org.openrewrite.java.tree.TypeUtils;

import java.time.Duration;
import java.util.Comparator;

public class AddSerialAnnotationToSerialVersionUID extends Recipe {
@Override
public String getDisplayName() {
return "Add `@Serial` annotation to `serialVersionUID`";
}

@Override
public String getDescription() {
return "Annotation any `serialVersionUID` fields with `@Serial` to indicate it's part of the serialization mechanism.";
}

@Override
public Duration getEstimatedEffortPerOccurrence() {
return Duration.ofMinutes(1);
}

@Override
@NonNull
public TreeVisitor<?, ExecutionContext> getVisitor() {
return Preconditions.check(
Preconditions.and(
new UsesJavaVersion<>(14),
new UsesType<>("java.io.Serializable", true)
),
new JavaIsoVisitor<ExecutionContext>() {
@Override
public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) {
if (TypeUtils.isAssignableTo("java.io.Serializable", classDecl.getType())) {
return super.visitClassDeclaration(classDecl, ctx);
}
return classDecl;
}

@Override
public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations multiVariable, ExecutionContext ctx) {
J.VariableDeclarations vd = super.visitVariableDeclarations(multiVariable, ctx);
if (isPrivateStaticFinalLongSerialVersionUID(vd) &&
FindAnnotations.find(vd, "@java.io.Serial").isEmpty()) {
maybeAddImport("java.io.Serial");
return JavaTemplate.builder("@Serial")
.imports("java.io.Serial")
.build()
.apply(getCursor(), vd.getCoordinates().addAnnotation(Comparator.comparing(J.Annotation::getSimpleName)));
}
return vd;
}

private boolean isPrivateStaticFinalLongSerialVersionUID(J.VariableDeclarations vd) {
return vd.hasModifier(J.Modifier.Type.Private) &&
vd.hasModifier(J.Modifier.Type.Static) &&
vd.hasModifier(J.Modifier.Type.Final) &&
TypeUtils.asPrimitive(vd.getType()) == JavaType.Primitive.Long &&
vd.getVariables().size() == 1 &&
"serialVersionUID".equals(vd.getVariables().get(0).getSimpleName());
}
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package org.openrewrite.staticanalysis;

import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.tree.J;
Expand Down Expand Up @@ -48,7 +48,7 @@ public String getDescription() {

@Override
public Set<String> getTags() {
return Collections.singleton("RSPEC-2057");
return Collections.singleton("RSPEC-S2057");
}

@Override
Expand Down Expand Up @@ -97,9 +97,9 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex

private J.VariableDeclarations maybeFixVariableDeclarations(J.VariableDeclarations varDecls) {
List<J.Modifier> modifiers = varDecls.getModifiers();
if (!J.Modifier.hasModifier(modifiers, J.Modifier.Type.Private)
|| !J.Modifier.hasModifier(modifiers, J.Modifier.Type.Static)
|| !J.Modifier.hasModifier(modifiers, J.Modifier.Type.Final)) {
if (!J.Modifier.hasModifier(modifiers, J.Modifier.Type.Private) ||
!J.Modifier.hasModifier(modifiers, J.Modifier.Type.Static) ||
!J.Modifier.hasModifier(modifiers, J.Modifier.Type.Final)) {
varDecls = varDecls.withModifiers(Arrays.asList(
new J.Modifier(Tree.randomId(), Space.EMPTY, Markers.EMPTY, null, J.Modifier.Type.Private, Collections.emptyList()),
new J.Modifier(Tree.randomId(), Space.SINGLE_SPACE, Markers.EMPTY, null, J.Modifier.Type.Static, Collections.emptyList()),
Expand Down Expand Up @@ -133,7 +133,9 @@ private boolean requiresSerialVersionField(@Nullable JavaType type) {
//All other parameterized types fall through
} else if (type instanceof JavaType.FullyQualified) {
JavaType.FullyQualified fq = (JavaType.FullyQualified) type;
if (fq.getKind() == JavaType.Class.Kind.Enum) return false;
if (fq.getKind() == JavaType.Class.Kind.Enum) {
return false;
}

if (fq.getKind() != JavaType.Class.Kind.Interface &&
!fq.isAssignableTo("java.lang.Throwable")) {
Expand Down
Loading

0 comments on commit 3d04f96

Please sign in to comment.