Skip to content

Commit

Permalink
Merge branch 'main' into no-xml-bind
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek authored Feb 25, 2024
2 parents ff0da5c + 9366e4b commit 1280928
Show file tree
Hide file tree
Showing 105 changed files with 596 additions and 354 deletions.
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
secrets:
GH_PAT_ACTIONS_READ: ${{ secrets.GH_PAT_ACTIONS_READ }}
5 changes: 3 additions & 2 deletions .github/workflows/properties.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
jobs:
update-migrations:
runs-on: ubuntu-latest
if: github.event_name != 'schedule' || github.repository_owner == 'openrewrite'
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -20,7 +21,7 @@ jobs:

# Generate Spring Boot property migrations recipes
- name: Create jar and copy dependencies
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3
with:
arguments: generatePropertyMigrationRecipes

Expand All @@ -29,7 +30,7 @@ jobs:
run: echo "NOW=$(date +'%Y-%m-%dT%H%M')" >> $GITHUB_ENV
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@v6
with:
base: main
branch: migrations/${{ env.NOW }}
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/receive-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: receive-pr
on:
pull_request:
types: [opened, synchronize]
branches:
- main
# 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
20 changes: 12 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,20 @@ recipeDependencies {
val rewriteVersion = rewriteRecipe.rewriteVersion.get()

dependencies {
implementation("org.openrewrite:rewrite-java:${rewriteVersion}")
implementation("org.openrewrite:rewrite-xml:${rewriteVersion}")
implementation("org.openrewrite:rewrite-properties:${rewriteVersion}")
implementation("org.openrewrite:rewrite-yaml:${rewriteVersion}")
implementation("org.openrewrite:rewrite-gradle:${rewriteVersion}")
implementation("org.openrewrite:rewrite-maven:${rewriteVersion}")
implementation(platform("org.openrewrite:rewrite-bom:${rewriteVersion}"))
implementation("org.openrewrite:rewrite-java")
implementation("org.openrewrite:rewrite-xml")
implementation("org.openrewrite:rewrite-properties")
implementation("org.openrewrite:rewrite-yaml")
implementation("org.openrewrite:rewrite-gradle")
implementation("org.openrewrite:rewrite-maven")
implementation("org.openrewrite.recipe:rewrite-java-dependencies:${rewriteVersion}")
implementation("org.openrewrite.gradle.tooling:model:${rewriteVersion}")

runtimeOnly("org.openrewrite:rewrite-java-17:$rewriteVersion")
runtimeOnly("org.openrewrite:rewrite-java-17")
runtimeOnly("org.openrewrite.recipe:rewrite-hibernate:$rewriteVersion")
runtimeOnly("org.openrewrite.recipe:rewrite-migrate-java:$rewriteVersion")
runtimeOnly("org.openrewrite.recipe:rewrite-openapi:${rewriteVersion}")
runtimeOnly("org.openrewrite.recipe:rewrite-testing-frameworks:$rewriteVersion")

testRuntimeOnly("ch.qos.logback:logback-classic:1.+")
Expand All @@ -134,9 +136,11 @@ dependencies {

testImplementation("com.github.marschall:memoryfilesystem:latest.release")

testImplementation("org.openrewrite.gradle.tooling:model:$rewriteVersion")

// for generating properties migration configurations
testImplementation("io.github.classgraph:classgraph:latest.release")
testImplementation("org.openrewrite:rewrite-java-17:${rewriteVersion}")
testImplementation("org.openrewrite:rewrite-java-17")
testImplementation("org.openrewrite.recipe:rewrite-migrate-java:$rewriteVersion")
testImplementation("org.openrewrite.recipe:rewrite-testing-frameworks:$rewriteVersion")

Expand Down
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionSha256Sum=9631d53cf3e74bfa726893aee1f8994fee4e060c401335946dba2156f440f24c
20 changes: 10 additions & 10 deletions gradlew.bat
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,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 +57,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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.Optional;

@Value
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode(callSuper = false)
public class AddSpringDependencyManagementPlugin extends Recipe {
@Override
public String getDisplayName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import org.openrewrite.java.search.UsesType;
import org.openrewrite.java.tree.J;

import java.util.Collections;
import java.util.Set;

public class MigrateDefaultHttpClient extends Recipe {
@Override
public String getDisplayName() {
Expand All @@ -31,8 +34,18 @@ public String getDisplayName() {

@Override
public String getDescription() {
return "Since DefaultHttpClient is deprecated, we need to change it to the CloseableHttpClient. " +
"It only covers the default scenario with no custom HttpParams or ConnectionManager.";
return "Since `DefaultHttpClient` is deprecated, we need to change it to the `CloseableHttpClient`. " +
"It only covers the default scenario with no custom `HttpParams` or `ConnectionManager`.\n\n" +
"Of note: the `DefaultHttpClient` [does not support TLS 1.2](https://find-sec-bugs.github.io/bugs.htm#DEFAULT_HTTP_CLIENT).\n" +
"\n" +
"References:\n" +
" - [Find Sec Bugs](https://find-sec-bugs.github.io/bugs.htm#DEFAULT_HTTP_CLIENT)" +
" - [IBM Support Pages](https://www.ibm.com/support/pages/im-using-apache-httpclient-make-outbound-call-my-web-application-running-websphere-application-server-traditional-and-im-getting-ssl-handshake-error-how-can-i-debug)";
}

@Override
public Set<String> getTags() {
return Collections.singleton("CWE-326");
}

@Override
Expand All @@ -46,7 +59,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {

@Override
public J visitNewClass(J.NewClass newClass, ExecutionContext ctx) {
if (noArgsMatcher.matches(newClass.getConstructorType())) {
if (noArgsMatcher.matches(newClass)) {
maybeAddImport("org.apache.http.impl.client.HttpClients");
doAfterVisit(new ChangeType(
"org.apache.http.impl.client.DefaultHttpClient",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


@Value
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode(callSuper = false)
public class AddTimeUnitArgument extends Recipe {

@Option(displayName = "Method pattern",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import org.openrewrite.ExecutionContext;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.java.*;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.JavaVisitor;
import org.openrewrite.java.MethodMatcher;
import org.openrewrite.java.tree.J;

public class NewStatusLine extends Recipe {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* the recipe is configured without pathExpressions, it will query the execution context for reasonable defaults.
*/
@Value
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode(callSuper = false)
public class AddSpringProperty extends Recipe {

@Option(displayName = "Property key",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* TODO: Add a java visitor to this recipe that will change property keys in @Value, @PropertySource and @TestPropertySource
*/
@Value
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode(callSuper = false)
public class ChangeSpringPropertyKey extends Recipe {

@Override
Expand All @@ -57,7 +57,8 @@ public String getDescription() {

@Option(displayName = "Except",
description = "Regex. If any of these property keys exist as direct children of `oldPropertyKey`, then they will not be moved to `newPropertyKey`.",
required = false)
required = false,
example = "jvm")
@Nullable
List<String> except;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.openrewrite.properties.tree.Properties;
import org.openrewrite.yaml.tree.Yaml;

@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode(callSuper = false)
@Value
public class ChangeSpringPropertyValue extends Recipe {

Expand All @@ -44,12 +44,14 @@ public String getDescription() {
String propertyKey;

@Option(displayName = "New value",
description = "The new value to be used for key specified by `propertyKey`.")
description = "The new value to be used for key specified by `propertyKey`.",
example = "management.metrics.enable.process.files")
String newValue;

@Option(displayName = "Old value",
required = false,
description = "Only change the property value if it matches the configured `oldValue`.")
description = "Only change the property value if it matches the configured `oldValue`.",
example = "false")
@Nullable
String oldValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* ".properties" and YAML files.
*/
@Value
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode(callSuper = false)
public class DeleteSpringProperty extends Recipe {

@Option(displayName = "Property key",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public List<Recipe> getRecipeList() {
return Arrays.asList(new PropertiesToKebabCaseYaml(), new PropertiesToKebabCaseProperties());
}

@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode(callSuper = false)
static class PropertiesToKebabCaseYaml extends Recipe {
@Override
public String getDisplayName() {
Expand Down Expand Up @@ -82,7 +82,7 @@ public Yaml.Mapping.Entry visitMappingEntry(Yaml.Mapping.Entry entry, ExecutionC
}
}

@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode(callSuper = false)
static class PropertiesToKebabCaseProperties extends Recipe {
@Override
public String getDisplayName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public J.Block visitBlock(J.Block block, ExecutionContext ctx) {

@Value
@With
private static class ToBeRemoved implements Marker {
static class ToBeRemoved implements Marker {
UUID id;
static <J2 extends J> J2 withMarker(J2 j) {
return j.withMarkers(j.getMarkers().addIfAbsent(new ToBeRemoved(randomId())));
Expand Down
20 changes: 6 additions & 14 deletions src/main/java/org/openrewrite/java/spring/RenameBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
import lombok.EqualsAndHashCode;
import lombok.Value;
import org.jetbrains.annotations.NotNull;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Option;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.*;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.StringUtils;
import org.openrewrite.internal.lang.Nullable;
Expand All @@ -32,28 +28,24 @@
import org.openrewrite.java.search.DeclaresType;
import org.openrewrite.java.search.FindAnnotations;
import org.openrewrite.java.search.UsesType;
import org.openrewrite.java.tree.Expression;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JavaType;
import org.openrewrite.java.tree.Statement;
import org.openrewrite.java.tree.TypeUtils;
import org.openrewrite.java.tree.*;

import java.util.*;

import static org.openrewrite.java.MethodMatcher.methodPattern;

@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode(callSuper = false)
@Value
public class RenameBean extends Recipe {

@Option(required = false)
@Option(required = false, example = "foo.MyType")
@Nullable
String type;

@Option
@Option(example = "fooBean")
String oldName;

@Option
@Option(example = "barBean")
String newName;

private static final String FQN_QUALIFIER = "org.springframework.beans.factory.annotation.Qualifier";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import java.util.List;

@Value
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode(callSuper = false)
public class UseTlsAmqpConnectionString extends Recipe {
private static final String PREFIX_AMQP = "amqp";
private static final String PREFIX_AMQP_SECURE = "amqps";
Expand Down Expand Up @@ -138,7 +138,7 @@ private boolean sourcePathMatches(Path sourcePath, ExecutionContext ctx) {
}

@Value
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode(callSuper = false)
static class UseTlsAmqpConnectionStringYaml extends Recipe {
String propertyKey;

Expand Down Expand Up @@ -238,7 +238,7 @@ public Yaml.Mapping.Entry visitMappingEntry(Yaml.Mapping.Entry entry, ExecutionC
}

@Value
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode(callSuper = false)
static class UseTlsAmqpConnectionStringProperties extends Recipe {
String propertyKey;

Expand Down
Loading

0 comments on commit 1280928

Please sign in to comment.