From d744c8d92472d0e912ec6420994d7c5b1ee60245 Mon Sep 17 00:00:00 2001 From: cjobinabo Date: Thu, 3 Aug 2023 17:27:53 -0500 Subject: [PATCH 01/12] 7 added was to liberty recipes --- .vscode/settings.json | 5 + .../main/META-INF/rewrite/category.yml | 4 + bin/main/META-INF/rewrite/was-to-liberty.yml | 131 +++++++ build.gradle.kts | 5 +- gradlew-e | 240 +++++++++++++ .../java/liberty/ChangeMethodInvocation.java | 189 +++++++++++ .../java/liberty/ChangeStringLiteral.java | 91 +++++ ...emoveWas2LibertyNonPortableJndiLookup.java | 86 +++++ .../xml/liberty/ChangeNamespaceValue.java | 152 +++++++++ .../liberty/PersistenceXmlLocationRule.java | 128 +++++++ .../META-INF/rewrite/was-to-liberty.yml | 131 +++++++ .../liberty/InvalidInitialContextTest.java | 86 +++++ ...eWas2LibertyNonPortableJndiLookupTest.java | 70 ++++ .../java/liberty/ServerNameTest.java | 110 ++++++ .../xml/liberty/AppDDNamespaceTest.java | 292 ++++++++++++++++ .../xml/liberty/ConnectorDDNamespaceTest.java | 224 ++++++++++++ .../xml/liberty/EJBDDNamespaceTest.java | 320 ++++++++++++++++++ .../PersistenceXmlLocationRuleTest.java | 53 +++ .../xml/liberty/WebDDNamespaceTest.java | 152 +++++++++ 19 files changed, 2468 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json rename src/main/resources/META-INF/rewrite/openliberty-23.yml => bin/main/META-INF/rewrite/category.yml (76%) create mode 100644 bin/main/META-INF/rewrite/was-to-liberty.yml create mode 100755 gradlew-e create mode 100644 src/main/java/org/openrewrite/java/liberty/ChangeMethodInvocation.java create mode 100644 src/main/java/org/openrewrite/java/liberty/ChangeStringLiteral.java create mode 100644 src/main/java/org/openrewrite/java/liberty/RemoveWas2LibertyNonPortableJndiLookup.java create mode 100644 src/main/java/org/openrewrite/xml/liberty/ChangeNamespaceValue.java create mode 100644 src/main/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRule.java create mode 100644 src/main/resources/META-INF/rewrite/was-to-liberty.yml create mode 100644 src/test/java/org/openrewrite/java/liberty/InvalidInitialContextTest.java create mode 100644 src/test/java/org/openrewrite/java/liberty/RemoveWas2LibertyNonPortableJndiLookupTest.java create mode 100644 src/test/java/org/openrewrite/java/liberty/ServerNameTest.java create mode 100644 src/test/java/org/openrewrite/xml/liberty/AppDDNamespaceTest.java create mode 100644 src/test/java/org/openrewrite/xml/liberty/ConnectorDDNamespaceTest.java create mode 100644 src/test/java/org/openrewrite/xml/liberty/EJBDDNamespaceTest.java create mode 100644 src/test/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRuleTest.java create mode 100644 src/test/java/org/openrewrite/xml/liberty/WebDDNamespaceTest.java diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..144146e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "java.compile.nullAnalysis.mode": "automatic", + "java.configuration.updateBuildConfiguration": "automatic", + "java.debug.settings.onBuildFailureProceed": true +} \ No newline at end of file diff --git a/src/main/resources/META-INF/rewrite/openliberty-23.yml b/bin/main/META-INF/rewrite/category.yml similarity index 76% rename from src/main/resources/META-INF/rewrite/openliberty-23.yml rename to bin/main/META-INF/rewrite/category.yml index bef3968..76270f0 100644 --- a/src/main/resources/META-INF/rewrite/openliberty-23.yml +++ b/bin/main/META-INF/rewrite/category.yml @@ -15,3 +15,7 @@ # --- +type: specs.openrewrite.org/v1beta/category +name: Open Liberty +packageName: org.openrewrite.liberty +description: Recipes to perform [Open Liberty](https://openliberty.io/) migration tasks. diff --git a/bin/main/META-INF/rewrite/was-to-liberty.yml b/bin/main/META-INF/rewrite/was-to-liberty.yml new file mode 100644 index 0000000..8c6fcd8 --- /dev/null +++ b/bin/main/META-INF/rewrite/was-to-liberty.yml @@ -0,0 +1,131 @@ +# +# Copyright 2023 the original author or 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 +#

+# https://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. +# + +######################################################################################################################## +# WebSphere traditional to Liberty +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.liberty +displayName: Migrate from WebSphere traditional to Liberty +description: > + Use this category of rules to identify code changes needed when migrating + from WebSphere Application Server traditional to Liberty. +recipeList: + - org.openrewrite.java.liberty.RemoveWas2LibertyNonPortableJndiLookup + - org.openrewrite.java.liberty.ServerName + - org.openrewrite.xml.liberty.AppDDNamespaceRule + - org.openrewrite.xml.liberty.ConnectorDDNamespaceRule + - org.openrewrite.xml.liberty.EJBDDNamespaceRule + - org.openrewrite.xml.liberty.PersistenceXmlLocationRule + - org.openrewrite.xml.liberty.WebDDNamespaceRule +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.liberty.RemoveWas2LibertyNonPortableJndiLookup +recipeList: + - org.openrewrite.java.liberty.RemoveWas2LibertyNonPortableJndiLookup +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.liberty.ServerName +recipeList: + - org.openrewrite.java.liberty.ChangeMethodInvocation: + methodPattern: com.ibm.websphere.runtime.ServerName getDisplayName() + newMethodPattern: java.lang.System getProperty("wlp.server.name") + performStaticCall: true + - org.openrewrite.java.liberty.ChangeMethodInvocation: + methodPattern: com.ibm.websphere.runtime.ServerName getFullName() + newMethodPattern: java.lang.System getProperty("wlp.server.name") + performStaticCall: true +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.xml.liberty.AppDDNamespaceRule +recipeList: + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: application + attributeName: xmlns + newValue: http://java.sun.com/xml/ns/j2ee + versionMatcher: 1.4 + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: application + attributeName: xmlns + newValue: http://java.sun.com/xml/ns/javaee + versionMatcher: 5,6 + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: application + attributeName: xmlns + newValue: http://xmlns.jcp.org/xml/ns/javaee + versionMatcher: 7+ +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.xml.liberty.ConnectorDDNamespaceRule +recipeList: + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: connector + attributeName: xmlns + newValue: http://java.sun.com/xml/ns/j2ee + versionMatcher: 1.5 + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: connector + attributeName: xmlns + newValue: http://java.sun.com/xml/ns/javaee + versionMatcher: 1.6 + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: connector + attributeName: xmlns + newValue: http://xmlns.jcp.org/xml/ns/javaee + versionMatcher: 1.7+ +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.xml.liberty.EJBDDNamespaceRule +recipeList: + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: ejb-jar + attributeName: xmlns + newValue: http://java.sun.com/xml/ns/j2ee + versionMatcher: 2.1 + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: ejb-jar + attributeName: xmlns + newValue: http://java.sun.com/xml/ns/javaee + versionMatcher: 3.0,3.1 + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: ejb-jar + attributeName: xmlns + newValue: http://xmlns.jcp.org/xml/ns/javaee + versionMatcher: 3.2+ +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.xml.liberty.PersistenceXmlLocationRule +recipeList: + - org.openrewrite.xml.liberty.PersistenceXmlLocationRule +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.xml.liberty.WebDDNamespaceRule +recipeList: + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: web-app + attributeName: xmlns + newValue: http://java.sun.com/xml/ns/j2ee + versionMatcher: 2.4 + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: web-app + attributeName: xmlns + newValue: http://java.sun.com/xml/ns/java + versionMatcher: 2.5,3.0 + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: web-app + attributeName: xmlns + newValue: http://xmlns.jcp.org/xml/ns/javaee + versionMatcher: 3.1+ diff --git a/build.gradle.kts b/build.gradle.kts index 18e9ddd..8b06c28 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { } group = "org.openrewrite.recipe" -description = "Open Liberty Migration" +description = "Recipes to migrate to the IBM WebSphere Liberty. Automatically." val rewriteVersion = rewriteRecipe.rewriteVersion.get() dependencies { @@ -12,6 +12,9 @@ dependencies { implementation("org.openrewrite:rewrite-java") implementation("org.openrewrite.recipe:rewrite-java-dependencies") implementation("org.openrewrite.recipe:rewrite-migrate-java") + implementation("org.openrewrite.recipe:rewrite-static-analysis") + //implementation("org.openrewrite.recipe:rewrite-xml") + implementation("org.openrewrite.recipe:rewrite-static-analysis") testImplementation("org.openrewrite:rewrite-java-17") testImplementation("org.openrewrite:rewrite-test") diff --git a/gradlew-e b/gradlew-e new file mode 100755 index 0000000..e405e77 --- /dev/null +++ b/gradlew-e @@ -0,0 +1,240 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original 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 +# +# https://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. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/src/main/java/org/openrewrite/java/liberty/ChangeMethodInvocation.java b/src/main/java/org/openrewrite/java/liberty/ChangeMethodInvocation.java new file mode 100644 index 0000000..82db0f1 --- /dev/null +++ b/src/main/java/org/openrewrite/java/liberty/ChangeMethodInvocation.java @@ -0,0 +1,189 @@ +/* + * Copyright 2023 the original author or 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 + *

+ * https://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 org.openrewrite.java.liberty; + +import lombok.EqualsAndHashCode; +import lombok.Value; + +import java.util.Collections; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.openrewrite.*; +import org.openrewrite.internal.lang.NonNull; +import org.openrewrite.internal.lang.Nullable; +import org.openrewrite.java.JavaTemplate; +import org.openrewrite.java.JavaVisitor; +import org.openrewrite.java.MethodMatcher; +import org.openrewrite.java.tree.*; +import org.openrewrite.java.tree.JavaType.FullyQualified; +import org.openrewrite.marker.Markers; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/* + Development in this class is not complete +*/ +@Value +@EqualsAndHashCode(callSuper = true) +public class ChangeMethodInvocation extends Recipe { + + @Option(displayName = "Method pattern", + description = "A method pattern that is used to find matching method invocations.", + example = "org.mockito.Matchers anyVararg()") + @NonNull + String methodPattern; + + @Option(displayName = "New method name", + description = "The method name that will replace the existing name.", + example = "org.mockito.Matchers any()") + @NonNull + String newMethodPattern; + + @Option(displayName = "Perform static methd call", + description = "When set to `true` the method invocation will be performed statically.", + example = "true", + required = false) + @Nullable + Boolean performStaticCall; + + @JsonCreator + public ChangeMethodInvocation(@NonNull @JsonProperty("methodPattern") String methodPattern, + @NonNull @JsonProperty("newMethodPattern") String newMethodPattern, @Nullable @JsonProperty("performStaticCall") Boolean performStaticCall) { + this.methodPattern = methodPattern; + this.newMethodPattern = newMethodPattern; + this.performStaticCall = performStaticCall; + } + + + @Override + public String getDisplayName() { + return "Change method invocation"; + } + + @Override + public String getDescription() { + return "Rename a method invocation."; + } + + @Override + public boolean causesAnotherCycle() { + return true; + } + + @Override + public TreeVisitor getVisitor() { + return new ChangeMethodInvocationVisitor(new MethodMatcher(methodPattern, false), newMethodPattern); + } + + private class ChangeMethodInvocationVisitor extends JavaVisitor { + private final MethodMatcher methodMatcher; + private MethodMatcher methodReplacmentMatcher; + private String oldMethodType; + + private String newMethodType; + private String newMethodOwnerName; + private String newMethodName; + private String newMethodsArgsStr; + + Pattern methodPatternMatcher = Pattern.compile("([^\\s]+)\\s+([a-zA-Z0-9]+)\\((.*)\\)"); + + private ChangeMethodInvocationVisitor(MethodMatcher methodMatcher, String newMethodPattern) { + this.methodMatcher = methodMatcher; + this.oldMethodType = methodMatcher.getTargetTypePattern().pattern().replace("[.$]", "."); + + if (newMethodPattern != null) { + Matcher m = methodPatternMatcher.matcher(newMethodPattern); + if(m.find()) { + this.newMethodType = m.group(1); + if(this.newMethodType != null) { + String[] parts = this.newMethodType.split("\\."); + this.newMethodOwnerName = parts[parts.length-1]; + } + + this.newMethodName = m.group(2); + this.newMethodsArgsStr = m.group(3); + if(this.newMethodsArgsStr != null) { + StringBuilder newArgs = new StringBuilder(); + int argSize = newMethodsArgsStr.split(",").length; + for(int i=1; i <= argSize; i++) { + newArgs.append("*"); + if (i < argSize) { + newArgs.append(","); + } + } + this.methodReplacmentMatcher = new MethodMatcher(newMethodPattern.replace(this.newMethodsArgsStr, newArgs), false); + } else { + this.newMethodsArgsStr = ""; + this.methodReplacmentMatcher = new MethodMatcher(newMethodPattern, false); + } + } + } + } + + @Override + public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { + J.MethodInvocation m = method; + + if (methodReplacmentMatcher != null && methodMatcher.matches(method) && !methodReplacmentMatcher.matches(method)) { + if (performStaticCall) { + String temp = newMethodType+"."+newMethodName+"("+newMethodsArgsStr+");"; + JavaTemplate addArgTemplate = JavaTemplate.builder(temp).build(); + J.MethodInvocation qualifiedInvocation = addArgTemplate.apply(getCursor(), m.getCoordinates().replace()); + + temp = newMethodOwnerName+"."+newMethodName+"("+newMethodsArgsStr+");"; + addArgTemplate = JavaTemplate.builder(temp).build(); + J.MethodInvocation simpleInvocation = addArgTemplate.apply(getCursor(), m.getCoordinates().replace()); + + m = simpleInvocation.withMethodType(qualifiedInvocation.getMethodType()); + m = m.withSelect(m.getSelect().withType(qualifiedInvocation.getSelect().getType())); + + maybeAddImport(m.getMethodType().getDeclaringType().getFullyQualifiedName(), false); + maybeRemoveImport(oldMethodType); + } else { + // This block of code is not complete + JavaType.Method type = m.getMethodType(); + if (type != null) { + type = type.withName(newMethodName); + FullyQualified declaringType = type.getDeclaringType(); + String previousMethodType = declaringType.getFullyQualifiedName(); + declaringType = declaringType.withFullyQualifiedName(newMethodType); + type = type.withDeclaringType(declaringType); + + //add new import and remove old if no longer used + maybeAddImport(newMethodType); + maybeRemoveImport(previousMethodType); + } + m = m.withName(m.getName().withSimpleName(newMethodName)) + .withMethodType(type); + + if(this.newMethodsArgsStr == null) { + // clear arguments + List methodArgs = Collections.singletonList(new J.Empty(Tree.randomId(), Space.EMPTY, Markers.EMPTY)); + m = m.withArguments(methodArgs); + } else { + // override arguments + JavaTemplate addArgTemplate = JavaTemplate.builder( newMethodsArgsStr).build(); + m = addArgTemplate.apply(getCursor(), m.getCoordinates().replaceArguments()); + } + } + } + return m; + } + } +} diff --git a/src/main/java/org/openrewrite/java/liberty/ChangeStringLiteral.java b/src/main/java/org/openrewrite/java/liberty/ChangeStringLiteral.java new file mode 100644 index 0000000..f3fd297 --- /dev/null +++ b/src/main/java/org/openrewrite/java/liberty/ChangeStringLiteral.java @@ -0,0 +1,91 @@ +/* + * Copyright 2023 the original author or 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 + *

