Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 4 new Java 11 recipes #300

Merged
merged 8 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
76 changes: 76 additions & 0 deletions src/main/resources/META-INF/rewrite/ibm-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#
# Copyright 2023 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.IBMSemeru
displayName: Migrate to IBM Semeru Runtimes
description: >
This recipe will apply changes commonly needed when upgrading Java versions. The solutions provided in this list are
solutions only availible in IBM Semeru Runtimes.
tags:
- java11
recipeList:
- org.openrewrite.java.migrate.JREDoNotUseSunNetSslInternalWwwProtocolHttpsHandler
- org.openrewrite.java.migrate.JREDoNotUseSunNetSslInternalWwwProtocol
- org.openrewrite.java.migrate.JREDoNotUseSunNetSslInternalSslProvider

---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.JREDoNotUseSunNetSslInternalWwwProtocolHttpsHandler
displayName: Use `com.ibm.net.ssl.www2.protocol.https.Handler` instead of `com.sun.net.ssl.internal.www.protocol.https.Handler`
description: Do not use the com.sun.net.ssl.internal.www.protocol.https.Handler class.
timtebeek marked this conversation as resolved.
Show resolved Hide resolved
tags:
- java11
recipeList:
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.sun.net.ssl.internal.www.protocol.https.Handler
newFullyQualifiedTypeName: com.ibm.net.ssl.www2.protocol.https.Handler
ignoreDefinition: true
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.JREDoNotUseSunNetSslInternalWwwProtocol
displayName: Use `com.ibm.net.ssl.www2.protocol` instead of `com.sun.net.ssl.internal.www.protocol`
description: Do not use the com.sun.net.ssl.internal.www.protocol package.
timtebeek marked this conversation as resolved.
Show resolved Hide resolved
tags:
- java11
recipeList:
- org.openrewrite.java.migrate.ReplaceStringLiteralValue:
oldLiteralValue: com.sun.net.ssl.internal.www.protocol
newLiteralValue: com.ibm.net.ssl.www2.protocol
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.JREDoNotUseSunNetSslInternalSslProvider
displayName: Use `com.ibm.jsse2` instead of `com.sun.net.ssl.internal.ssl`
description: Do not use the com.sun.net.ssl.internal.ssl.Provider class.
timtebeek marked this conversation as resolved.
Show resolved Hide resolved
tags:
- java11
recipeList:
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.sun.net.ssl.internal.ssl.Provider
newFullyQualifiedTypeName: com.ibm.jsse2.IBMJSSEProvider2
ignoreDefinition: true
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.sun.net.ssl.internal.ssl.Debug
newFullyQualifiedTypeName: com.ibm.jsse2.Debug
ignoreDefinition: true
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.sun.net.ssl.internal.ssl.SSLServerSocketFactoryImpl
newFullyQualifiedTypeName: com.ibm.jsse2.SSLServerSocketFactoryImpl
ignoreDefinition: true
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl
newFullyQualifiedTypeName: com.ibm.jsse2.SSLSocketFactoryImpl
ignoreDefinition: true
26 changes: 25 additions & 1 deletion src/main/resources/META-INF/rewrite/java-version-11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ recipeList:
- org.openrewrite.java.migrate.util.OptionalNotEmptyToIsPresent
- org.openrewrite.github.SetupJavaUpgradeJavaVersion:
minimumJavaMajorVersion: 11
- org.openrewrite.java.migrate.InternalBindContextFactory

---
type: specs.openrewrite.org/v1beta/recipe
Expand Down Expand Up @@ -196,4 +197,27 @@ recipeList:
groupPattern: com.sun.xml.ws
artifactPattern: "*"
onlyIfVersionsMatch: true

