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
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: 25
java-version: 17
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to change this is open rewrite is jvm specific there is an issue with AbstractSyntaxtTree (AST) when having this on java 25. I'm pretty sure we could improve on these things regardin open rewite (like test with multiple java version but I don't have the bandwidth.

Note that all java versions are tested in integration tests

cache: 'maven'
- name: Check code format
run: |
Expand Down
5 changes: 5 additions & 0 deletions docs/content/en/blog/releases/v5-3-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ checks.

`reconciliationFinished(..)` is extended with `RetryInfo`. `monitorSizeOf(..)` is removed.

### `ResourceAction` relocated

`ResourceAction` in `io.javaoperatorsdk.operator.processing.event.source.controller` has been
removed. Use `io.javaoperatorsdk.operator.processing.event.source.ResourceAction` instead.

See the full [migration guide](/docs/migration/v5-3-migration) for details.

## Getting Started
Expand Down
32 changes: 31 additions & 1 deletion 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 Expand Up @@ -48,4 +72,10 @@ The following table shows the relevant method renames:

Other changes:
- `reconciliationFinished(..)` method is extended with `RetryInfo`
- `monitorSizeOf(..)` method is removed.
- `monitorSizeOf(..)` method is removed.

## ResourceAction relocation

The `ResourceAction` enum has been removed from
`io.javaoperatorsdk.operator.processing.event.source.controller` use the one in package
`io.javaoperatorsdk.operator.processing.event.source.ResourceAction`; thus update your imports accordingly.
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,150 @@
/*
* 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 java.util.Objects;

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

public class RemoveMethodDeclaration extends Recipe {

@Option(
displayName = "Interface name",
description = "Fully qualified or simple name of the interface.",
example = "com.example.YourInterface")
String interfaceName;

@Option(
displayName = "Method name",
description = "Name of the method to remove.",
example = "removedMethod")
String methodName;

@Override
public String getDisplayName() {
return "Remove obsolete method from implementing classes";
}

@Override
public @NlsRewrite.Description String getDescription() {
return "Remove obsolete method from implementing classes";
}

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new JavaIsoVisitor<ExecutionContext>() {

@Override
public J.ClassDeclaration visitClassDeclaration(
J.ClassDeclaration classDecl, ExecutionContext ctx) {
J.ClassDeclaration cd = super.visitClassDeclaration(classDecl, ctx);

if (cd.getType() == null || !typeMatchesOrImplements(cd.getType())) {
return cd;
}

// Mutate the type info in place to remove the method from the declared methods list,
// so all AST nodes sharing this type reference stay consistent.
var type = cd.getType();
if (type instanceof JavaType.Class classType) {
var updatedMethods =
classType.getMethods().stream().filter(m -> !m.getName().equals(methodName)).toList();
classType.unsafeSet(
classType.getTypeParameters(),
classType.getSupertype(),
classType.getOwningClass(),
classType.getAnnotations(),
classType.getInterfaces(),
classType.getMembers(),
updatedMethods);
}

return cd;
}

@Override
public J.MethodDeclaration visitMethodDeclaration(
J.MethodDeclaration method, ExecutionContext ctx) {
if (!method.getSimpleName().equals(methodName)) {
return super.visitMethodDeclaration(method, ctx);
}

J.ClassDeclaration classDecl = getCursor().firstEnclosing(J.ClassDeclaration.class);
if (classDecl == null || classDecl.getType() == null) {
return super.visitMethodDeclaration(method, ctx);
}

if (typeMatchesOrImplements(classDecl.getType())) {
//noinspection DataFlowIssue
return null;
}

return super.visitMethodDeclaration(method, ctx);
}

private boolean typeMatchesOrImplements(JavaType.FullyQualified type) {
for (var iface : type.getInterfaces()) {
if (iface.getFullyQualifiedName().equals(interfaceName)
|| typeMatchesOrImplements(iface)) {
return true;
}
}
var supertype = type.getSupertype();
if (supertype != null && !supertype.getFullyQualifiedName().equals("java.lang.Object")) {
return typeMatchesOrImplements(supertype);
}
return false;
}
};
}

public String getInterfaceName() {
return interfaceName;
}

public void setInterfaceName(String interfaceName) {
this.interfaceName = interfaceName;
}

public String getMethodName() {
return methodName;
}

public void setMethodName(String methodName) {
this.methodName = methodName;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
RemoveMethodDeclaration that = (RemoveMethodDeclaration) o;
return Objects.equals(interfaceName, that.interfaceName)
&& Objects.equals(methodName, that.methodName);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), interfaceName, methodName);
}
}
Loading
Loading