-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added 4 new Java 11 recipes --------- Co-authored-by: Tim te Beek <tim@moderne.io>
- Loading branch information
Showing
4 changed files
with
339 additions
and
1 deletion.
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
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. | ||
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. | ||
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. | ||
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 |
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
250 changes: 250 additions & 0 deletions
250
src/test/java/org/openrewrite/java/migrate/UpgradeSunJavaToJava11Test.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,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.