+ * https://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 org.openrewrite.java.liberty; + +import lombok.EqualsAndHashCode; +import lombok.Value; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.openrewrite.ExecutionContext; +import org.openrewrite.Option; +import org.openrewrite.Recipe; +import org.openrewrite.TreeVisitor; +import org.openrewrite.internal.lang.NonNull; +import org.openrewrite.java.JavaIsoVisitor; +import org.openrewrite.java.tree.*; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +@Value +@EqualsAndHashCode(callSuper = true) +public class ChangeStringLiteral extends Recipe { + + @Option(displayName = "Value pattern", + description = "A pattern that is used to find matching string literal.", + example = "java:(.*)") + @NonNull + String valuePattern; + + @Option(displayName = "New value template", + description = "The template that will replace the existing value.", + example = "org:$1") + @NonNull + String newValueTemplate; + + @JsonCreator + public ChangeStringLiteral(@NonNull @JsonProperty("valuePattern") String valuePattern, @NonNull @JsonProperty("newValueTemplate") String newValueTemplate) { + this.valuePattern = valuePattern; + this.newValueTemplate = newValueTemplate; + } + + + @Override + public String getDisplayName() { + return "Change string literal"; + } + + @Override + public String getDescription() { + return "Changes the value of a string literal."; + } + + @Override + public TreeVisitor getVisitor() { + return new ChangeStringLiteralVisitor<> (Pattern.compile(valuePattern), newValueTemplate); + } + + @Value + @EqualsAndHashCode(callSuper = true) + public class ChangeStringLiteralVisitor

extends JavaIsoVisitor

