-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into java_toolchain_21
- Loading branch information
Showing
18 changed files
with
1,076 additions
and
457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/org/openrewrite/java/migrate/RemovedSecurityManagerMethods.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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.java.migrate; | ||
|
||
import org.openrewrite.ExecutionContext; | ||
import org.openrewrite.Recipe; | ||
import org.openrewrite.TreeVisitor; | ||
import org.openrewrite.java.JavaTemplate; | ||
import org.openrewrite.java.JavaVisitor; | ||
import org.openrewrite.java.MethodMatcher; | ||
import org.openrewrite.java.tree.J; | ||
|
||
public class RemovedSecurityManagerMethods extends Recipe { | ||
@Override | ||
public String getDisplayName() { | ||
return "Replace deprecated methods in`SecurityManager`"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Replace `SecurityManager` methods `checkAwtEventQueueAccess()`, `checkSystemClipboardAccess()`," + | ||
" `checkMemberAccess()` and `checkTopLevelWindow()` deprecated in Java SE 11 by" + | ||
" `checkPermission(new java.security.AllPermission())`."; | ||
} | ||
|
||
@Override | ||
public TreeVisitor<?, ExecutionContext> getVisitor() { | ||
return new JavaVisitor<ExecutionContext>() { | ||
private final MethodMatcher METHOD_PATTERN_QUE = new MethodMatcher("java.lang.SecurityManager checkAwtEventQueueAccess()", false); | ||
private final MethodMatcher METHOD_PATTERN_CLIP = new MethodMatcher("java.lang.SecurityManager checkSystemClipboardAccess()", false); | ||
private final MethodMatcher METHOD_PATTERN_MEMBER = new MethodMatcher("java.lang.SecurityManager checkMemberAccess(..)", false); | ||
private final MethodMatcher METHOD_PATTERN_WINDOW = new MethodMatcher("java.lang.SecurityManager checkTopLevelWindow(..)", false); | ||
|
||
@Override | ||
public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { | ||
if (METHOD_PATTERN_QUE.matches(method) || METHOD_PATTERN_CLIP.matches(method) || METHOD_PATTERN_MEMBER.matches(method) || METHOD_PATTERN_WINDOW.matches(method)) { | ||
return JavaTemplate.builder("checkPermission(new java.security.AllPermission())") | ||
.imports("java.security.AllPermission") | ||
.build().apply(updateCursor(method), | ||
method.getCoordinates().replaceMethod()); | ||
} | ||
return method; | ||
} | ||
}; | ||
} | ||
} |
72 changes: 0 additions & 72 deletions
72
src/main/java/org/openrewrite/java/migrate/jakarta/MaybeAddJakartaServletApi.java
This file was deleted.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
src/main/java/org/openrewrite/java/migrate/javax/AddDefaultConstructorToEntityClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* 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.java.migrate.javax; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import org.openrewrite.*; | ||
import org.openrewrite.java.JavaIsoVisitor; | ||
import org.openrewrite.java.JavaTemplate; | ||
import org.openrewrite.java.search.FindAnnotations; | ||
import org.openrewrite.java.search.UsesType; | ||
import org.openrewrite.java.tree.J; | ||
|
||
import java.util.Comparator; | ||
|
||
@EqualsAndHashCode(callSuper = false) | ||
public class AddDefaultConstructorToEntityClass extends Recipe { | ||
@Override | ||
public String getDisplayName() { | ||
return "`@Entity` objects with constructors must also have a default constructor"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "When a Java Persistence API (JPA) entity class has a constructor with arguments, the class must also " + | ||
"have a default, no-argument constructor. The OpenJPA implementation automatically generates the " + | ||
"no-argument constructor, but the EclipseLink implementation does not."; | ||
} | ||
|
||
@Override | ||
public TreeVisitor<?, ExecutionContext> getVisitor() { | ||
return Preconditions.check( | ||
Preconditions.or( | ||
new UsesType<>("javax.persistence.Entity", true), | ||
new UsesType<>("javax.persistence.MappedSuperclass", true)), | ||
new JavaIsoVisitor<ExecutionContext>() { | ||
@Override | ||
public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) { | ||
// Exit if class not annotated with either @Entity or @MappedSuperclass | ||
if (FindAnnotations.find(classDecl, "javax.persistence.Entity").isEmpty() | ||
&& FindAnnotations.find(classDecl, "javax.persistence.MappedSuperclass").isEmpty()) { | ||
return classDecl; | ||
} | ||
|
||
// Exit if class already has default no-arg constructor | ||
if (classDecl.getBody().getStatements().stream() | ||
.filter(statement -> statement instanceof J.MethodDeclaration) | ||
.map(J.MethodDeclaration.class::cast) | ||
.filter(J.MethodDeclaration::isConstructor) | ||
.anyMatch(constructor -> constructor.getParameters().get(0) instanceof J.Empty)) { | ||
return classDecl; | ||
} | ||
|
||
// Add default constructor with empty body | ||
return classDecl.withBody(JavaTemplate.builder("public #{}(){}") | ||
.contextSensitive() | ||
.build() | ||
.apply(new Cursor(getCursor(), classDecl.getBody()), | ||
classDecl.getBody().getCoordinates().firstStatement(), | ||
classDecl.getSimpleName() | ||
) | ||
); | ||
} | ||
} | ||
); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/resources/META-INF/rewrite/add-common-annotations-dependencies.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# | ||
# 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. | ||
# | ||
--- | ||
type: specs.openrewrite.org/v1beta/recipe | ||
name: org.openrewrite.java.migrate.javax.AddCommonAnnotationsDependencies | ||
displayName: Add explicit Common Annotations dependencies | ||
description: > | ||
Add the necessary `annotation-api` dependency from Jakarta EE 8 to maintain compatibility with Java version 11 or greater. | ||
tags: | ||
- javax | ||
- java11 | ||
- jsr250 | ||
- jakarta | ||
recipeList: | ||
# Add or update the jakarta.annotation-api to a maven project. This artifact still uses the javax.annotation name space. | ||
- org.openrewrite.java.dependencies.ChangeDependency: | ||
oldGroupId: javax.annotation | ||
oldArtifactId: javax.annotation-api | ||
newGroupId: jakarta.annotation | ||
newArtifactId: jakarta.annotation-api | ||
newVersion: 1.3.x | ||
- org.openrewrite.java.dependencies.AddDependency: | ||
groupId: jakarta.annotation | ||
artifactId: jakarta.annotation-api | ||
version: 1.3.x | ||
onlyIfUsing: javax.annotation..* | ||
acceptTransitive: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.