Skip to content
Open
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
24 changes: 24 additions & 0 deletions docs/content/en/docs/migration/v5-3-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@ title: Migrating from v5.2 to v5.3
description: Migrating from v5.2 to v5.3
---

## Automated Migration with OpenRewrite

You can automatically apply all the migration changes described below using [OpenRewrite](https://docs.openrewrite.org/).
Add the following to your `pom.xml` and run `mvn rewrite:run`:

```xml
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>6.33.0</version>
<configuration>
<activeRecipes>
<recipe>io.javaoperatorsdk.operator.migration.V5_3Migration</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>io.javaoperatorsdk</groupId>
<artifactId>migration</artifactId>
<version>5.3.1</version>
</dependency>
</dependencies>
</plugin>
```

## Rename of JUnit module

Expand Down
75 changes: 75 additions & 0 deletions migration/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright Java Operator SDK Authors

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

http://www.apache.org/licenses/LICENSE-2.0

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.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.javaoperatorsdk</groupId>
<artifactId>java-operator-sdk</artifactId>
<version>5.3.1-SNAPSHOT</version>
</parent>

<artifactId>migration</artifactId>
<name>Operator SDK - Migration Recipes</name>
<description>OpenRewrite migration recipes for Java Operator SDK</description>

<properties>
<openrewrite.version>8.46.1</openrewrite.version>
</properties>

<dependencies>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java</artifactId>
<version>${openrewrite.version}</version>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-maven</artifactId>
<version>${openrewrite.version}</version>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-test</artifactId>
<version>${openrewrite.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java-17</artifactId>
<version>${openrewrite.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright Java Operator SDK Authors
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 io.javaoperatorsdk.operator.migration;

import org.openrewrite.ExecutionContext;
import org.openrewrite.Option;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.MethodMatcher;
import org.openrewrite.java.tree.J;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class RemoveMethodDeclaration extends Recipe {

@Option(
displayName = "Method pattern",
description = "A method pattern used to find matching method declarations.",
example = "com.example.Foo bar(..)")
private final String methodPattern;

@JsonCreator
public RemoveMethodDeclaration(@JsonProperty("methodPattern") String methodPattern) {
this.methodPattern = methodPattern;
}

@Override
public String getDisplayName() {
return "Remove method declaration";
}

@Override
public String getDescription() {
return "Removes method declarations matching the given method pattern.";
}

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
var matcher = new MethodMatcher(methodPattern, true);
return new JavaIsoVisitor<>() {
@Override
public J.MethodDeclaration visitMethodDeclaration(
J.MethodDeclaration method, ExecutionContext ctx) {
if (method.getMethodType() != null && matcher.matches(method.getMethodType())) {
//noinspection DataFlowIssue
return null;
}
var classDecl = getCursor().firstEnclosing(J.ClassDeclaration.class);
if (classDecl != null && matcher.matches(method, classDecl)) {
//noinspection DataFlowIssue
return null;
}
return super.visitMethodDeclaration(method, ctx);
}
};
}
}
108 changes: 108 additions & 0 deletions migration/src/main/resources/META-INF/rewrite/v5-3-migration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#
# Copyright Java Operator SDK Authors
#
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.
#

---
type: specs.openrewrite.org/v1beta/recipe
name: io.javaoperatorsdk.operator.migration.V5_3Migration
displayName: Migrate to Java Operator SDK v5.3
description: >-
Migrates Java Operator SDK from v5.2 to v5.3, including the JUnit module
rename and Metrics interface method renames.
recipeList:
- io.javaoperatorsdk.operator.migration.UpgradeJOSDKVersion
- io.javaoperatorsdk.operator.migration.RenameJUnitModule
- io.javaoperatorsdk.operator.migration.MetricsMethodRenames
- io.javaoperatorsdk.operator.migration.RemoveMonitorSizeOf
---
type: specs.openrewrite.org/v1beta/recipe
name: io.javaoperatorsdk.operator.migration.UpgradeJOSDKVersion
displayName: Upgrade Java Operator SDK version to 5.3.0
description: >-
Upgrades all io.javaoperatorsdk dependencies from 5.2.x to 5.3.0.
recipeList:
- org.openrewrite.maven.UpgradeDependencyVersion:
groupId: io.javaoperatorsdk
artifactId: "*"
newVersion: 5.3.0
versionPattern: "5.2.*"
---
type: specs.openrewrite.org/v1beta/recipe
name: io.javaoperatorsdk.operator.migration.RenameJUnitModule
displayName: Rename JUnit module artifact
description: >-
Renames the operator-framework-junit-5 artifact to operator-framework-junit.
recipeList:
- org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId:
oldGroupId: io.javaoperatorsdk
oldArtifactId: operator-framework-junit-5
newArtifactId: operator-framework-junit
newVersion: 5.3.0
---
type: specs.openrewrite.org/v1beta/recipe
name: io.javaoperatorsdk.operator.migration.MetricsMethodRenames
displayName: Rename Metrics interface methods
description: >-
Renames methods on the Metrics interface to match the new v5.3 API.
recipeList:
- org.openrewrite.java.ChangeMethodName:
methodPattern: "io.javaoperatorsdk.operator.api.monitoring.Metrics reconcileCustomResource(..)"
newMethodName: reconciliationSubmitted
matchOverrides: true
- org.openrewrite.java.ChangeMethodName:
methodPattern: "io.javaoperatorsdk.operator.api.monitoring.Metrics reconciliationExecutionStarted(..)"
newMethodName: reconciliationStarted
matchOverrides: true
- org.openrewrite.java.ChangeMethodName:
methodPattern: "io.javaoperatorsdk.operator.api.monitoring.Metrics reconciliationExecutionFinished(..)"
newMethodName: reconciliationSucceeded
matchOverrides: true
- org.openrewrite.java.ChangeMethodName:
methodPattern: "io.javaoperatorsdk.operator.api.monitoring.Metrics failedReconciliation(..)"
newMethodName: reconciliationFailed
matchOverrides: true
- org.openrewrite.java.AddMethodParameter:
methodPattern: "io.javaoperatorsdk.operator.api.monitoring.Metrics reconciliationFailed(..)"
parameterType: io.javaoperatorsdk.operator.api.reconciler.RetryInfo
parameterName: retryInfo
parameterIndex: 1
- org.openrewrite.java.ChangeMethodName:
methodPattern: "io.javaoperatorsdk.operator.api.monitoring.Metrics finishedReconciliation(..)"
newMethodName: reconciliationFinished
matchOverrides: true
- org.openrewrite.java.AddMethodParameter:
methodPattern: "io.javaoperatorsdk.operator.api.monitoring.Metrics reconciliationFinished(..)"
parameterType: io.javaoperatorsdk.operator.api.reconciler.RetryInfo
parameterName: retryInfo
parameterIndex: 1
- org.openrewrite.java.ChangeMethodName:
methodPattern: "io.javaoperatorsdk.operator.api.monitoring.Metrics cleanupDoneFor(..)"
newMethodName: cleanupDone
matchOverrides: true
- org.openrewrite.java.ChangeMethodName:
methodPattern: "io.javaoperatorsdk.operator.api.monitoring.Metrics receivedEvent(..)"
newMethodName: eventReceived
matchOverrides: true
---
type: specs.openrewrite.org/v1beta/recipe
name: io.javaoperatorsdk.operator.migration.RemoveMonitorSizeOf
displayName: Remove monitorSizeOf method
description: >-
Removes the monitorSizeOf method declarations and invocations which were removed in v5.3.
recipeList:
- org.openrewrite.java.RemoveMethodInvocations:
methodPattern: "io.javaoperatorsdk.operator.api.monitoring.Metrics monitorSizeOf(..)"
- io.javaoperatorsdk.operator.migration.RemoveMethodDeclaration:
methodPattern: "io.javaoperatorsdk.operator.api.monitoring.Metrics monitorSizeOf(..)"
Loading
Loading