---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.InternalBindContextFactory
displayName: Use `com.sun.xml.bind.v2.ContextFactory` instead of `com.sun.xml.internal.bind.v2.ContextFactory`
description: Do not use the com.sun.xml.internal.bind.v2.ContextFactory class.
timtebeek marked this conversation as resolved.
Show resolved Hide resolved
tags:
- java11
recipeList:
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.sun.xml.internal.bind.v2.ContextFactory
newFullyQualifiedTypeName: com.sun.xml.bind.v2.ContextFactory
ignoreDefinition: true
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.JREDoNotUseSunNetSslInternalWwwProtocolHttpsHandler
displayName: Use `com.ibm.net.ssl.www2.protocol.https.Handler` instead of `com.sun.net.ssl.internal.www.protocol.https.Handler`
description: Do not use the com.sun.net.ssl.internal.www.protocol.https.Handler class.
tags:
- java11
recipeList:
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.sun.net.ssl.internal.www.protocol.https.Handler
newFullyQualifiedTypeName: com.ibm.net.ssl.www2.protocol.https.Handler
ignoreDefinition: true
timtebeek marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
/*
* Copyright 2023 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.junit.jupiter.api.Test;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.config.Environment;
import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import static org.openrewrite.java.Assertions.java;

class UpgradeSunJavaToJava11Test implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
spec
.parser(JavaParser.fromJavaVersion()
.classpathFromResources(new InMemoryExecutionContext(), "sun.internal"))
.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.migrate").build()
.activateRecipes("org.openrewrite.java.migrate.Java8toJava11", "org.openrewrite.java.migrate.IBMSemeru"));
}

@Test
void testInternalBindContextFactory() {
//language=java
rewriteRun(
java(
"""
public class TestInternalBindContextFactoryAPIs {
public void testInternalBindContextFactory() {
com.sun.xml.internal.bind.v2.ContextFactory contextFactory = null;
contextFactory.hashCode();
}
}
""",
"""
public class TestInternalBindContextFactoryAPIs {
public void testInternalBindContextFactory() {
com.sun.xml.bind.v2.ContextFactory contextFactory = null;
contextFactory.hashCode();
}
}
"""
),
java(
"""
import com.sun.xml.internal.bind.v2.ContextFactory;
public class TestInternalBindContextFactoryAPIs2 {
public void testInternalBindContextFactory() {
ContextFactory factory = null;
factory.hashCode();
}
}
""",
"""
import com.sun.xml.bind.v2.ContextFactory;
public class TestInternalBindContextFactoryAPIs2 {
public void testInternalBindContextFactory() {
ContextFactory factory = null;
factory.hashCode();
}
}
"""
),
java(
"""
import com.sun.xml.internal.bind.v2.*;
public class TestInternalBindContextFactoryAPIs3 {
public void testInternalBindContextFactory() {
ContextFactory factory = null;
factory.hashCode();
}
}
""",
"""
import com.sun.xml.bind.v2.ContextFactory;
import com.sun.xml.internal.bind.v2.*;
public class TestInternalBindContextFactoryAPIs3 {
public void testInternalBindContextFactory() {
ContextFactory factory = null;
factory.hashCode();
}
}
"""
)
);
}

@Test
void testJREDoNotUseSunNetSslInternalWwwProtocolHttpsHandler() {
rewriteRun(
//language=java
java(
"""
package com.test;
import com.sun.net.ssl.internal.www.protocol.https.*; //do NOT flag this
public class TestClass_1{
public static void main(String[] args) {
com.sun.net.ssl.internal.www.protocol.https.Handler handler_1 = //flag
new com.sun.net.ssl.internal.www.protocol.https.Handler(); //flag
Handler handler_2 = new Handler("String", 1); //flag (2)
testMethod(handler_1);
testMethod(handler_2);
if (handler_1 instanceof com.sun.net.ssl.internal.www.protocol.https.Handler){ //flag
//do nothing
}
if (handler_1 instanceof Handler){ //flag
//do nothing
}
}
public static com.sun.net.ssl.internal.www.protocol.https.Handler testMethod(Handler handler){ //flag (2)
return handler;
}
}
""",
"""
package com.test;
import com.ibm.net.ssl.www2.protocol.https.Handler;
import com.sun.net.ssl.internal.www.protocol.https.*; //do NOT flag this
public class TestClass_1{
public static void main(String[] args) {
com.ibm.net.ssl.www2.protocol.https.Handler handler_1 = //flag
new com.ibm.net.ssl.www2.protocol.https.Handler(); //flag
Handler handler_2 = new Handler("String", 1); //flag (2)
testMethod(handler_1);
testMethod(handler_2);
if (handler_1 instanceof com.ibm.net.ssl.www2.protocol.https.Handler){ //flag
//do nothing
}
if (handler_1 instanceof Handler){ //flag
//do nothing
}
}
public static com.ibm.net.ssl.www2.protocol.https.Handler testMethod(Handler handler){ //flag (2)
return handler;
}
}
"""
)
);
}

@Test
void testJREDoNotUseSunNetSslInternalWwwProtocol() {
rewriteRun(
//language=java
java(
"""
package com.test;
public class TestClass_1{
private String flagMe = "com.sun.net.ssl.internal.www.protocol"; //flag this
public static void main(String[] args) {
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); //flag this
String s1 = "com.sun.net.ssl"; //DO NOT FLAG
String s2 = "com.sun.net.ssl.internal"; //DO NOT FLAG
String s3 = "com.sun.net.ssl.internal.ssl"; //DO NOT FLAG
String s4 = "com.sun.net.ssl.internal.www"; //DO NOT FLAG
String s5 = "com.sun.net.ssl.internal.www.protocol"; //flag this
String s6 = "com.sun.net.ssl.internal.www.protocol.https"; //DO NOT FLAG
}
}
""",
"""
package com.test;
public class TestClass_1{
private String flagMe = "com.ibm.net.ssl.www2.protocol"; //flag this
public static void main(String[] args) {
System.setProperty("java.protocol.handler.pkgs", "com.ibm.net.ssl.www2.protocol"); //flag this
String s1 = "com.sun.net.ssl"; //DO NOT FLAG
String s2 = "com.sun.net.ssl.internal"; //DO NOT FLAG
String s3 = "com.sun.net.ssl.internal.ssl"; //DO NOT FLAG
String s4 = "com.sun.net.ssl.internal.www"; //DO NOT FLAG
String s5 = "com.ibm.net.ssl.www2.protocol"; //flag this
String s6 = "com.sun.net.ssl.internal.www.protocol.https"; //DO NOT FLAG
}
}
"""
)
);
}

@Test
void testJREDoNotUseSunNetSslInternalSslProvider() {
rewriteRun(
//language=java
java(
"""
import com.sun.net.ssl.internal.ssl.*; // do NOT flag, handled by other rule
public class TestClass_2{
public static void main(String[] args) {
Provider provider_4 = new Provider(); // flag (2)
}
private void fdsa( Provider p1 ){} // flag
}
""",
"""
import com.ibm.jsse2.IBMJSSEProvider2;
import com.sun.net.ssl.internal.ssl.*; // do NOT flag, handled by other rule
public class TestClass_2{
public static void main(String[] args) {
IBMJSSEProvider2 provider_4 = new IBMJSSEProvider2(); // flag (2)
}
private void fdsa( IBMJSSEProvider2 p1 ){} // flag
}
"""
)
);
}
}
Binary file not shown.
Loading