{ + Pattern valuePattern; + String newValueTemplate; + + @Override + public J.Literal visitLiteral(J.Literal literal, P p) { + String literalValue = literal.getValue().toString(); + Matcher m = valuePattern.matcher(literalValue); + if (m.find()) { + literalValue = m.replaceFirst(newValueTemplate); + literal = literal.withValue(literalValue).withValueSource(literalValue); + } + return literal; + } + } + +} \ No newline at end of file diff --git a/src/main/java/org/openrewrite/java/liberty/RemoveWas2LibertyNonPortableJndiLookup.java b/src/main/java/org/openrewrite/java/liberty/RemoveWas2LibertyNonPortableJndiLookup.java new file mode 100644 index 0000000..53a2c54 --- /dev/null +++ b/src/main/java/org/openrewrite/java/liberty/RemoveWas2LibertyNonPortableJndiLookup.java @@ -0,0 +1,86 @@ +/* + * Copyright 2023 the original author or 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 + *

+ * https://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 org.openrewrite.java.liberty; + +import java.util.function.Supplier; + +import org.openrewrite.internal.lang.Nullable; +import org.openrewrite.ExecutionContext; +import org.openrewrite.Recipe; +import org.openrewrite.TreeVisitor; +import org.openrewrite.java.JavaVisitor; +import org.openrewrite.java.MethodMatcher; +import org.openrewrite.java.tree.Expression; +import org.openrewrite.java.tree.J; +import org.openrewrite.java.tree.MethodCall; + +public class RemoveWas2LibertyNonPortableJndiLookup extends Recipe { + + @Override + public String getDisplayName() { + return "Removes invalid JNDI properties"; + } + + @Override + public String getDescription() { + return "Remove the use of invalid JNDI properties from Hashtable."; + } + + @Override + public TreeVisitor getVisitor() { + return new MethodInvocationVisitor(); + } + + private class MethodInvocationVisitor extends JavaVisitor { + MethodMatcher methodMatcher = new MethodMatcher("java.util.Hashtable put(java.lang.Object, java.lang.Object)", false); + + @SuppressWarnings("NullableProblems") + @Nullable + @Override + public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ec) { + return visitMethodCall(method); + } + + @Nullable + private M visitMethodCall(M methodCall) { + if (!methodMatcher.matches(methodCall)) { + return methodCall; + } + J.Block parentBlock = getCursor().firstEnclosing(J.Block.class); + //noinspection SuspiciousMethodCalls + if (parentBlock != null && !parentBlock.getStatements().contains(methodCall)) { + return methodCall; + } + // Remove the method invocation when the argumentMatcherPredicate is true for all arguments + Expression firstArg = methodCall.getArguments().get(0); + if (firstArg instanceof J.Literal) { + J.Literal literalExp = (J.Literal) firstArg; + Object value = literalExp.getValue(); + if(!value.equals("java.naming.factory.initial") && !value.equals("java.naming.provider.url")) { + return methodCall; + } + } else { + return methodCall; + } + + if (methodCall.getMethodType() != null) { + maybeRemoveImport(methodCall.getMethodType().getDeclaringType()); + } + return null; + } + } + +} diff --git a/src/main/java/org/openrewrite/xml/liberty/ChangeNamespaceValue.java b/src/main/java/org/openrewrite/xml/liberty/ChangeNamespaceValue.java new file mode 100644 index 0000000..4bda817 --- /dev/null +++ b/src/main/java/org/openrewrite/xml/liberty/ChangeNamespaceValue.java @@ -0,0 +1,152 @@ +/* + * Copyright 2023 the original author or 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 + *

+ * https://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 org.openrewrite.xml.liberty; + +import org.openrewrite.*; +import org.openrewrite.internal.ListUtils; +import org.openrewrite.xml.XPathMatcher; +import org.openrewrite.xml.XmlVisitor; +import org.openrewrite.xml.tree.Xml; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.openrewrite.internal.lang.NonNull; +import org.openrewrite.internal.lang.Nullable; + +import lombok.EqualsAndHashCode; +import lombok.Value; + +@Value +@EqualsAndHashCode(callSuper = true) +public class ChangeNamespaceValue extends Recipe { + + @Override + public String getDisplayName() { + return "Change XML Attribute of a specific resource version"; + } + + @Override + public String getDescription() { + return "Alters XML Attribute value within specified element of a specific resource versions."; + } + + @Option(displayName = "Element name", + description = "The name of the element whose attribute's value is to be changed. Interpreted as an XPath Expression.", + example = "property") + String elementName; + + @Option(displayName = "Attribute name", + description = "The name of the attribute whose value is to be changed.", + example = "name") + String attributeName; + + @Option(displayName = "New value", + description = "The new value to be used for key specified by `attributeName`, Set to null if you want to remove the attribute.", + example = "newfoo.bar.attribute.value.string") + @Nullable + String newValue; + + @Option(displayName = "Resource version", + description = "The version of resource to change", + example = "1.1") + String versionMatcher; + + + @JsonCreator + public ChangeNamespaceValue(@NonNull @JsonProperty("elementName") String elementName, @NonNull @JsonProperty("attributeName") String attributeName, + @Nullable @JsonProperty("newValue") String newValue, @Nullable @JsonProperty("versionMatcher") String versionMatcher) { + this.elementName = elementName; + this.attributeName = attributeName; + this.newValue = newValue; + this.versionMatcher = versionMatcher; + } + + @Override + public TreeVisitor getVisitor() { + return new XmlVisitor() { + + String version = null; + + @Override + public Xml visitTag(Xml.Tag tag, ExecutionContext ctx) { + Xml.Tag t = (Xml.Tag) super.visitTag(tag, ctx); + this.version = null; + if (new XPathMatcher(elementName).matches(getCursor())) { + // find versions + t = t.withAttributes(ListUtils.map(t.getAttributes(), this::visitChosenElementAttribute)); + } + + if(this.version != null) { + //change namespace + t = t.withAttributes(ListUtils.map(t.getAttributes(), this::visitChosenElementAttribute)); + } + return t; + } + + public boolean matchesVersion() { + String[] versions = versionMatcher.split(","); + double dversion = Double.parseDouble(this.version); + for(String splitVersion: versions) { + boolean checkGreaterThan = false; + double dversionExpected; + if(splitVersion.endsWith("+")) { + splitVersion = splitVersion.substring(0, splitVersion.length()-1); + checkGreaterThan = true; + } + try { + dversionExpected = Double.parseDouble(splitVersion); + } catch(NumberFormatException e) { + return false; + } + if (!checkGreaterThan && dversionExpected == dversion || checkGreaterThan && dversionExpected <= dversion) { + return true; + } + } + return false; + } + + public Xml.Attribute visitChosenElementAttribute(Xml.Attribute attribute) { + if(this.version == null && !attribute.getKeyAsString().equals("version")) { + return attribute; + } + + if(this.version != null && !attribute.getKeyAsString().equals(attributeName)) { + return attribute; + } + + if(this.version != null && matchesVersion()) { + if (newValue == null) { + //noinspection DataFlowIssue + return null; + } + + String changedValue = newValue; + return attribute.withValue( + new Xml.Attribute.Value(attribute.getId(), + "", + attribute.getMarkers(), + attribute.getValue().getQuote(), + changedValue)); + } else { + this.version = attribute.getValueAsString(); + return attribute; + } + } + }; + } + +} diff --git a/src/main/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRule.java b/src/main/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRule.java new file mode 100644 index 0000000..815b700 --- /dev/null +++ b/src/main/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRule.java @@ -0,0 +1,128 @@ +/* + * Copyright 2023 the original author or 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 + *

+ * https://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 org.openrewrite.xml.liberty; +import org.openrewrite.internal.lang.Nullable; +import org.openrewrite.java.marker.JavaProject; + +import org.openrewrite.ExecutionContext; +import org.openrewrite.Recipe; +import org.openrewrite.SourceFile; +import org.openrewrite.Tree; +import org.openrewrite.TreeVisitor; + +import java.io.File; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +public class PersistenceXmlLocationRule extends Recipe { + + @Override + public String getDisplayName() { + return "Move persistence.xml file."; + } + + @Override + public String getDescription() { + return "This recipes moves persistence.xml files into the root META-INF directory in source folder."; + } + + public File getProjectDirectory(File sourceFile, String projectName) { + File parent = sourceFile.getParentFile(); + while(parent != null && !parent.getName().equals(projectName)) { + parent = parent.getParentFile(); + } + + return parent; + } + + public List getSrcDirectories(SourceFile sourceFile) { + List srcDirs = new ArrayList(); + Path sourcePath = sourceFile.getSourcePath(); + + String projectName = sourceFile.getMarkers() + .findFirst(JavaProject.class) + .map(JavaProject::getProjectName) + .orElse(""); + + File projectDirctory = getProjectDirectory(new File(sourcePath.toAbsolutePath().toString()), projectName); + if(projectDirctory != null) { + File[] subDirs = projectDirctory.listFiles(File::isDirectory); + if(subDirs != null) { + for (File subDir: subDirs) { + String dirName = subDir.getName().toLowerCase(); + if(dirName.endsWith("src") || dirName.equals("source")) { + srcDirs.add(subDir); + } + } + } + } + + return srcDirs; + } + + @Override + public TreeVisitor getVisitor() { + return new TreeVisitor() { + @Nullable + @Override + public Tree visit(@Nullable Tree tree, ExecutionContext executionContext) { + if (tree instanceof SourceFile) { + SourceFile sourceFile = ((SourceFile) tree); + + Path sourcePath = ((SourceFile) tree).getSourcePath(); + if(sourcePath.getFileName().toString().equals("persistence.xml")) { + String projectName = sourceFile.getMarkers() + .findFirst(JavaProject.class) + .map(JavaProject::getProjectName) + .orElse(""); + + List srcDirs = getSrcDirectories(sourceFile); + boolean isValidPath = false; + boolean correctFileExists = false; + Path correctPath = null; + if(!srcDirs.isEmpty()) { + for(File srcDir: srcDirs) { + correctPath = srcDir.toPath().resolve("META-INF").resolve("persistence.xml"); + if(sourcePath.toAbsolutePath().equals(correctPath.toAbsolutePath())) { + isValidPath = true; + break; + } + + if(correctPath.toFile().exists()) { + correctFileExists = true; + } + } + } else { + if(!sourcePath.toAbsolutePath().endsWith("src"+File.separator+"META-INF"+File.separator+"persistence.xml")) { + File projectFile = getProjectDirectory(new File(sourcePath.toAbsolutePath().toString()), projectName); + correctPath = projectFile.toPath().resolve("src").resolve("META-INF").resolve("persistence.xml"); + return ((SourceFile) tree).withSourcePath(correctPath); + } + } + + if(!isValidPath && !correctFileExists && correctPath != null) { + return ((SourceFile) tree).withSourcePath(correctPath); + } else { + return sourceFile; + } + } + } + return super.visit(tree, executionContext); + } + }; + } +} \ No newline at end of file diff --git a/src/main/resources/META-INF/rewrite/was-to-liberty.yml b/src/main/resources/META-INF/rewrite/was-to-liberty.yml new file mode 100644 index 0000000..8c6fcd8 --- /dev/null +++ b/src/main/resources/META-INF/rewrite/was-to-liberty.yml @@ -0,0 +1,131 @@ +# +# Copyright 2023 the original author or 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 +#

+# https://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. +# + +######################################################################################################################## +# WebSphere traditional to Liberty +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.liberty +displayName: Migrate from WebSphere traditional to Liberty +description: > + Use this category of rules to identify code changes needed when migrating + from WebSphere Application Server traditional to Liberty. +recipeList: + - org.openrewrite.java.liberty.RemoveWas2LibertyNonPortableJndiLookup + - org.openrewrite.java.liberty.ServerName + - org.openrewrite.xml.liberty.AppDDNamespaceRule + - org.openrewrite.xml.liberty.ConnectorDDNamespaceRule + - org.openrewrite.xml.liberty.EJBDDNamespaceRule + - org.openrewrite.xml.liberty.PersistenceXmlLocationRule + - org.openrewrite.xml.liberty.WebDDNamespaceRule +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.liberty.RemoveWas2LibertyNonPortableJndiLookup +recipeList: + - org.openrewrite.java.liberty.RemoveWas2LibertyNonPortableJndiLookup +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.liberty.ServerName +recipeList: + - org.openrewrite.java.liberty.ChangeMethodInvocation: + methodPattern: com.ibm.websphere.runtime.ServerName getDisplayName() + newMethodPattern: java.lang.System getProperty("wlp.server.name") + performStaticCall: true + - org.openrewrite.java.liberty.ChangeMethodInvocation: + methodPattern: com.ibm.websphere.runtime.ServerName getFullName() + newMethodPattern: java.lang.System getProperty("wlp.server.name") + performStaticCall: true +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.xml.liberty.AppDDNamespaceRule +recipeList: + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: application + attributeName: xmlns + newValue: http://java.sun.com/xml/ns/j2ee + versionMatcher: 1.4 + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: application + attributeName: xmlns + newValue: http://java.sun.com/xml/ns/javaee + versionMatcher: 5,6 + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: application + attributeName: xmlns + newValue: http://xmlns.jcp.org/xml/ns/javaee + versionMatcher: 7+ +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.xml.liberty.ConnectorDDNamespaceRule +recipeList: + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: connector + attributeName: xmlns + newValue: http://java.sun.com/xml/ns/j2ee + versionMatcher: 1.5 + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: connector + attributeName: xmlns + newValue: http://java.sun.com/xml/ns/javaee + versionMatcher: 1.6 + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: connector + attributeName: xmlns + newValue: http://xmlns.jcp.org/xml/ns/javaee + versionMatcher: 1.7+ +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.xml.liberty.EJBDDNamespaceRule +recipeList: + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: ejb-jar + attributeName: xmlns + newValue: http://java.sun.com/xml/ns/j2ee + versionMatcher: 2.1 + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: ejb-jar + attributeName: xmlns + newValue: http://java.sun.com/xml/ns/javaee + versionMatcher: 3.0,3.1 + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: ejb-jar + attributeName: xmlns + newValue: http://xmlns.jcp.org/xml/ns/javaee + versionMatcher: 3.2+ +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.xml.liberty.PersistenceXmlLocationRule +recipeList: + - org.openrewrite.xml.liberty.PersistenceXmlLocationRule +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.xml.liberty.WebDDNamespaceRule +recipeList: + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: web-app + attributeName: xmlns + newValue: http://java.sun.com/xml/ns/j2ee + versionMatcher: 2.4 + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: web-app + attributeName: xmlns + newValue: http://java.sun.com/xml/ns/java + versionMatcher: 2.5,3.0 + - org.openrewrite.xml.liberty.ChangeNamespaceValue: + elementName: web-app + attributeName: xmlns + newValue: http://xmlns.jcp.org/xml/ns/javaee + versionMatcher: 3.1+ diff --git a/src/test/java/org/openrewrite/java/liberty/InvalidInitialContextTest.java b/src/test/java/org/openrewrite/java/liberty/InvalidInitialContextTest.java new file mode 100644 index 0000000..b5b193b --- /dev/null +++ b/src/test/java/org/openrewrite/java/liberty/InvalidInitialContextTest.java @@ -0,0 +1,86 @@ +/* + * Copyright 2023 the original author or 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 + *

+ * https://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 org.openrewrite.java.liberty; + +import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.java.Assertions.java; + +public class InvalidInitialContextTest implements RewriteTest { + + String initialContextClass = """ + package javax.naming; + + public class InitialContext { + + public InitialContext() { + } + + public void lookup() { + } + + } + """; + + @Test + void replaceTimeoutTest() { + rewriteRun( + spec -> spec.recipe(new ChangeStringLiteral("^java:/comp(.*)$", "java:comp$1")), + java(initialContextClass), + java( + """ + package com.test; + + import javax.naming.InitialContext; + import javax.naming.NamingException; + + public class TestDetectInvalidInitialContext { + public static final String BAD_ENV = "java:/comp"; + public static final String GOOD_ENV = "java:comp"; + + private void doX(){ + InitialContext ic = new InitialContext(); + ic.lookup("java:/comp"); + ic.lookup("java:/comp/BadEntry"); + ic.lookup("java:comp/GoodEntry"); + } + } + """, + """ + package com.test; + + import javax.naming.InitialContext; + import javax.naming.NamingException; + + public class TestDetectInvalidInitialContext { + public static final String BAD_ENV = java:comp; + public static final String GOOD_ENV = "java:comp"; + + private void doX(){ + InitialContext ic = new InitialContext(); + ic.lookup(java:comp); + ic.lookup(java:comp/BadEntry); + ic.lookup("java:comp/GoodEntry"); + } + } + """ + ) + ); + } + +} diff --git a/src/test/java/org/openrewrite/java/liberty/RemoveWas2LibertyNonPortableJndiLookupTest.java b/src/test/java/org/openrewrite/java/liberty/RemoveWas2LibertyNonPortableJndiLookupTest.java new file mode 100644 index 0000000..3a51b45 --- /dev/null +++ b/src/test/java/org/openrewrite/java/liberty/RemoveWas2LibertyNonPortableJndiLookupTest.java @@ -0,0 +1,70 @@ +/* + * Copyright 2023 the original author or 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 + *

+ * https://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 org.openrewrite.java.liberty; + +import org.junit.jupiter.api.Test; +import org.openrewrite.config.Environment; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.java.Assertions.java; + +public class RemoveWas2LibertyNonPortableJndiLookupTest implements RewriteTest { + + @Test + void removeInvalidPropertiesTest() { + rewriteRun( + spec -> spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.java.liberty.RemoveWas2LibertyNonPortableJndiLookup")), + java( + """ + package com.ibm; + + import java.util.Hashtable; + import javax.naming.InitialContext; + + public class ServerNameUsage { + + public void doX() { + Hashtable ht = new Hashtable(); + ht.put("java.naming.factory.initial", "com.ibm.websphere.naming.WsnInitialContextFactory"); + ht.put("java.naming.provider.url", "corbaloc:iiop:localhost:2809"); + + InitialContext ctx = new InitialContext(ht); + } + + } + """, + """ + package com.ibm; + + import java.util.Hashtable; + import javax.naming.InitialContext; + + public class ServerNameUsage { + + public void doX() { + Hashtable ht = new Hashtable(); + + InitialContext ctx = new InitialContext(ht); + } + + } + """ + ) + ); + } + +} diff --git a/src/test/java/org/openrewrite/java/liberty/ServerNameTest.java b/src/test/java/org/openrewrite/java/liberty/ServerNameTest.java new file mode 100644 index 0000000..c2173b2 --- /dev/null +++ b/src/test/java/org/openrewrite/java/liberty/ServerNameTest.java @@ -0,0 +1,110 @@ +/* + * Copyright 2023 the original author or 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 + *

+ * https://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 org.openrewrite.java.liberty; + +import org.junit.jupiter.api.Test; +import org.openrewrite.config.Environment; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.java.Assertions.java; + +public class ServerNameTest implements RewriteTest { + + String serverNameClass = """ + package com.ibm.websphere.runtime; + + public class ServerName { + + public static String getDisplayName() { + return ""; + } + + public static String getFullName() { + return ""; + } + + } + """; + + @Test + void replaceGetFullNameTest() { + rewriteRun( + spec -> spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.java.liberty.ServerName")), + java(serverNameClass), + java( + """ + package com.ibm; + + import com.ibm.websphere.runtime.ServerName; + + public class ServerNameUsage { + + public void doX() { + ServerName.getFullName(); + } + + } + """, + """ + package com.ibm; + + public class ServerNameUsage { + + public void doX() { + System.getProperty("wlp.server.name"); + } + + } + """ + ) + ); + } + + @Test + void replaceGetDisplayNameTest() { + rewriteRun( + spec -> spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.java.liberty.ServerName")), + java(serverNameClass), + java( + """ + package com.ibm; + + import com.ibm.websphere.runtime.ServerName; + + public class ServerNameUsage { + + public void doX() { + ServerName.getDisplayName(); + } + + } + """, + """ + package com.ibm; + + public class ServerNameUsage { + + public void doX() { + System.getProperty("wlp.server.name"); + } + + } + """ + ) + ); + } +} diff --git a/src/test/java/org/openrewrite/xml/liberty/AppDDNamespaceTest.java b/src/test/java/org/openrewrite/xml/liberty/AppDDNamespaceTest.java new file mode 100644 index 0000000..43c778b --- /dev/null +++ b/src/test/java/org/openrewrite/xml/liberty/AppDDNamespaceTest.java @@ -0,0 +1,292 @@ +/* + * Copyright 2023 the original author or 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 + *

+ * https://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 org.openrewrite.xml.liberty; + +import org.junit.jupiter.api.Test; +import org.openrewrite.config.Environment; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.xml.Assertions.xml; + +public class AppDDNamespaceTest implements RewriteTest { + @Override + public void defaults(RecipeSpec spec) { + spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.xml.liberty.AppDDNamespaceRule")); + } + + @Test + void replaceVersion14Test() { + rewriteRun( + xml( + """ + + DayTrader Stock Trading Performance Benchmark Sample + Trade + + daytrader-streamer-1.0.jar + + + daytrader-wsappclient-1.0.jar + + + + daytrader-web-1.0.war + /daytrader + + + + daytrader-ejb-1.0.jar + + + """, + """ + + DayTrader Stock Trading Performance Benchmark Sample + Trade + + daytrader-streamer-1.0.jar + + + daytrader-wsappclient-1.0.jar + + + + daytrader-web-1.0.war + /daytrader + + + + daytrader-ejb-1.0.jar + + + """ + ) + ); + } + + @Test + void replaceVersion5Test() { + rewriteRun( + xml( + """ + + + + test-client.jar + + + + test-ejb.jar + + + + + test.war + test + + + + lib + + """, + """ + + + + test-client.jar + + + + test-ejb.jar + + + + + test.war + test + + + + lib + + """ + ) + ); + } + + @Test + void replaceVersion6Test() { + rewriteRun( + xml( + """ + + + + test-client.jar + + + + test-ejb.jar + + + + + test.war + test + + + + lib + + """, + """ + + + + test-client.jar + + + + test-ejb.jar + + + + + test.war + test + + + + lib + + """ + ) + ); + } + + @Test + void replaceVersion7Test() { + rewriteRun( + xml( + """ + + + test-app + true + + + test-web.war + test + + + + + test-ejb.jar + + lib + + """, + """ + + + test-app + true + + + test-web.war + test + + + + + test-ejb.jar + + lib + + """ + ) + ); + } + + @Test + void replaceVersion8Test() { + rewriteRun( + xml( + """ + + + test-app + true + + + test-web.war + test + + + + + test-ejb.jar + + lib + + """, + """ + + + test-app + true + + + test-web.war + test + + + + + test-ejb.jar + + lib + + """ + ) + ); + } +} + diff --git a/src/test/java/org/openrewrite/xml/liberty/ConnectorDDNamespaceTest.java b/src/test/java/org/openrewrite/xml/liberty/ConnectorDDNamespaceTest.java new file mode 100644 index 0000000..a385711 --- /dev/null +++ b/src/test/java/org/openrewrite/xml/liberty/ConnectorDDNamespaceTest.java @@ -0,0 +1,224 @@ +/* + * Copyright 2023 the original author or 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 + *

+ * https://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 org.openrewrite.xml.liberty; + +import org.junit.jupiter.api.Test; +import org.openrewrite.config.Environment; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.xml.Assertions.xml; + +public class ConnectorDDNamespaceTest implements RewriteTest { + @Override + public void defaults(RecipeSpec spec) { + spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.xml.liberty.ConnectorDDNamespaceRule")); + } + + @Test + void replaceVersion15Test() { + rewriteRun( + xml( + """ + + Generic JCA + adam-bien.com + Generic JCA + 1.0 + + + + ...genericjca.GenericManagedConnectionFactory + ...genericjca.DataSource + ...genericjca.FileDataSource + ...genericjca.Connection + ...genericjca.FileConnection + + LocalTransaction + + BasicPassword + javax.resource.spi.security.PasswordCredential + + false + + + + """, + """ + + Generic JCA + adam-bien.com + Generic JCA + 1.0 + + + + ...genericjca.GenericManagedConnectionFactory + ...genericjca.DataSource + ...genericjca.FileDataSource + ...genericjca.Connection + ...genericjca.FileConnection + + LocalTransaction + + BasicPassword + javax.resource.spi.security.PasswordCredential + + false + + + + """ + ) + ); + } + + @Test + void replaceVersion16Test() { + rewriteRun( + xml( + """ + + Generic JCA + adam-bien.com + Generic JCA + 1.0 + + + + ...genericjca.GenericManagedConnectionFactory + ...genericjca.DataSource + ...genericjca.FileDataSource + ...genericjca.Connection + ...genericjca.FileConnection + + LocalTransaction + + BasicPassword + javax.resource.spi.security.PasswordCredential + + false + + + + """, + """ + + Generic JCA + adam-bien.com + Generic JCA + 1.0 + + + + ...genericjca.GenericManagedConnectionFactory + ...genericjca.DataSource + ...genericjca.FileDataSource + ...genericjca.Connection + ...genericjca.FileConnection + + LocalTransaction + + BasicPassword + javax.resource.spi.security.PasswordCredential + + false + + + + """ + ) + ); + } + + @Test + void replaceVersion17Test() { + rewriteRun( + xml( + """ + + Generic JCA + adam-bien.com + Generic JCA + 1.0 + + + + ...genericjca.GenericManagedConnectionFactory + ...genericjca.DataSource + ...genericjca.FileDataSource + ...genericjca.Connection + ...genericjca.FileConnection + + LocalTransaction + + BasicPassword + javax.resource.spi.security.PasswordCredential + + false + + + + """, + """ + + Generic JCA + adam-bien.com + Generic JCA + 1.0 + + + + ...genericjca.GenericManagedConnectionFactory + ...genericjca.DataSource + ...genericjca.FileDataSource + ...genericjca.Connection + ...genericjca.FileConnection + + LocalTransaction + + BasicPassword + javax.resource.spi.security.PasswordCredential + + false + + + + """ + ) + ); + } +} + diff --git a/src/test/java/org/openrewrite/xml/liberty/EJBDDNamespaceTest.java b/src/test/java/org/openrewrite/xml/liberty/EJBDDNamespaceTest.java new file mode 100644 index 0000000..cb78afc --- /dev/null +++ b/src/test/java/org/openrewrite/xml/liberty/EJBDDNamespaceTest.java @@ -0,0 +1,320 @@ +/* + * Copyright 2023 the original author or 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 + *

+ * https://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 org.openrewrite.xml.liberty; + +import org.junit.jupiter.api.Test; +import org.openrewrite.config.Environment; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.xml.Assertions.xml; + +public class EJBDDNamespaceTest implements RewriteTest { + @Override + public void defaults(RecipeSpec spec) { + spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.xml.liberty.EJBDDNamespaceRule")); + } + + @Test + void replaceVersion21Test() { + rewriteRun( + xml( + """ + + + EchoEJBProject + + + EchoEJB + test.EchoEJBHome + test.EchoEJB + test.EchoEJB + test.EchoEJBBean + Stateless + Container + + + + """, + """ + + + EchoEJBProject + + + EchoEJB + test.EchoEJBHome + test.EchoEJB + test.EchoEJB + test.EchoEJBBean + Stateless + Container + + + + """ + ) + ); + } + + @Test + void replaceVersion30Test() { + rewriteRun( + xml( + """ + + + + TestBean + + ejb/fooremote + Session + test.FooRemoteIF + + + + + + + test.Interceptor1 + + + + + + * + test.Interceptor1 + + + + """, + """ + + + + TestBean + + ejb/fooremote + Session + test.FooRemoteIF + + + + + + + test.Interceptor1 + + + + + + * + test.Interceptor1 + + + + """ + ) + ); + } + + @Test + void replaceVersion31Test() { + rewriteRun( + xml( + """ + + + + TestBean + + ejb/fooremote + Session + test.FooRemoteIF + + + + + + + test.Interceptor1 + + + + + + * + test.Interceptor1 + + + + """, + """ + + + + TestBean + + ejb/fooremote + Session + test.FooRemoteIF + + + + + + + test.Interceptor1 + + + + + + * + test.Interceptor1 + + + + """ + ) + ); + } + + @Test + void replaceVersion32Test() { + rewriteRun( + xml( + """ + + Enterprise JavaBeans 3.1 + Enterprise JavaBeans 3.1 + + + WorkerBean + com.sample.ejb3.slsb.simple2.WorkerBusinessLocal + com.sample.ejb3.slsb.simple2.WorkerBusinessRemote + com.sample.ejb3.slsb.simple2.WorkerBase + Stateless + true + Container + + FILTER + java.lang.Long + 11011 + + + + + """, + """ + + Enterprise JavaBeans 3.1 + Enterprise JavaBeans 3.1 + + + WorkerBean + com.sample.ejb3.slsb.simple2.WorkerBusinessLocal + com.sample.ejb3.slsb.simple2.WorkerBusinessRemote + com.sample.ejb3.slsb.simple2.WorkerBase + Stateless + true + Container + + FILTER + java.lang.Long + 11011 + + + + + """ + ) + ); + } + + @Test + void replaceVersion33Test() { + rewriteRun( + xml( + """ + + Enterprise JavaBeans 3.1 + Enterprise JavaBeans 3.1 + + + WorkerBean + com.sample.ejb3.slsb.simple2.WorkerBusinessLocal + com.sample.ejb3.slsb.simple2.WorkerBusinessRemote + com.sample.ejb3.slsb.simple2.WorkerBase + Stateless + true + Container + + FILTER + java.lang.Long + 11011 + + + + + """, + """ + + Enterprise JavaBeans 3.1 + Enterprise JavaBeans 3.1 + + + WorkerBean + com.sample.ejb3.slsb.simple2.WorkerBusinessLocal + com.sample.ejb3.slsb.simple2.WorkerBusinessRemote + com.sample.ejb3.slsb.simple2.WorkerBase + Stateless + true + Container + + FILTER + java.lang.Long + 11011 + + + + + """ + ) + ); + } +} + diff --git a/src/test/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRuleTest.java b/src/test/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRuleTest.java new file mode 100644 index 0000000..3670ec7 --- /dev/null +++ b/src/test/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRuleTest.java @@ -0,0 +1,53 @@ +/* + * Copyright 2023 the original author or 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 + *

+ * https://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 org.openrewrite.xml.liberty; + +import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; +import org.openrewrite.config.Environment; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; +import java.nio.file.Paths; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.openrewrite.test.SourceSpecs.text; + +import static org.openrewrite.java.Assertions.*; + +public class PersistenceXmlLocationRuleTest implements RewriteTest { + @Override + public void defaults(RecipeSpec spec) { + spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.xml.liberty.PersistenceXmlLocationRule")); + } + + @DocumentExample + @Test + void movePersistenceXMLFileTest() { + rewriteRun( + text( + """ + + + + + """, + spec -> project(spec, "testEjbWithJpa").path("testEjbWithJpa/notsrc/META-INF/persistence.xml") + .afterRecipe(pt -> assertThat(pt.getSourcePath()).isEqualTo(Paths.get(System.getProperty("user.dir"), "testEjbWithJpa/src/META-INF/persistence.xml"))) + ) + ); + } +} diff --git a/src/test/java/org/openrewrite/xml/liberty/WebDDNamespaceTest.java b/src/test/java/org/openrewrite/xml/liberty/WebDDNamespaceTest.java new file mode 100644 index 0000000..824d1a1 --- /dev/null +++ b/src/test/java/org/openrewrite/xml/liberty/WebDDNamespaceTest.java @@ -0,0 +1,152 @@ +/* + * Copyright 2023 the original author or 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 + *

+ * https://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 org.openrewrite.xml.liberty; + +import org.junit.jupiter.api.Test; +import org.openrewrite.config.Environment; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.xml.Assertions.xml; + +public class WebDDNamespaceTest implements RewriteTest { + @Override + public void defaults(RecipeSpec spec) { + spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.xml.liberty.WebDDNamespaceRule")); + } + + @Test + void replaceVersion24Test() { + rewriteRun( + xml( + """ + + testWebDDNamespace + + """, + """ + + testWebDDNamespace + + """ + ) + ); + } + + @Test + void replaceVersion25Test() { + rewriteRun( + xml( + """ + + testWebDDNamespace + + """, + """ + + testWebDDNamespace + + """ + ) + ); + } + + @Test + void replaceVersion30Test() { + rewriteRun( + xml( + """ + + testWebDDNamespace + + """, + """ + + testWebDDNamespace + + """ + ) + ); + } + + @Test + void replaceVersion31Test() { + rewriteRun( + xml( + """ + + testWebDDNamespace + + """, + """ + + testWebDDNamespace + + """ + ) + ); + } + + @Test + void replaceVersion32Test() { + rewriteRun( + xml( + """ + + testWebDDNamespace + + """, + """ + + testWebDDNamespace + + """ + ) + ); + } +} + From 919da367742e737b0eaf300d87a0d35a868111e6 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Fri, 4 Aug 2023 17:21:11 +0200 Subject: [PATCH 02/12] Remove bin/ and .vscode/; Update .gitignore --- .gitignore | 4 +- .vscode/settings.json | 5 - bin/main/META-INF/rewrite/category.yml | 21 --- bin/main/META-INF/rewrite/was-to-liberty.yml | 131 ------------------- 4 files changed, 3 insertions(+), 158 deletions(-) delete mode 100644 .vscode/settings.json delete mode 100644 bin/main/META-INF/rewrite/category.yml delete mode 100644 bin/main/META-INF/rewrite/was-to-liberty.yml diff --git a/.gitignore b/.gitignore index 261a2e0..8d9638e 100644 --- a/.gitignore +++ b/.gitignore @@ -46,4 +46,6 @@ gradle-app.setting .classpath .idea/ -out/ \ No newline at end of file +out/ +bin/ +.vscode/ diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 144146e..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "java.compile.nullAnalysis.mode": "automatic", - "java.configuration.updateBuildConfiguration": "automatic", - "java.debug.settings.onBuildFailureProceed": true -} \ No newline at end of file diff --git a/bin/main/META-INF/rewrite/category.yml b/bin/main/META-INF/rewrite/category.yml deleted file mode 100644 index 76270f0..0000000 --- a/bin/main/META-INF/rewrite/category.yml +++ /dev/null @@ -1,21 +0,0 @@ -# -# Copyright 2023 the original author or 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 -#

-# https://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/category -name: Open Liberty -packageName: org.openrewrite.liberty -description: Recipes to perform [Open Liberty](https://openliberty.io/) migration tasks. diff --git a/bin/main/META-INF/rewrite/was-to-liberty.yml b/bin/main/META-INF/rewrite/was-to-liberty.yml deleted file mode 100644 index 8c6fcd8..0000000 --- a/bin/main/META-INF/rewrite/was-to-liberty.yml +++ /dev/null @@ -1,131 +0,0 @@ -# -# Copyright 2023 the original author or 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 -#

-# https://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. -# - -######################################################################################################################## -# WebSphere traditional to Liberty ---- -type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.java.liberty -displayName: Migrate from WebSphere traditional to Liberty -description: > - Use this category of rules to identify code changes needed when migrating - from WebSphere Application Server traditional to Liberty. -recipeList: - - org.openrewrite.java.liberty.RemoveWas2LibertyNonPortableJndiLookup - - org.openrewrite.java.liberty.ServerName - - org.openrewrite.xml.liberty.AppDDNamespaceRule - - org.openrewrite.xml.liberty.ConnectorDDNamespaceRule - - org.openrewrite.xml.liberty.EJBDDNamespaceRule - - org.openrewrite.xml.liberty.PersistenceXmlLocationRule - - org.openrewrite.xml.liberty.WebDDNamespaceRule ---- -type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.java.liberty.RemoveWas2LibertyNonPortableJndiLookup -recipeList: - - org.openrewrite.java.liberty.RemoveWas2LibertyNonPortableJndiLookup ---- -type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.java.liberty.ServerName -recipeList: - - org.openrewrite.java.liberty.ChangeMethodInvocation: - methodPattern: com.ibm.websphere.runtime.ServerName getDisplayName() - newMethodPattern: java.lang.System getProperty("wlp.server.name") - performStaticCall: true - - org.openrewrite.java.liberty.ChangeMethodInvocation: - methodPattern: com.ibm.websphere.runtime.ServerName getFullName() - newMethodPattern: java.lang.System getProperty("wlp.server.name") - performStaticCall: true ---- -type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.xml.liberty.AppDDNamespaceRule -recipeList: - - org.openrewrite.xml.liberty.ChangeNamespaceValue: - elementName: application - attributeName: xmlns - newValue: http://java.sun.com/xml/ns/j2ee - versionMatcher: 1.4 - - org.openrewrite.xml.liberty.ChangeNamespaceValue: - elementName: application - attributeName: xmlns - newValue: http://java.sun.com/xml/ns/javaee - versionMatcher: 5,6 - - org.openrewrite.xml.liberty.ChangeNamespaceValue: - elementName: application - attributeName: xmlns - newValue: http://xmlns.jcp.org/xml/ns/javaee - versionMatcher: 7+ ---- -type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.xml.liberty.ConnectorDDNamespaceRule -recipeList: - - org.openrewrite.xml.liberty.ChangeNamespaceValue: - elementName: connector - attributeName: xmlns - newValue: http://java.sun.com/xml/ns/j2ee - versionMatcher: 1.5 - - org.openrewrite.xml.liberty.ChangeNamespaceValue: - elementName: connector - attributeName: xmlns - newValue: http://java.sun.com/xml/ns/javaee - versionMatcher: 1.6 - - org.openrewrite.xml.liberty.ChangeNamespaceValue: - elementName: connector - attributeName: xmlns - newValue: http://xmlns.jcp.org/xml/ns/javaee - versionMatcher: 1.7+ ---- -type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.xml.liberty.EJBDDNamespaceRule -recipeList: - - org.openrewrite.xml.liberty.ChangeNamespaceValue: - elementName: ejb-jar - attributeName: xmlns - newValue: http://java.sun.com/xml/ns/j2ee - versionMatcher: 2.1 - - org.openrewrite.xml.liberty.ChangeNamespaceValue: - elementName: ejb-jar - attributeName: xmlns - newValue: http://java.sun.com/xml/ns/javaee - versionMatcher: 3.0,3.1 - - org.openrewrite.xml.liberty.ChangeNamespaceValue: - elementName: ejb-jar - attributeName: xmlns - newValue: http://xmlns.jcp.org/xml/ns/javaee - versionMatcher: 3.2+ ---- -type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.xml.liberty.PersistenceXmlLocationRule -recipeList: - - org.openrewrite.xml.liberty.PersistenceXmlLocationRule ---- -type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.xml.liberty.WebDDNamespaceRule -recipeList: - - org.openrewrite.xml.liberty.ChangeNamespaceValue: - elementName: web-app - attributeName: xmlns - newValue: http://java.sun.com/xml/ns/j2ee - versionMatcher: 2.4 - - org.openrewrite.xml.liberty.ChangeNamespaceValue: - elementName: web-app - attributeName: xmlns - newValue: http://java.sun.com/xml/ns/java - versionMatcher: 2.5,3.0 - - org.openrewrite.xml.liberty.ChangeNamespaceValue: - elementName: web-app - attributeName: xmlns - newValue: http://xmlns.jcp.org/xml/ns/javaee - versionMatcher: 3.1+ From 3147139a21d1584abb3e18c29c5f11a743cff845 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Fri, 4 Aug 2023 22:24:13 +0100 Subject: [PATCH 03/12] Delete gradlew-e --- gradlew-e | 240 ------------------------------------------------------ 1 file changed, 240 deletions(-) delete mode 100755 gradlew-e diff --git a/gradlew-e b/gradlew-e deleted file mode 100755 index e405e77..0000000 --- a/gradlew-e +++ /dev/null @@ -1,240 +0,0 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 the original 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 -# -# https://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. -# - -############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# -############################################################################## - -# Attempt to set APP_HOME - -# Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac -done - -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" -APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum - -warn () { - echo "$*" -} >&2 - -die () { - echo - echo "$*" - echo - exit 1 -} >&2 - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done -fi - -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" - -# Stop when "xargs" is not available. -if ! command -v xargs >/dev/null 2>&1 -then - die "xargs is not available" -fi - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" From dc19b108ea19c33c603a1c52815336c8f91f7158 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Wed, 9 Aug 2023 13:50:00 +0200 Subject: [PATCH 04/12] Adopt org.openrewrite.xml.ChangeNamespaceValue --- .../xml/liberty/ChangeNamespaceValue.java | 152 ------------------ .../META-INF/rewrite/was-to-liberty.yml | 24 +-- 2 files changed, 12 insertions(+), 164 deletions(-) delete mode 100644 src/main/java/org/openrewrite/xml/liberty/ChangeNamespaceValue.java diff --git a/src/main/java/org/openrewrite/xml/liberty/ChangeNamespaceValue.java b/src/main/java/org/openrewrite/xml/liberty/ChangeNamespaceValue.java deleted file mode 100644 index 4bda817..0000000 --- a/src/main/java/org/openrewrite/xml/liberty/ChangeNamespaceValue.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright 2023 the original author or 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 - *

- * https://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 org.openrewrite.xml.liberty; - -import org.openrewrite.*; -import org.openrewrite.internal.ListUtils; -import org.openrewrite.xml.XPathMatcher; -import org.openrewrite.xml.XmlVisitor; -import org.openrewrite.xml.tree.Xml; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -import org.openrewrite.internal.lang.NonNull; -import org.openrewrite.internal.lang.Nullable; - -import lombok.EqualsAndHashCode; -import lombok.Value; - -@Value -@EqualsAndHashCode(callSuper = true) -public class ChangeNamespaceValue extends Recipe { - - @Override - public String getDisplayName() { - return "Change XML Attribute of a specific resource version"; - } - - @Override - public String getDescription() { - return "Alters XML Attribute value within specified element of a specific resource versions."; - } - - @Option(displayName = "Element name", - description = "The name of the element whose attribute's value is to be changed. Interpreted as an XPath Expression.", - example = "property") - String elementName; - - @Option(displayName = "Attribute name", - description = "The name of the attribute whose value is to be changed.", - example = "name") - String attributeName; - - @Option(displayName = "New value", - description = "The new value to be used for key specified by `attributeName`, Set to null if you want to remove the attribute.", - example = "newfoo.bar.attribute.value.string") - @Nullable - String newValue; - - @Option(displayName = "Resource version", - description = "The version of resource to change", - example = "1.1") - String versionMatcher; - - - @JsonCreator - public ChangeNamespaceValue(@NonNull @JsonProperty("elementName") String elementName, @NonNull @JsonProperty("attributeName") String attributeName, - @Nullable @JsonProperty("newValue") String newValue, @Nullable @JsonProperty("versionMatcher") String versionMatcher) { - this.elementName = elementName; - this.attributeName = attributeName; - this.newValue = newValue; - this.versionMatcher = versionMatcher; - } - - @Override - public TreeVisitor getVisitor() { - return new XmlVisitor() { - - String version = null; - - @Override - public Xml visitTag(Xml.Tag tag, ExecutionContext ctx) { - Xml.Tag t = (Xml.Tag) super.visitTag(tag, ctx); - this.version = null; - if (new XPathMatcher(elementName).matches(getCursor())) { - // find versions - t = t.withAttributes(ListUtils.map(t.getAttributes(), this::visitChosenElementAttribute)); - } - - if(this.version != null) { - //change namespace - t = t.withAttributes(ListUtils.map(t.getAttributes(), this::visitChosenElementAttribute)); - } - return t; - } - - public boolean matchesVersion() { - String[] versions = versionMatcher.split(","); - double dversion = Double.parseDouble(this.version); - for(String splitVersion: versions) { - boolean checkGreaterThan = false; - double dversionExpected; - if(splitVersion.endsWith("+")) { - splitVersion = splitVersion.substring(0, splitVersion.length()-1); - checkGreaterThan = true; - } - try { - dversionExpected = Double.parseDouble(splitVersion); - } catch(NumberFormatException e) { - return false; - } - if (!checkGreaterThan && dversionExpected == dversion || checkGreaterThan && dversionExpected <= dversion) { - return true; - } - } - return false; - } - - public Xml.Attribute visitChosenElementAttribute(Xml.Attribute attribute) { - if(this.version == null && !attribute.getKeyAsString().equals("version")) { - return attribute; - } - - if(this.version != null && !attribute.getKeyAsString().equals(attributeName)) { - return attribute; - } - - if(this.version != null && matchesVersion()) { - if (newValue == null) { - //noinspection DataFlowIssue - return null; - } - - String changedValue = newValue; - return attribute.withValue( - new Xml.Attribute.Value(attribute.getId(), - "", - attribute.getMarkers(), - attribute.getValue().getQuote(), - changedValue)); - } else { - this.version = attribute.getValueAsString(); - return attribute; - } - } - }; - } - -} diff --git a/src/main/resources/META-INF/rewrite/was-to-liberty.yml b/src/main/resources/META-INF/rewrite/was-to-liberty.yml index 8c6fcd8..2397fb0 100644 --- a/src/main/resources/META-INF/rewrite/was-to-liberty.yml +++ b/src/main/resources/META-INF/rewrite/was-to-liberty.yml @@ -52,17 +52,17 @@ recipeList: type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.xml.liberty.AppDDNamespaceRule recipeList: - - org.openrewrite.xml.liberty.ChangeNamespaceValue: + - org.openrewrite.xml.ChangeNamespaceValue: elementName: application attributeName: xmlns newValue: http://java.sun.com/xml/ns/j2ee versionMatcher: 1.4 - - org.openrewrite.xml.liberty.ChangeNamespaceValue: + - org.openrewrite.xml.ChangeNamespaceValue: elementName: application attributeName: xmlns newValue: http://java.sun.com/xml/ns/javaee versionMatcher: 5,6 - - org.openrewrite.xml.liberty.ChangeNamespaceValue: + - org.openrewrite.xml.ChangeNamespaceValue: elementName: application attributeName: xmlns newValue: http://xmlns.jcp.org/xml/ns/javaee @@ -71,17 +71,17 @@ recipeList: type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.xml.liberty.ConnectorDDNamespaceRule recipeList: - - org.openrewrite.xml.liberty.ChangeNamespaceValue: + - org.openrewrite.xml.ChangeNamespaceValue: elementName: connector attributeName: xmlns newValue: http://java.sun.com/xml/ns/j2ee versionMatcher: 1.5 - - org.openrewrite.xml.liberty.ChangeNamespaceValue: + - org.openrewrite.xml.ChangeNamespaceValue: elementName: connector attributeName: xmlns newValue: http://java.sun.com/xml/ns/javaee versionMatcher: 1.6 - - org.openrewrite.xml.liberty.ChangeNamespaceValue: + - org.openrewrite.xml.ChangeNamespaceValue: elementName: connector attributeName: xmlns newValue: http://xmlns.jcp.org/xml/ns/javaee @@ -90,17 +90,17 @@ recipeList: type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.xml.liberty.EJBDDNamespaceRule recipeList: - - org.openrewrite.xml.liberty.ChangeNamespaceValue: + - org.openrewrite.xml.ChangeNamespaceValue: elementName: ejb-jar attributeName: xmlns newValue: http://java.sun.com/xml/ns/j2ee versionMatcher: 2.1 - - org.openrewrite.xml.liberty.ChangeNamespaceValue: + - org.openrewrite.xml.ChangeNamespaceValue: elementName: ejb-jar attributeName: xmlns newValue: http://java.sun.com/xml/ns/javaee versionMatcher: 3.0,3.1 - - org.openrewrite.xml.liberty.ChangeNamespaceValue: + - org.openrewrite.xml.ChangeNamespaceValue: elementName: ejb-jar attributeName: xmlns newValue: http://xmlns.jcp.org/xml/ns/javaee @@ -114,17 +114,17 @@ recipeList: type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.xml.liberty.WebDDNamespaceRule recipeList: - - org.openrewrite.xml.liberty.ChangeNamespaceValue: + - org.openrewrite.xml.ChangeNamespaceValue: elementName: web-app attributeName: xmlns newValue: http://java.sun.com/xml/ns/j2ee versionMatcher: 2.4 - - org.openrewrite.xml.liberty.ChangeNamespaceValue: + - org.openrewrite.xml.ChangeNamespaceValue: elementName: web-app attributeName: xmlns newValue: http://java.sun.com/xml/ns/java versionMatcher: 2.5,3.0 - - org.openrewrite.xml.liberty.ChangeNamespaceValue: + - org.openrewrite.xml.ChangeNamespaceValue: elementName: web-app attributeName: xmlns newValue: http://xmlns.jcp.org/xml/ns/javaee From 096431979cd1639bd6530a310cae49edb33a54a5 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Wed, 9 Aug 2023 13:50:46 +0200 Subject: [PATCH 05/12] Add rewrite-xml dependency --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8b06c28..7ffe640 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,7 +13,7 @@ dependencies { implementation("org.openrewrite.recipe:rewrite-java-dependencies") implementation("org.openrewrite.recipe:rewrite-migrate-java") implementation("org.openrewrite.recipe:rewrite-static-analysis") - //implementation("org.openrewrite.recipe:rewrite-xml") + implementation("org.openrewrite.recipe:rewrite-xml") implementation("org.openrewrite.recipe:rewrite-static-analysis") testImplementation("org.openrewrite:rewrite-java-17") From 03407086f43361bef974ab6a5456c34eb7937852 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Wed, 9 Aug 2023 13:59:55 +0200 Subject: [PATCH 06/12] Apply formatter with .editorconfig --- src/test/java/org/openrewrite/.editorconfig | 5 + .../xml/liberty/AppDDNamespaceTest.java | 472 ++++++++-------- .../xml/liberty/ConnectorDDNamespaceTest.java | 357 ++++++------ .../xml/liberty/EJBDDNamespaceTest.java | 527 +++++++++--------- .../PersistenceXmlLocationRuleTest.java | 16 +- .../xml/liberty/WebDDNamespaceTest.java | 193 ++++--- 6 files changed, 804 insertions(+), 766 deletions(-) create mode 100644 src/test/java/org/openrewrite/.editorconfig diff --git a/src/test/java/org/openrewrite/.editorconfig b/src/test/java/org/openrewrite/.editorconfig new file mode 100644 index 0000000..a482493 --- /dev/null +++ b/src/test/java/org/openrewrite/.editorconfig @@ -0,0 +1,5 @@ +root = true + +[*.java] +indent_size = 4 +ij_continuation_indent_size = 2 diff --git a/src/test/java/org/openrewrite/xml/liberty/AppDDNamespaceTest.java b/src/test/java/org/openrewrite/xml/liberty/AppDDNamespaceTest.java index 43c778b..7d1bb4a 100644 --- a/src/test/java/org/openrewrite/xml/liberty/AppDDNamespaceTest.java +++ b/src/test/java/org/openrewrite/xml/liberty/AppDDNamespaceTest.java @@ -23,269 +23,277 @@ import static org.openrewrite.xml.Assertions.xml; -public class AppDDNamespaceTest implements RewriteTest { +class AppDDNamespaceTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { - spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.xml.liberty.AppDDNamespaceRule")); + spec.recipe( + Environment.builder() + .scanRuntimeClasspath("org.openrewrite.java.liberty") + .build() + .activateRecipes("org.openrewrite.xml.liberty.AppDDNamespaceRule")); } @Test void replaceVersion14Test() { rewriteRun( - xml( - """ - - DayTrader Stock Trading Performance Benchmark Sample - Trade - - daytrader-streamer-1.0.jar - - - daytrader-wsappclient-1.0.jar - - - - daytrader-web-1.0.war - /daytrader - - - - daytrader-ejb-1.0.jar - - - """, - """ - - DayTrader Stock Trading Performance Benchmark Sample - Trade - - daytrader-streamer-1.0.jar - - - daytrader-wsappclient-1.0.jar - - - - daytrader-web-1.0.war - /daytrader - - - - daytrader-ejb-1.0.jar - - - """ - ) + //language=xml + xml( + """ + + DayTrader Stock Trading Performance Benchmark Sample + Trade + + daytrader-streamer-1.0.jar + + + daytrader-wsappclient-1.0.jar + + + + daytrader-web-1.0.war + /daytrader + + + + daytrader-ejb-1.0.jar + + + """, + """ + + DayTrader Stock Trading Performance Benchmark Sample + Trade + + daytrader-streamer-1.0.jar + + + daytrader-wsappclient-1.0.jar + + + + daytrader-web-1.0.war + /daytrader + + + + daytrader-ejb-1.0.jar + + + """ + ) ); } @Test void replaceVersion5Test() { rewriteRun( - xml( - """ - - - - test-client.jar - - - - test-ejb.jar - - - - - test.war - test - - - - lib - - """, - """ - - - - test-client.jar - - - - test-ejb.jar - - - - - test.war - test - - - - lib - - """ - ) + //language=xml + xml( + """ + + + + test-client.jar + + + + test-ejb.jar + + + + + test.war + test + + + + lib + + """, + """ + + + + test-client.jar + + + + test-ejb.jar + + + + + test.war + test + + + + lib + + """ + ) ); } @Test void replaceVersion6Test() { rewriteRun( - xml( - """ - - - - test-client.jar - - - - test-ejb.jar - - - - - test.war - test - - - - lib - - """, - """ - - - - test-client.jar - - - - test-ejb.jar - - - - - test.war - test - - - - lib - - """ - ) + //language=xml + xml( + """ + + + + test-client.jar + + + + test-ejb.jar + + + + + test.war + test + + + + lib + + """, + """ + + + + test-client.jar + + + + test-ejb.jar + + + + + test.war + test + + + + lib + + """ + ) ); } @Test void replaceVersion7Test() { rewriteRun( - xml( - """ - - - test-app - true - - - test-web.war - test - - - - - test-ejb.jar - - lib - - """, - """ - - - test-app - true - - - test-web.war - test - - - - - test-ejb.jar - - lib - - """ - ) + //language=xml + xml( + """ + + + test-app + true + + + test-web.war + test + + + + + test-ejb.jar + + lib + + """, + """ + + + test-app + true + + + test-web.war + test + + + + + test-ejb.jar + + lib + + """ + ) ); } @Test void replaceVersion8Test() { rewriteRun( - xml( - """ - - - test-app - true - - - test-web.war - test - - - - - test-ejb.jar - - lib - - """, - """ - - - test-app - true - - - test-web.war - test - - - - - test-ejb.jar - - lib - - """ - ) + //language=xml + xml( + """ + + + test-app + true + + + test-web.war + test + + + + + test-ejb.jar + + lib + + """, + """ + + + test-app + true + + + test-web.war + test + + + + + test-ejb.jar + + lib + + """ + ) ); } } diff --git a/src/test/java/org/openrewrite/xml/liberty/ConnectorDDNamespaceTest.java b/src/test/java/org/openrewrite/xml/liberty/ConnectorDDNamespaceTest.java index a385711..7cadea1 100644 --- a/src/test/java/org/openrewrite/xml/liberty/ConnectorDDNamespaceTest.java +++ b/src/test/java/org/openrewrite/xml/liberty/ConnectorDDNamespaceTest.java @@ -23,201 +23,206 @@ import static org.openrewrite.xml.Assertions.xml; -public class ConnectorDDNamespaceTest implements RewriteTest { + class ConnectorDDNamespaceTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { - spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.xml.liberty.ConnectorDDNamespaceRule")); + spec.recipe( + Environment.builder() + .scanRuntimeClasspath("org.openrewrite.java.liberty") + .build() + .activateRecipes("org.openrewrite.xml.liberty.ConnectorDDNamespaceRule")); } @Test void replaceVersion15Test() { rewriteRun( - xml( - """ - - Generic JCA - adam-bien.com - Generic JCA - 1.0 - - - - ...genericjca.GenericManagedConnectionFactory - ...genericjca.DataSource - ...genericjca.FileDataSource - ...genericjca.Connection - ...genericjca.FileConnection - - LocalTransaction - - BasicPassword - javax.resource.spi.security.PasswordCredential - - false - - - - """, - """ - - Generic JCA - adam-bien.com - Generic JCA - 1.0 - - - - ...genericjca.GenericManagedConnectionFactory - ...genericjca.DataSource - ...genericjca.FileDataSource - ...genericjca.Connection - ...genericjca.FileConnection - - LocalTransaction - - BasicPassword - javax.resource.spi.security.PasswordCredential - - false - - - - """ - ) + //language=xml + xml( + """ + + Generic JCA + adam-bien.com + Generic JCA + 1.0 + + + + ...genericjca.GenericManagedConnectionFactory + ...genericjca.DataSource + ...genericjca.FileDataSource + ...genericjca.Connection + ...genericjca.FileConnection + + LocalTransaction + + BasicPassword + javax.resource.spi.security.PasswordCredential + + false + + + + """, + """ + + Generic JCA + adam-bien.com + Generic JCA + 1.0 + + + + ...genericjca.GenericManagedConnectionFactory + ...genericjca.DataSource + ...genericjca.FileDataSource + ...genericjca.Connection + ...genericjca.FileConnection + + LocalTransaction + + BasicPassword + javax.resource.spi.security.PasswordCredential + + false + + + + """ + ) ); } @Test void replaceVersion16Test() { rewriteRun( - xml( - """ - - Generic JCA - adam-bien.com - Generic JCA - 1.0 - - - - ...genericjca.GenericManagedConnectionFactory - ...genericjca.DataSource - ...genericjca.FileDataSource - ...genericjca.Connection - ...genericjca.FileConnection - - LocalTransaction - - BasicPassword - javax.resource.spi.security.PasswordCredential - - false - - - - """, - """ - - Generic JCA - adam-bien.com - Generic JCA - 1.0 - - - - ...genericjca.GenericManagedConnectionFactory - ...genericjca.DataSource - ...genericjca.FileDataSource - ...genericjca.Connection - ...genericjca.FileConnection - - LocalTransaction - - BasicPassword - javax.resource.spi.security.PasswordCredential - - false - - - - """ - ) + //language=xml + xml( + """ + + Generic JCA + adam-bien.com + Generic JCA + 1.0 + + + + ...genericjca.GenericManagedConnectionFactory + ...genericjca.DataSource + ...genericjca.FileDataSource + ...genericjca.Connection + ...genericjca.FileConnection + + LocalTransaction + + BasicPassword + javax.resource.spi.security.PasswordCredential + + false + + + + """, + """ + + Generic JCA + adam-bien.com + Generic JCA + 1.0 + + + + ...genericjca.GenericManagedConnectionFactory + ...genericjca.DataSource + ...genericjca.FileDataSource + ...genericjca.Connection + ...genericjca.FileConnection + + LocalTransaction + + BasicPassword + javax.resource.spi.security.PasswordCredential + + false + + + + """ + ) ); } @Test void replaceVersion17Test() { rewriteRun( - xml( - """ - - Generic JCA - adam-bien.com - Generic JCA - 1.0 - - - - ...genericjca.GenericManagedConnectionFactory - ...genericjca.DataSource - ...genericjca.FileDataSource - ...genericjca.Connection - ...genericjca.FileConnection - - LocalTransaction - - BasicPassword - javax.resource.spi.security.PasswordCredential - - false - - - - """, - """ - - Generic JCA - adam-bien.com - Generic JCA - 1.0 - - - - ...genericjca.GenericManagedConnectionFactory - ...genericjca.DataSource - ...genericjca.FileDataSource - ...genericjca.Connection - ...genericjca.FileConnection - - LocalTransaction - - BasicPassword - javax.resource.spi.security.PasswordCredential - - false - - - - """ - ) + //language=xml + xml( + """ + + Generic JCA + adam-bien.com + Generic JCA + 1.0 + + + + ...genericjca.GenericManagedConnectionFactory + ...genericjca.DataSource + ...genericjca.FileDataSource + ...genericjca.Connection + ...genericjca.FileConnection + + LocalTransaction + + BasicPassword + javax.resource.spi.security.PasswordCredential + + false + + + + """, + """ + + Generic JCA + adam-bien.com + Generic JCA + 1.0 + + + + ...genericjca.GenericManagedConnectionFactory + ...genericjca.DataSource + ...genericjca.FileDataSource + ...genericjca.Connection + ...genericjca.FileConnection + + LocalTransaction + + BasicPassword + javax.resource.spi.security.PasswordCredential + + false + + + + """ + ) ); } } diff --git a/src/test/java/org/openrewrite/xml/liberty/EJBDDNamespaceTest.java b/src/test/java/org/openrewrite/xml/liberty/EJBDDNamespaceTest.java index cb78afc..d3849b2 100644 --- a/src/test/java/org/openrewrite/xml/liberty/EJBDDNamespaceTest.java +++ b/src/test/java/org/openrewrite/xml/liberty/EJBDDNamespaceTest.java @@ -23,297 +23,304 @@ import static org.openrewrite.xml.Assertions.xml; -public class EJBDDNamespaceTest implements RewriteTest { +class EJBDDNamespaceTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { - spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.xml.liberty.EJBDDNamespaceRule")); + spec.recipe( + Environment.builder() + .scanRuntimeClasspath("org.openrewrite.java.liberty") + .build() + .activateRecipes("org.openrewrite.xml.liberty.EJBDDNamespaceRule")); } @Test void replaceVersion21Test() { rewriteRun( - xml( - """ - - - EchoEJBProject - - - EchoEJB - test.EchoEJBHome - test.EchoEJB - test.EchoEJB - test.EchoEJBBean - Stateless - Container - - - - """, - """ - - - EchoEJBProject - - - EchoEJB - test.EchoEJBHome - test.EchoEJB - test.EchoEJB - test.EchoEJBBean - Stateless - Container - - - - """ - ) + //language=xml + xml( + """ + + + EchoEJBProject + + + EchoEJB + test.EchoEJBHome + test.EchoEJB + test.EchoEJB + test.EchoEJBBean + Stateless + Container + + + + """, + """ + + + EchoEJBProject + + + EchoEJB + test.EchoEJBHome + test.EchoEJB + test.EchoEJB + test.EchoEJBBean + Stateless + Container + + + + """ + ) ); } @Test void replaceVersion30Test() { rewriteRun( - xml( - """ - - - - TestBean - - ejb/fooremote - Session - test.FooRemoteIF - - - - - - - test.Interceptor1 - - - - - - * - test.Interceptor1 - - - - """, - """ - - - - TestBean - - ejb/fooremote - Session - test.FooRemoteIF - - - - - - - test.Interceptor1 - - - - - - * - test.Interceptor1 - - - - """ - ) + //language=xml + xml( + """ + + + + TestBean + + ejb/fooremote + Session + test.FooRemoteIF + + + + + + + test.Interceptor1 + + + + + + * + test.Interceptor1 + + + + """, + """ + + + + TestBean + + ejb/fooremote + Session + test.FooRemoteIF + + + + + + + test.Interceptor1 + + + + + + * + test.Interceptor1 + + + + """ + ) ); } @Test void replaceVersion31Test() { rewriteRun( - xml( - """ - - - - TestBean - - ejb/fooremote - Session - test.FooRemoteIF - - - - - - - test.Interceptor1 - - - - - - * - test.Interceptor1 - - - - """, - """ - - - - TestBean - - ejb/fooremote - Session - test.FooRemoteIF - - - - - - - test.Interceptor1 - - - - - - * - test.Interceptor1 - - - - """ - ) + //language=xml + xml( + """ + + + + TestBean + + ejb/fooremote + Session + test.FooRemoteIF + + + + + + + test.Interceptor1 + + + + + + * + test.Interceptor1 + + + + """, + """ + + + + TestBean + + ejb/fooremote + Session + test.FooRemoteIF + + + + + + + test.Interceptor1 + + + + + + * + test.Interceptor1 + + + + """ + ) ); } @Test void replaceVersion32Test() { rewriteRun( - xml( - """ - - Enterprise JavaBeans 3.1 - Enterprise JavaBeans 3.1 - - - WorkerBean - com.sample.ejb3.slsb.simple2.WorkerBusinessLocal - com.sample.ejb3.slsb.simple2.WorkerBusinessRemote - com.sample.ejb3.slsb.simple2.WorkerBase - Stateless - true - Container - - FILTER - java.lang.Long - 11011 - - - - - """, - """ - - Enterprise JavaBeans 3.1 - Enterprise JavaBeans 3.1 - - - WorkerBean - com.sample.ejb3.slsb.simple2.WorkerBusinessLocal - com.sample.ejb3.slsb.simple2.WorkerBusinessRemote - com.sample.ejb3.slsb.simple2.WorkerBase - Stateless - true - Container - - FILTER - java.lang.Long - 11011 - - - - - """ - ) + //language=xml + xml( + """ + + Enterprise JavaBeans 3.1 + Enterprise JavaBeans 3.1 + + + WorkerBean + com.sample.ejb3.slsb.simple2.WorkerBusinessLocal + com.sample.ejb3.slsb.simple2.WorkerBusinessRemote + com.sample.ejb3.slsb.simple2.WorkerBase + Stateless + true + Container + + FILTER + java.lang.Long + 11011 + + + + + """, + """ + + Enterprise JavaBeans 3.1 + Enterprise JavaBeans 3.1 + + + WorkerBean + com.sample.ejb3.slsb.simple2.WorkerBusinessLocal + com.sample.ejb3.slsb.simple2.WorkerBusinessRemote + com.sample.ejb3.slsb.simple2.WorkerBase + Stateless + true + Container + + FILTER + java.lang.Long + 11011 + + + + + """ + ) ); } @Test void replaceVersion33Test() { rewriteRun( - xml( - """ - - Enterprise JavaBeans 3.1 - Enterprise JavaBeans 3.1 - - - WorkerBean - com.sample.ejb3.slsb.simple2.WorkerBusinessLocal - com.sample.ejb3.slsb.simple2.WorkerBusinessRemote - com.sample.ejb3.slsb.simple2.WorkerBase - Stateless - true - Container - - FILTER - java.lang.Long - 11011 - - - - - """, - """ - - Enterprise JavaBeans 3.1 - Enterprise JavaBeans 3.1 - - - WorkerBean - com.sample.ejb3.slsb.simple2.WorkerBusinessLocal - com.sample.ejb3.slsb.simple2.WorkerBusinessRemote - com.sample.ejb3.slsb.simple2.WorkerBase - Stateless - true - Container - - FILTER - java.lang.Long - 11011 - - - - - """ - ) + //language=xml + xml( + """ + + Enterprise JavaBeans 3.1 + Enterprise JavaBeans 3.1 + + + WorkerBean + com.sample.ejb3.slsb.simple2.WorkerBusinessLocal + com.sample.ejb3.slsb.simple2.WorkerBusinessRemote + com.sample.ejb3.slsb.simple2.WorkerBase + Stateless + true + Container + + FILTER + java.lang.Long + 11011 + + + + + """, + """ + + Enterprise JavaBeans 3.1 + Enterprise JavaBeans 3.1 + + + WorkerBean + com.sample.ejb3.slsb.simple2.WorkerBusinessLocal + com.sample.ejb3.slsb.simple2.WorkerBusinessRemote + com.sample.ejb3.slsb.simple2.WorkerBase + Stateless + true + Container + + FILTER + java.lang.Long + 11011 + + + + + """ + ) ); } } diff --git a/src/test/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRuleTest.java b/src/test/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRuleTest.java index 3670ec7..2fda451 100644 --- a/src/test/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRuleTest.java +++ b/src/test/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRuleTest.java @@ -21,17 +21,21 @@ import org.openrewrite.config.Environment; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; + import java.nio.file.Paths; import static org.assertj.core.api.Assertions.assertThat; +import static org.openrewrite.java.Assertions.project; import static org.openrewrite.test.SourceSpecs.text; -import static org.openrewrite.java.Assertions.*; - -public class PersistenceXmlLocationRuleTest implements RewriteTest { +class PersistenceXmlLocationRuleTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { - spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.xml.liberty.PersistenceXmlLocationRule")); + spec.recipe( + Environment.builder() + .scanRuntimeClasspath("org.openrewrite.java.liberty") + .build() + .activateRecipes("org.openrewrite.xml.liberty.PersistenceXmlLocationRule")); } @DocumentExample @@ -44,9 +48,9 @@ void movePersistenceXMLFileTest() { - """, + """, spec -> project(spec, "testEjbWithJpa").path("testEjbWithJpa/notsrc/META-INF/persistence.xml") - .afterRecipe(pt -> assertThat(pt.getSourcePath()).isEqualTo(Paths.get(System.getProperty("user.dir"), "testEjbWithJpa/src/META-INF/persistence.xml"))) + .afterRecipe(pt -> assertThat(pt.getSourcePath()).isEqualTo(Paths.get(System.getProperty("user.dir"), "testEjbWithJpa/src/META-INF/persistence.xml"))) ) ); } diff --git a/src/test/java/org/openrewrite/xml/liberty/WebDDNamespaceTest.java b/src/test/java/org/openrewrite/xml/liberty/WebDDNamespaceTest.java index 824d1a1..3a1eed7 100644 --- a/src/test/java/org/openrewrite/xml/liberty/WebDDNamespaceTest.java +++ b/src/test/java/org/openrewrite/xml/liberty/WebDDNamespaceTest.java @@ -23,129 +23,138 @@ import static org.openrewrite.xml.Assertions.xml; -public class WebDDNamespaceTest implements RewriteTest { +class WebDDNamespaceTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { - spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.xml.liberty.WebDDNamespaceRule")); + spec.recipe( + Environment.builder() + .scanRuntimeClasspath("org.openrewrite.java.liberty") + .build() + .activateRecipes("org.openrewrite.xml.liberty.WebDDNamespaceRule")); } @Test void replaceVersion24Test() { rewriteRun( - xml( - """ - - testWebDDNamespace - - """, - """ - - testWebDDNamespace - - """ - ) + //language=xml + xml( + """ + + testWebDDNamespace + + """, + """ + + testWebDDNamespace + + """ + ) ); } @Test void replaceVersion25Test() { rewriteRun( - xml( - """ - - testWebDDNamespace - - """, - """ - - testWebDDNamespace - - """ - ) + //language=xml + xml( + """ + + testWebDDNamespace + + """, + """ + + testWebDDNamespace + + """ + ) ); } @Test void replaceVersion30Test() { + //language=xml rewriteRun( - xml( - """ - - testWebDDNamespace - - """, - """ - - testWebDDNamespace - - """ - ) + //language=xml + xml( + """ + + testWebDDNamespace + + """, + """ + + testWebDDNamespace + + """ + ) ); } @Test void replaceVersion31Test() { rewriteRun( - xml( - """ - - testWebDDNamespace - - """, - """ - - testWebDDNamespace - - """ - ) + //language=xml + xml( + """ + + testWebDDNamespace + + """, + """ + + testWebDDNamespace + + """ + ) ); } @Test void replaceVersion32Test() { rewriteRun( - xml( - """ - - testWebDDNamespace - - """, - """ - - testWebDDNamespace - - """ - ) + //language=xml + xml( + """ + + testWebDDNamespace + + """, + """ + + testWebDDNamespace + + """ + ) ); } } From 817e0eecd6a861ab97d713b33660a22f8e385c41 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Wed, 9 Aug 2023 14:08:21 +0200 Subject: [PATCH 07/12] Drop removed argument; Update dependency groupId --- build.gradle.kts | 2 +- .../resources/META-INF/rewrite/was-to-liberty.yml | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 7ffe640..bfa1dec 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,10 +10,10 @@ dependencies { implementation(platform("org.openrewrite:rewrite-bom:$rewriteVersion")) implementation(platform("org.openrewrite.recipe:rewrite-recipe-bom:$rewriteVersion")) implementation("org.openrewrite:rewrite-java") + implementation("org.openrewrite:rewrite-xml") implementation("org.openrewrite.recipe:rewrite-java-dependencies") implementation("org.openrewrite.recipe:rewrite-migrate-java") implementation("org.openrewrite.recipe:rewrite-static-analysis") - implementation("org.openrewrite.recipe:rewrite-xml") implementation("org.openrewrite.recipe:rewrite-static-analysis") testImplementation("org.openrewrite:rewrite-java-17") diff --git a/src/main/resources/META-INF/rewrite/was-to-liberty.yml b/src/main/resources/META-INF/rewrite/was-to-liberty.yml index 2397fb0..26afc72 100644 --- a/src/main/resources/META-INF/rewrite/was-to-liberty.yml +++ b/src/main/resources/META-INF/rewrite/was-to-liberty.yml @@ -54,17 +54,14 @@ name: org.openrewrite.xml.liberty.AppDDNamespaceRule recipeList: - org.openrewrite.xml.ChangeNamespaceValue: elementName: application - attributeName: xmlns newValue: http://java.sun.com/xml/ns/j2ee versionMatcher: 1.4 - org.openrewrite.xml.ChangeNamespaceValue: elementName: application - attributeName: xmlns newValue: http://java.sun.com/xml/ns/javaee versionMatcher: 5,6 - org.openrewrite.xml.ChangeNamespaceValue: elementName: application - attributeName: xmlns newValue: http://xmlns.jcp.org/xml/ns/javaee versionMatcher: 7+ --- @@ -73,17 +70,14 @@ name: org.openrewrite.xml.liberty.ConnectorDDNamespaceRule recipeList: - org.openrewrite.xml.ChangeNamespaceValue: elementName: connector - attributeName: xmlns newValue: http://java.sun.com/xml/ns/j2ee versionMatcher: 1.5 - org.openrewrite.xml.ChangeNamespaceValue: elementName: connector - attributeName: xmlns newValue: http://java.sun.com/xml/ns/javaee versionMatcher: 1.6 - org.openrewrite.xml.ChangeNamespaceValue: elementName: connector - attributeName: xmlns newValue: http://xmlns.jcp.org/xml/ns/javaee versionMatcher: 1.7+ --- @@ -92,17 +86,14 @@ name: org.openrewrite.xml.liberty.EJBDDNamespaceRule recipeList: - org.openrewrite.xml.ChangeNamespaceValue: elementName: ejb-jar - attributeName: xmlns newValue: http://java.sun.com/xml/ns/j2ee versionMatcher: 2.1 - org.openrewrite.xml.ChangeNamespaceValue: elementName: ejb-jar - attributeName: xmlns newValue: http://java.sun.com/xml/ns/javaee versionMatcher: 3.0,3.1 - org.openrewrite.xml.ChangeNamespaceValue: elementName: ejb-jar - attributeName: xmlns newValue: http://xmlns.jcp.org/xml/ns/javaee versionMatcher: 3.2+ --- @@ -116,16 +107,13 @@ name: org.openrewrite.xml.liberty.WebDDNamespaceRule recipeList: - org.openrewrite.xml.ChangeNamespaceValue: elementName: web-app - attributeName: xmlns newValue: http://java.sun.com/xml/ns/j2ee versionMatcher: 2.4 - org.openrewrite.xml.ChangeNamespaceValue: elementName: web-app - attributeName: xmlns newValue: http://java.sun.com/xml/ns/java versionMatcher: 2.5,3.0 - org.openrewrite.xml.ChangeNamespaceValue: elementName: web-app - attributeName: xmlns newValue: http://xmlns.jcp.org/xml/ns/javaee versionMatcher: 3.1+ From a3520156fc168e05e41783ceaaca801a3d6e96cd Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Wed, 9 Aug 2023 14:27:00 +0200 Subject: [PATCH 08/12] Revert formatter introduced changes --- build.gradle.kts | 1 - .../xml/liberty/AppDDNamespaceTest.java | 9 +--- .../xml/liberty/ConnectorDDNamespaceTest.java | 28 +++-------- .../xml/liberty/EJBDDNamespaceTest.java | 36 ++++---------- .../PersistenceXmlLocationRuleTest.java | 1 + .../xml/liberty/WebDDNamespaceTest.java | 49 ++++--------------- 6 files changed, 29 insertions(+), 95 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index bfa1dec..53af77c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,7 +10,6 @@ dependencies { implementation(platform("org.openrewrite:rewrite-bom:$rewriteVersion")) implementation(platform("org.openrewrite.recipe:rewrite-recipe-bom:$rewriteVersion")) implementation("org.openrewrite:rewrite-java") - implementation("org.openrewrite:rewrite-xml") implementation("org.openrewrite.recipe:rewrite-java-dependencies") implementation("org.openrewrite.recipe:rewrite-migrate-java") implementation("org.openrewrite.recipe:rewrite-static-analysis") diff --git a/src/test/java/org/openrewrite/xml/liberty/AppDDNamespaceTest.java b/src/test/java/org/openrewrite/xml/liberty/AppDDNamespaceTest.java index 7d1bb4a..2398991 100644 --- a/src/test/java/org/openrewrite/xml/liberty/AppDDNamespaceTest.java +++ b/src/test/java/org/openrewrite/xml/liberty/AppDDNamespaceTest.java @@ -39,9 +39,7 @@ void replaceVersion14Test() { //language=xml xml( """ - + DayTrader Stock Trading Performance Benchmark Sample Trade @@ -62,10 +60,7 @@ void replaceVersion14Test() { """, """ - + DayTrader Stock Trading Performance Benchmark Sample Trade diff --git a/src/test/java/org/openrewrite/xml/liberty/ConnectorDDNamespaceTest.java b/src/test/java/org/openrewrite/xml/liberty/ConnectorDDNamespaceTest.java index 7cadea1..ea39984 100644 --- a/src/test/java/org/openrewrite/xml/liberty/ConnectorDDNamespaceTest.java +++ b/src/test/java/org/openrewrite/xml/liberty/ConnectorDDNamespaceTest.java @@ -39,8 +39,7 @@ void replaceVersion15Test() { //language=xml xml( """ - + Generic JCA adam-bien.com Generic JCA @@ -65,10 +64,7 @@ void replaceVersion15Test() { """, """ - + Generic JCA adam-bien.com Generic JCA @@ -102,10 +98,7 @@ void replaceVersion16Test() { //language=xml xml( """ - + Generic JCA adam-bien.com Generic JCA @@ -130,10 +123,7 @@ void replaceVersion16Test() { """, """ - + Generic JCA adam-bien.com Generic JCA @@ -167,10 +157,7 @@ void replaceVersion17Test() { //language=xml xml( """ - + Generic JCA adam-bien.com Generic JCA @@ -195,10 +182,7 @@ void replaceVersion17Test() { """, """ - + Generic JCA adam-bien.com Generic JCA diff --git a/src/test/java/org/openrewrite/xml/liberty/EJBDDNamespaceTest.java b/src/test/java/org/openrewrite/xml/liberty/EJBDDNamespaceTest.java index d3849b2..6ab77e6 100644 --- a/src/test/java/org/openrewrite/xml/liberty/EJBDDNamespaceTest.java +++ b/src/test/java/org/openrewrite/xml/liberty/EJBDDNamespaceTest.java @@ -39,8 +39,7 @@ void replaceVersion21Test() { //language=xml xml( """ - + EchoEJBProject @@ -57,8 +56,7 @@ void replaceVersion21Test() { """, """ - + EchoEJBProject @@ -84,8 +82,7 @@ void replaceVersion30Test() { //language=xml xml( """ - + TestBean @@ -112,8 +109,7 @@ void replaceVersion30Test() { """, """ - + TestBean @@ -149,8 +145,7 @@ void replaceVersion31Test() { //language=xml xml( """ - + TestBean @@ -177,8 +172,7 @@ void replaceVersion31Test() { """, """ - + TestBean @@ -214,10 +208,7 @@ void replaceVersion32Test() { //language=xml xml( """ - + Enterprise JavaBeans 3.1 Enterprise JavaBeans 3.1 @@ -239,10 +230,7 @@ void replaceVersion32Test() { """, """ - + Enterprise JavaBeans 3.1 Enterprise JavaBeans 3.1 @@ -273,8 +261,7 @@ void replaceVersion33Test() { //language=xml xml( """ - + Enterprise JavaBeans 3.1 Enterprise JavaBeans 3.1 @@ -296,10 +283,7 @@ void replaceVersion33Test() { """, """ - + Enterprise JavaBeans 3.1 Enterprise JavaBeans 3.1 diff --git a/src/test/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRuleTest.java b/src/test/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRuleTest.java index 2fda451..256bc17 100644 --- a/src/test/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRuleTest.java +++ b/src/test/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRuleTest.java @@ -43,6 +43,7 @@ public void defaults(RecipeSpec spec) { void movePersistenceXMLFileTest() { rewriteRun( text( + //language=xml """ diff --git a/src/test/java/org/openrewrite/xml/liberty/WebDDNamespaceTest.java b/src/test/java/org/openrewrite/xml/liberty/WebDDNamespaceTest.java index 3a1eed7..4c37884 100644 --- a/src/test/java/org/openrewrite/xml/liberty/WebDDNamespaceTest.java +++ b/src/test/java/org/openrewrite/xml/liberty/WebDDNamespaceTest.java @@ -39,18 +39,12 @@ void replaceVersion24Test() { //language=xml xml( """ - + testWebDDNamespace """, """ - + testWebDDNamespace """ @@ -64,18 +58,12 @@ void replaceVersion25Test() { //language=xml xml( """ - + testWebDDNamespace """, """ - + testWebDDNamespace """ @@ -90,18 +78,12 @@ void replaceVersion30Test() { //language=xml xml( """ - + testWebDDNamespace """, """ - + testWebDDNamespace """ @@ -115,18 +97,12 @@ void replaceVersion31Test() { //language=xml xml( """ - + testWebDDNamespace """, """ - + testWebDDNamespace """ @@ -140,17 +116,12 @@ void replaceVersion32Test() { //language=xml xml( """ - + testWebDDNamespace """, """ - + testWebDDNamespace """ From ee2837c6f1b508cbef4836a98c35d557bb81f0e1 Mon Sep 17 00:00:00 2001 From: cjobinabo Date: Wed, 9 Aug 2023 10:25:12 -0500 Subject: [PATCH 09/12] formatter --- .../java/liberty/ChangeMethodInvocation.java | 28 ++--- .../java/liberty/ChangeStringLiteral.java | 4 +- ...emoveWas2LibertyNonPortableJndiLookup.java | 8 +- .../liberty/PersistenceXmlLocationRule.java | 41 ++++--- .../liberty/InvalidInitialContextTest.java | 100 +++++++-------- ...eWas2LibertyNonPortableJndiLookupTest.java | 60 ++++----- .../java/liberty/ServerNameTest.java | 114 +++++++++--------- 7 files changed, 178 insertions(+), 177 deletions(-) diff --git a/src/main/java/org/openrewrite/java/liberty/ChangeMethodInvocation.java b/src/main/java/org/openrewrite/java/liberty/ChangeMethodInvocation.java index 82db0f1..4a8dea1 100644 --- a/src/main/java/org/openrewrite/java/liberty/ChangeMethodInvocation.java +++ b/src/main/java/org/openrewrite/java/liberty/ChangeMethodInvocation.java @@ -63,8 +63,8 @@ public class ChangeMethodInvocation extends Recipe { Boolean performStaticCall; @JsonCreator - public ChangeMethodInvocation(@NonNull @JsonProperty("methodPattern") String methodPattern, - @NonNull @JsonProperty("newMethodPattern") String newMethodPattern, @Nullable @JsonProperty("performStaticCall") Boolean performStaticCall) { + public ChangeMethodInvocation(@NonNull @JsonProperty("methodPattern") String methodPattern, + @NonNull @JsonProperty("newMethodPattern") String newMethodPattern, @Nullable @JsonProperty("performStaticCall") Boolean performStaticCall) { this.methodPattern = methodPattern; this.newMethodPattern = newMethodPattern; this.performStaticCall = performStaticCall; @@ -95,7 +95,7 @@ private class ChangeMethodInvocationVisitor extends JavaVisitor methodArgs = Collections.singletonList(new J.Empty(Tree.randomId(), Space.EMPTY, Markers.EMPTY)); m = m.withArguments(methodArgs); } else { // override arguments - JavaTemplate addArgTemplate = JavaTemplate.builder( newMethodsArgsStr).build(); + JavaTemplate addArgTemplate = JavaTemplate.builder(newMethodsArgsStr).build(); m = addArgTemplate.apply(getCursor(), m.getCoordinates().replaceArguments()); } } diff --git a/src/main/java/org/openrewrite/java/liberty/ChangeStringLiteral.java b/src/main/java/org/openrewrite/java/liberty/ChangeStringLiteral.java index f3fd297..ab58585 100644 --- a/src/main/java/org/openrewrite/java/liberty/ChangeStringLiteral.java +++ b/src/main/java/org/openrewrite/java/liberty/ChangeStringLiteral.java @@ -67,7 +67,7 @@ public String getDescription() { @Override public TreeVisitor getVisitor() { - return new ChangeStringLiteralVisitor<> (Pattern.compile(valuePattern), newValueTemplate); + return new ChangeStringLiteralVisitor<>(Pattern.compile(valuePattern), newValueTemplate); } @Value @@ -81,7 +81,7 @@ public J.Literal visitLiteral(J.Literal literal, P p) { String literalValue = literal.getValue().toString(); Matcher m = valuePattern.matcher(literalValue); if (m.find()) { - literalValue = m.replaceFirst(newValueTemplate); + literalValue = m.replaceFirst(newValueTemplate); literal = literal.withValue(literalValue).withValueSource(literalValue); } return literal; diff --git a/src/main/java/org/openrewrite/java/liberty/RemoveWas2LibertyNonPortableJndiLookup.java b/src/main/java/org/openrewrite/java/liberty/RemoveWas2LibertyNonPortableJndiLookup.java index 53a2c54..7d9270b 100644 --- a/src/main/java/org/openrewrite/java/liberty/RemoveWas2LibertyNonPortableJndiLookup.java +++ b/src/main/java/org/openrewrite/java/liberty/RemoveWas2LibertyNonPortableJndiLookup.java @@ -43,7 +43,7 @@ public String getDescription() { public TreeVisitor getVisitor() { return new MethodInvocationVisitor(); } - + private class MethodInvocationVisitor extends JavaVisitor { MethodMatcher methodMatcher = new MethodMatcher("java.util.Hashtable put(java.lang.Object, java.lang.Object)", false); @@ -65,16 +65,16 @@ private M visitMethodCall(M methodCall) { return methodCall; } // Remove the method invocation when the argumentMatcherPredicate is true for all arguments - Expression firstArg = methodCall.getArguments().get(0); + Expression firstArg = methodCall.getArguments().get(0); if (firstArg instanceof J.Literal) { J.Literal literalExp = (J.Literal) firstArg; Object value = literalExp.getValue(); - if(!value.equals("java.naming.factory.initial") && !value.equals("java.naming.provider.url")) { + if (!value.equals("java.naming.factory.initial") && !value.equals("java.naming.provider.url")) { return methodCall; } } else { return methodCall; - } + } if (methodCall.getMethodType() != null) { maybeRemoveImport(methodCall.getMethodType().getDeclaringType()); diff --git a/src/main/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRule.java b/src/main/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRule.java index 815b700..c12e6a7 100644 --- a/src/main/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRule.java +++ b/src/main/java/org/openrewrite/xml/liberty/PersistenceXmlLocationRule.java @@ -14,6 +14,7 @@ * limitations under the License. */ package org.openrewrite.xml.liberty; + import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.marker.JavaProject; @@ -42,7 +43,7 @@ public String getDescription() { public File getProjectDirectory(File sourceFile, String projectName) { File parent = sourceFile.getParentFile(); - while(parent != null && !parent.getName().equals(projectName)) { + while (parent != null && !parent.getName().equals(projectName)) { parent = parent.getParentFile(); } @@ -52,19 +53,19 @@ public File getProjectDirectory(File sourceFile, String projectName) { public List getSrcDirectories(SourceFile sourceFile) { List srcDirs = new ArrayList(); Path sourcePath = sourceFile.getSourcePath(); - + String projectName = sourceFile.getMarkers() - .findFirst(JavaProject.class) - .map(JavaProject::getProjectName) - .orElse(""); - + .findFirst(JavaProject.class) + .map(JavaProject::getProjectName) + .orElse(""); + File projectDirctory = getProjectDirectory(new File(sourcePath.toAbsolutePath().toString()), projectName); - if(projectDirctory != null) { + if (projectDirctory != null) { File[] subDirs = projectDirctory.listFiles(File::isDirectory); - if(subDirs != null) { - for (File subDir: subDirs) { + if (subDirs != null) { + for (File subDir : subDirs) { String dirName = subDir.getName().toLowerCase(); - if(dirName.endsWith("src") || dirName.equals("source")) { + if (dirName.endsWith("src") || dirName.equals("source")) { srcDirs.add(subDir); } } @@ -84,37 +85,37 @@ public Tree visit(@Nullable Tree tree, ExecutionContext executionContext) { SourceFile sourceFile = ((SourceFile) tree); Path sourcePath = ((SourceFile) tree).getSourcePath(); - if(sourcePath.getFileName().toString().equals("persistence.xml")) { + if (sourcePath.getFileName().toString().equals("persistence.xml")) { String projectName = sourceFile.getMarkers() - .findFirst(JavaProject.class) - .map(JavaProject::getProjectName) - .orElse(""); + .findFirst(JavaProject.class) + .map(JavaProject::getProjectName) + .orElse(""); List srcDirs = getSrcDirectories(sourceFile); boolean isValidPath = false; boolean correctFileExists = false; Path correctPath = null; - if(!srcDirs.isEmpty()) { - for(File srcDir: srcDirs) { + if (!srcDirs.isEmpty()) { + for (File srcDir : srcDirs) { correctPath = srcDir.toPath().resolve("META-INF").resolve("persistence.xml"); - if(sourcePath.toAbsolutePath().equals(correctPath.toAbsolutePath())) { + if (sourcePath.toAbsolutePath().equals(correctPath.toAbsolutePath())) { isValidPath = true; break; } - if(correctPath.toFile().exists()) { + if (correctPath.toFile().exists()) { correctFileExists = true; } } } else { - if(!sourcePath.toAbsolutePath().endsWith("src"+File.separator+"META-INF"+File.separator+"persistence.xml")) { + if (!sourcePath.toAbsolutePath().endsWith("src" + File.separator + "META-INF" + File.separator + "persistence.xml")) { File projectFile = getProjectDirectory(new File(sourcePath.toAbsolutePath().toString()), projectName); correctPath = projectFile.toPath().resolve("src").resolve("META-INF").resolve("persistence.xml"); return ((SourceFile) tree).withSourcePath(correctPath); } } - if(!isValidPath && !correctFileExists && correctPath != null) { + if (!isValidPath && !correctFileExists && correctPath != null) { return ((SourceFile) tree).withSourcePath(correctPath); } else { return sourceFile; diff --git a/src/test/java/org/openrewrite/java/liberty/InvalidInitialContextTest.java b/src/test/java/org/openrewrite/java/liberty/InvalidInitialContextTest.java index b5b193b..b99a4e6 100644 --- a/src/test/java/org/openrewrite/java/liberty/InvalidInitialContextTest.java +++ b/src/test/java/org/openrewrite/java/liberty/InvalidInitialContextTest.java @@ -22,65 +22,65 @@ import static org.openrewrite.java.Assertions.java; public class InvalidInitialContextTest implements RewriteTest { - + String initialContextClass = """ - package javax.naming; + package javax.naming; - public class InitialContext { + public class InitialContext { - public InitialContext() { - } + public InitialContext() { + } - public void lookup() { - } + public void lookup() { + } - } - """; + } + """; @Test void replaceTimeoutTest() { rewriteRun( - spec -> spec.recipe(new ChangeStringLiteral("^java:/comp(.*)$", "java:comp$1")), - java(initialContextClass), - java( - """ - package com.test; - - import javax.naming.InitialContext; - import javax.naming.NamingException; - - public class TestDetectInvalidInitialContext { - public static final String BAD_ENV = "java:/comp"; - public static final String GOOD_ENV = "java:comp"; - - private void doX(){ - InitialContext ic = new InitialContext(); - ic.lookup("java:/comp"); - ic.lookup("java:/comp/BadEntry"); - ic.lookup("java:comp/GoodEntry"); - } - } - """, - """ - package com.test; - - import javax.naming.InitialContext; - import javax.naming.NamingException; - - public class TestDetectInvalidInitialContext { - public static final String BAD_ENV = java:comp; - public static final String GOOD_ENV = "java:comp"; - - private void doX(){ - InitialContext ic = new InitialContext(); - ic.lookup(java:comp); - ic.lookup(java:comp/BadEntry); - ic.lookup("java:comp/GoodEntry"); - } - } - """ - ) + spec -> spec.recipe(new ChangeStringLiteral("^java:/comp(.*)$", "java:comp$1")), + java(initialContextClass), + java( + """ + package com.test; + + import javax.naming.InitialContext; + import javax.naming.NamingException; + + public class TestDetectInvalidInitialContext { + public static final String BAD_ENV = "java:/comp"; + public static final String GOOD_ENV = "java:comp"; + + private void doX(){ + InitialContext ic = new InitialContext(); + ic.lookup("java:/comp"); + ic.lookup("java:/comp/BadEntry"); + ic.lookup("java:comp/GoodEntry"); + } + } + """, + """ + package com.test; + + import javax.naming.InitialContext; + import javax.naming.NamingException; + + public class TestDetectInvalidInitialContext { + public static final String BAD_ENV = java:comp; + public static final String GOOD_ENV = "java:comp"; + + private void doX(){ + InitialContext ic = new InitialContext(); + ic.lookup(java:comp); + ic.lookup(java:comp/BadEntry); + ic.lookup("java:comp/GoodEntry"); + } + } + """ + ) ); } - + } diff --git a/src/test/java/org/openrewrite/java/liberty/RemoveWas2LibertyNonPortableJndiLookupTest.java b/src/test/java/org/openrewrite/java/liberty/RemoveWas2LibertyNonPortableJndiLookupTest.java index 3a51b45..992e802 100644 --- a/src/test/java/org/openrewrite/java/liberty/RemoveWas2LibertyNonPortableJndiLookupTest.java +++ b/src/test/java/org/openrewrite/java/liberty/RemoveWas2LibertyNonPortableJndiLookupTest.java @@ -27,44 +27,44 @@ public class RemoveWas2LibertyNonPortableJndiLookupTest implements RewriteTest { @Test void removeInvalidPropertiesTest() { rewriteRun( - spec -> spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.java.liberty.RemoveWas2LibertyNonPortableJndiLookup")), - java( - """ - package com.ibm; + spec -> spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.java.liberty.RemoveWas2LibertyNonPortableJndiLookup")), + java( + """ + package com.ibm; - import java.util.Hashtable; - import javax.naming.InitialContext; + import java.util.Hashtable; + import javax.naming.InitialContext; - public class ServerNameUsage { - - public void doX() { - Hashtable ht = new Hashtable(); - ht.put("java.naming.factory.initial", "com.ibm.websphere.naming.WsnInitialContextFactory"); - ht.put("java.naming.provider.url", "corbaloc:iiop:localhost:2809"); + public class ServerNameUsage { + + public void doX() { + Hashtable ht = new Hashtable(); + ht.put("java.naming.factory.initial", "com.ibm.websphere.naming.WsnInitialContextFactory"); + ht.put("java.naming.provider.url", "corbaloc:iiop:localhost:2809"); - InitialContext ctx = new InitialContext(ht); - } + InitialContext ctx = new InitialContext(ht); + } - } - """, - """ - package com.ibm; + } + """, + """ + package com.ibm; - import java.util.Hashtable; - import javax.naming.InitialContext; + import java.util.Hashtable; + import javax.naming.InitialContext; - public class ServerNameUsage { - - public void doX() { - Hashtable ht = new Hashtable(); + public class ServerNameUsage { + + public void doX() { + Hashtable ht = new Hashtable(); - InitialContext ctx = new InitialContext(ht); - } + InitialContext ctx = new InitialContext(ht); + } - } - """ - ) + } + """ + ) ); } - + } diff --git a/src/test/java/org/openrewrite/java/liberty/ServerNameTest.java b/src/test/java/org/openrewrite/java/liberty/ServerNameTest.java index c2173b2..1402cde 100644 --- a/src/test/java/org/openrewrite/java/liberty/ServerNameTest.java +++ b/src/test/java/org/openrewrite/java/liberty/ServerNameTest.java @@ -25,86 +25,86 @@ public class ServerNameTest implements RewriteTest { String serverNameClass = """ - package com.ibm.websphere.runtime; + package com.ibm.websphere.runtime; - public class ServerName { + public class ServerName { - public static String getDisplayName() { - return ""; - } + public static String getDisplayName() { + return ""; + } - public static String getFullName() { - return ""; - } + public static String getFullName() { + return ""; + } + + } + """; - } - """; - @Test void replaceGetFullNameTest() { rewriteRun( - spec -> spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.java.liberty.ServerName")), - java(serverNameClass), - java( - """ - package com.ibm; + spec -> spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.java.liberty.ServerName")), + java(serverNameClass), + java( + """ + package com.ibm; - import com.ibm.websphere.runtime.ServerName; + import com.ibm.websphere.runtime.ServerName; - public class ServerNameUsage { - - public void doX() { - ServerName.getFullName(); - } + public class ServerNameUsage { + + public void doX() { + ServerName.getFullName(); + } - } - """, - """ - package com.ibm; + } + """, + """ + package com.ibm; - public class ServerNameUsage { - - public void doX() { - System.getProperty("wlp.server.name"); - } + public class ServerNameUsage { + + public void doX() { + System.getProperty("wlp.server.name"); + } - } - """ - ) + } + """ + ) ); } @Test void replaceGetDisplayNameTest() { rewriteRun( - spec -> spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.java.liberty.ServerName")), - java(serverNameClass), - java( - """ - package com.ibm; + spec -> spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.liberty").build().activateRecipes("org.openrewrite.java.liberty.ServerName")), + java(serverNameClass), + java( + """ + package com.ibm; - import com.ibm.websphere.runtime.ServerName; + import com.ibm.websphere.runtime.ServerName; - public class ServerNameUsage { - - public void doX() { - ServerName.getDisplayName(); - } + public class ServerNameUsage { + + public void doX() { + ServerName.getDisplayName(); + } - } - """, - """ - package com.ibm; + } + """, + """ + package com.ibm; - public class ServerNameUsage { - - public void doX() { - System.getProperty("wlp.server.name"); - } + public class ServerNameUsage { + + public void doX() { + System.getProperty("wlp.server.name"); + } - } - """ - ) + } + """ + ) ); } } From e561b2d32fe03572959351f8bbe0009190cd5aa1 Mon Sep 17 00:00:00 2001 From: cjobinabo Date: Fri, 11 Aug 2023 11:42:25 -0500 Subject: [PATCH 10/12] fix tests --- .../java/liberty/ChangeMethodInvocation.java | 2 ++ .../resources/META-INF/rewrite/was-to-liberty.yml | 12 ++++++++++++ .../openrewrite/xml/liberty/AppDDNamespaceTest.java | 2 +- .../xml/liberty/ConnectorDDNamespaceTest.java | 2 +- .../openrewrite/xml/liberty/EJBDDNamespaceTest.java | 2 +- .../openrewrite/xml/liberty/WebDDNamespaceTest.java | 2 +- 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/openrewrite/java/liberty/ChangeMethodInvocation.java b/src/main/java/org/openrewrite/java/liberty/ChangeMethodInvocation.java index 4a8dea1..a87074f 100644 --- a/src/main/java/org/openrewrite/java/liberty/ChangeMethodInvocation.java +++ b/src/main/java/org/openrewrite/java/liberty/ChangeMethodInvocation.java @@ -36,6 +36,8 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import org.openrewrite.xml.ChangeNamespaceValue; + /* Development in this class is not complete */ diff --git a/src/main/resources/META-INF/rewrite/was-to-liberty.yml b/src/main/resources/META-INF/rewrite/was-to-liberty.yml index 26afc72..4887967 100644 --- a/src/main/resources/META-INF/rewrite/was-to-liberty.yml +++ b/src/main/resources/META-INF/rewrite/was-to-liberty.yml @@ -56,14 +56,17 @@ recipeList: elementName: application newValue: http://java.sun.com/xml/ns/j2ee versionMatcher: 1.4 + searchAllNamespaces: false - org.openrewrite.xml.ChangeNamespaceValue: elementName: application newValue: http://java.sun.com/xml/ns/javaee versionMatcher: 5,6 + searchAllNamespaces: false - org.openrewrite.xml.ChangeNamespaceValue: elementName: application newValue: http://xmlns.jcp.org/xml/ns/javaee versionMatcher: 7+ + searchAllNamespaces: false --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.xml.liberty.ConnectorDDNamespaceRule @@ -72,14 +75,17 @@ recipeList: elementName: connector newValue: http://java.sun.com/xml/ns/j2ee versionMatcher: 1.5 + searchAllNamespaces: false - org.openrewrite.xml.ChangeNamespaceValue: elementName: connector newValue: http://java.sun.com/xml/ns/javaee versionMatcher: 1.6 + searchAllNamespaces: false - org.openrewrite.xml.ChangeNamespaceValue: elementName: connector newValue: http://xmlns.jcp.org/xml/ns/javaee versionMatcher: 1.7+ + searchAllNamespaces: false --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.xml.liberty.EJBDDNamespaceRule @@ -88,14 +94,17 @@ recipeList: elementName: ejb-jar newValue: http://java.sun.com/xml/ns/j2ee versionMatcher: 2.1 + searchAllNamespaces: false - org.openrewrite.xml.ChangeNamespaceValue: elementName: ejb-jar newValue: http://java.sun.com/xml/ns/javaee versionMatcher: 3.0,3.1 + searchAllNamespaces: false - org.openrewrite.xml.ChangeNamespaceValue: elementName: ejb-jar newValue: http://xmlns.jcp.org/xml/ns/javaee versionMatcher: 3.2+ + searchAllNamespaces: false --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.xml.liberty.PersistenceXmlLocationRule @@ -109,11 +118,14 @@ recipeList: elementName: web-app newValue: http://java.sun.com/xml/ns/j2ee versionMatcher: 2.4 + searchAllNamespaces: false - org.openrewrite.xml.ChangeNamespaceValue: elementName: web-app newValue: http://java.sun.com/xml/ns/java versionMatcher: 2.5,3.0 + searchAllNamespaces: false - org.openrewrite.xml.ChangeNamespaceValue: elementName: web-app newValue: http://xmlns.jcp.org/xml/ns/javaee versionMatcher: 3.1+ + searchAllNamespaces: false diff --git a/src/test/java/org/openrewrite/xml/liberty/AppDDNamespaceTest.java b/src/test/java/org/openrewrite/xml/liberty/AppDDNamespaceTest.java index 2398991..1aac361 100644 --- a/src/test/java/org/openrewrite/xml/liberty/AppDDNamespaceTest.java +++ b/src/test/java/org/openrewrite/xml/liberty/AppDDNamespaceTest.java @@ -60,7 +60,7 @@ void replaceVersion14Test() { """, """ - + DayTrader Stock Trading Performance Benchmark Sample Trade diff --git a/src/test/java/org/openrewrite/xml/liberty/ConnectorDDNamespaceTest.java b/src/test/java/org/openrewrite/xml/liberty/ConnectorDDNamespaceTest.java index ea39984..58e508a 100644 --- a/src/test/java/org/openrewrite/xml/liberty/ConnectorDDNamespaceTest.java +++ b/src/test/java/org/openrewrite/xml/liberty/ConnectorDDNamespaceTest.java @@ -64,7 +64,7 @@ void replaceVersion15Test() { """, """ - + Generic JCA adam-bien.com Generic JCA diff --git a/src/test/java/org/openrewrite/xml/liberty/EJBDDNamespaceTest.java b/src/test/java/org/openrewrite/xml/liberty/EJBDDNamespaceTest.java index 6ab77e6..d3e6cc5 100644 --- a/src/test/java/org/openrewrite/xml/liberty/EJBDDNamespaceTest.java +++ b/src/test/java/org/openrewrite/xml/liberty/EJBDDNamespaceTest.java @@ -283,7 +283,7 @@ void replaceVersion33Test() { """, """ - + Enterprise JavaBeans 3.1 Enterprise JavaBeans 3.1 diff --git a/src/test/java/org/openrewrite/xml/liberty/WebDDNamespaceTest.java b/src/test/java/org/openrewrite/xml/liberty/WebDDNamespaceTest.java index 4c37884..3286aa9 100644 --- a/src/test/java/org/openrewrite/xml/liberty/WebDDNamespaceTest.java +++ b/src/test/java/org/openrewrite/xml/liberty/WebDDNamespaceTest.java @@ -116,7 +116,7 @@ void replaceVersion32Test() { //language=xml xml( """ - + testWebDDNamespace """, From 5778e4099fd7d1b58b16fd0c59a3d8d1f512405f Mon Sep 17 00:00:00 2001 From: cjobinabo Date: Fri, 11 Aug 2023 11:48:23 -0500 Subject: [PATCH 11/12] removed unnecessary import --- .../org/openrewrite/java/liberty/ChangeMethodInvocation.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/openrewrite/java/liberty/ChangeMethodInvocation.java b/src/main/java/org/openrewrite/java/liberty/ChangeMethodInvocation.java index a87074f..4a8dea1 100644 --- a/src/main/java/org/openrewrite/java/liberty/ChangeMethodInvocation.java +++ b/src/main/java/org/openrewrite/java/liberty/ChangeMethodInvocation.java @@ -36,8 +36,6 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import org.openrewrite.xml.ChangeNamespaceValue; - /* Development in this class is not complete */ From 24b883838c4d5eb9ed891d751ef1d585f6d7e90c Mon Sep 17 00:00:00 2001 From: cjobinabo Date: Fri, 11 Aug 2023 11:52:52 -0500 Subject: [PATCH 12/12] removed duplicate dependency in build file --- build.gradle.kts | 1 - 1 file changed, 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 53af77c..202e55e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,7 +13,6 @@ dependencies { implementation("org.openrewrite.recipe:rewrite-java-dependencies") implementation("org.openrewrite.recipe:rewrite-migrate-java") implementation("org.openrewrite.recipe:rewrite-static-analysis") - implementation("org.openrewrite.recipe:rewrite-static-analysis") testImplementation("org.openrewrite:rewrite-java-17") testImplementation("org.openrewrite:rewrite-test")