├── .github └── workflows │ └── maven.yml ├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── README.md ├── mvnw ├── mvnw.cmd ├── pom.xml ├── src ├── main │ ├── java │ │ └── com │ │ │ └── huaweicse │ │ │ └── tools │ │ │ └── migrator │ │ │ ├── MigrateApplication.java │ │ │ ├── common │ │ │ ├── Action.java │ │ │ ├── AddBootstrapYamlAction.java │ │ │ ├── Const.java │ │ │ ├── FileAction.java │ │ │ ├── ModifyPomAction.java │ │ │ ├── OrderedWriteProperties.java │ │ │ └── ParamValueType.java │ │ │ ├── dubbo │ │ │ ├── ModifyDubboAction.java │ │ │ ├── ModifyDubboAddBootstrapYamlAction.java │ │ │ ├── ModifyDubboInterface2RestAction.java │ │ │ ├── ModifyDubboMainClassAction.java │ │ │ ├── ModifyDubboPomAction.java │ │ │ ├── ModifyDubboReferenceAction.java │ │ │ └── ModifyDubboServiceAction.java │ │ │ ├── eureka │ │ │ ├── ModifyEurekaAction.java │ │ │ ├── ModifyEurekaAddBootstrapYamlAction.java │ │ │ ├── ModifyEurekaMainClassAction.java │ │ │ └── ModifyEurekaPomAction.java │ │ │ ├── hsf │ │ │ ├── ModifyHSFAction.java │ │ │ ├── ModifyHSFAddBootstrapYamlAction.java │ │ │ ├── ModifyHSFConsumerAction.java │ │ │ ├── ModifyHSFInterface2RestAction.java │ │ │ ├── ModifyHSFMainClassAction.java │ │ │ ├── ModifyHSFPomAction.java │ │ │ └── ModifyHSFProviderAction.java │ │ │ └── nacos │ │ │ ├── ModifyNacosAction.java │ │ │ ├── ModifyNacosAddBootstrapYamlAction.java │ │ │ └── ModifyNacosPomAction.java │ └── resources │ │ ├── application.properties │ │ └── logback-spring.xml └── test │ └── java │ └── com │ └── huaweicse │ └── tools │ └── migrator │ ├── Utils.java │ ├── dubbo │ ├── ModifyDubboAddBootstrapYamlActionTest.java │ ├── ModifyDubboInterface2RestActionTest.java │ ├── ModifyDubboMainClassActionTest.java │ ├── ModifyDubboReferenceActionTest.java │ └── ModifyDubboServiceActionTest.java │ ├── eureka │ └── ModifyEurekaMainClassActionTest.java │ ├── hsf │ ├── ModifyHSFAddBootstrapYamlActionTest.java │ ├── ModifyHSFConsumerActionTest.java │ ├── ModifyHSFInterface2RestActionTest.java │ ├── ModifyHSFMainClassActionTest.java │ ├── ModifyHSFPomActionTest.java │ └── ModifyHSFProviderActionTest.java │ └── nacos │ └── ModifyNacosActionTest.java ├── templates ├── bootstrap.yml ├── dubbo.pom.json ├── eureka.pom.json ├── hsf.pom.json └── nacos.pom.json └── testfiles ├── ModifyDubboAddBootstrapYamlActionTest └── src │ └── main │ └── resources │ └── application.properties ├── ModifyDubboInterface2RestActionTest ├── input │ ├── HelloService.java │ └── HelloServiceImpl.java └── output │ └── HelloService.java ├── ModifyDubboMainClassActionTest ├── input │ ├── dubbo-annotation │ │ └── DubboConsumerApplication.java │ ├── dubbo-springboot │ │ └── DubboConsumerApplication.java │ └── dubbo-xml │ │ └── DubboConsumerApplication.java └── output │ └── DubboConsumerApplication.java ├── ModifyDubboReferenceActionTest ├── input │ ├── dubbo-annotation │ │ ├── consumer │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── huaweicse │ │ │ │ │ └── test │ │ │ │ │ └── DubboAnnotationConsumerController.java │ │ │ │ └── resources │ │ │ │ ├── application.yml │ │ │ │ └── spring │ │ │ │ └── dubbo-consumer.properties │ │ └── provider │ │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── huaweicse │ │ │ │ └── test │ │ │ │ └── HelloAnnotationServiceImpl.java │ │ │ └── resources │ │ │ ├── application.yml │ │ │ └── spring │ │ │ └── dubbo-provider.properties │ ├── dubbo-springboot │ │ ├── consumer │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── huaweicse │ │ │ │ │ └── test │ │ │ │ │ └── DubboSpringBootConsumerController.java │ │ │ │ └── resources │ │ │ │ └── application.yml │ │ └── provider │ │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── huaweicse │ │ │ │ └── test │ │ │ │ ├── HelloSpringBootAccountServiceImpl.java │ │ │ │ └── HelloSpringBootServiceImpl.java │ │ │ └── resources │ │ │ └── application.yml │ └── dubbo-xml │ │ ├── common-api │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── huaweicse │ │ │ └── test │ │ │ └── api │ │ │ └── HelloXmlService.java │ │ ├── consumer │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── huaweicse │ │ │ │ └── test │ │ │ │ └── DubboXmlConsumerController.java │ │ │ └── resources │ │ │ ├── application.properties │ │ │ └── consumer.xml │ │ └── provider │ │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── huaweicse │ │ │ └── test │ │ │ └── HelloXmlServiceImpl.java │ │ └── resources │ │ ├── application.properties │ │ └── provider.xml └── output │ ├── dubbo-annotation │ ├── DubboAnnotationConsumerController.java │ └── DubboInterfaceConfig.java │ ├── dubbo-springboot │ ├── DubboInterfaceConfig.java │ └── DubboSpringBootConsumerController.java │ └── dubbo-xml │ ├── DubboInterfaceConfig.java │ └── HelloXmlServiceImpl.java ├── ModifyDubboServiceActionTest ├── input │ └── HelloServiceImpl.java └── output │ └── HelloServiceImpl.java ├── ModifyEurekaMainClassActionTest ├── input │ ├── EurekaConsumerApplication.java │ └── EurekaProviderApplication.java └── output │ ├── EurekaConsumerApplication.java │ └── EurekaProviderApplication.java ├── ModifyHSFAddBootstrapYamlActionTest └── src │ └── main │ └── resources │ └── application.properties ├── ModifyHSFMainClassActionTest ├── input │ └── HSFConsumerApplication.java └── output │ └── HSFConsumerApplication.java ├── ModifyNacosActionTest ├── input │ ├── consumer │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── huaweicse │ │ │ │ └── test │ │ │ │ ├── ConsumerApplication.java │ │ │ │ ├── ConsumerController.java │ │ │ │ └── ProviderService.java │ │ │ └── resources │ │ │ └── application.yml │ ├── pom.xml │ └── provider │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── huaweicse │ │ │ └── test │ │ │ ├── ProviderApplication.java │ │ │ ├── ProviderController.java │ │ │ └── ProviderService.java │ │ └── resources │ │ └── application.yml └── output │ ├── consumer │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── huaweicse │ │ │ └── test │ │ │ ├── ConsumerApplication.java │ │ │ ├── ConsumerController.java │ │ │ └── ProviderService.java │ │ └── resources │ │ ├── application.yml │ │ └── bootstrap.yml │ ├── pom.xml │ └── provider │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── huaweicse │ │ └── test │ │ ├── ProviderApplication.java │ │ ├── ProviderController.java │ │ └── ProviderService.java │ └── resources │ ├── application.yml │ └── bootstrap.yml ├── ModifyPomActionTest ├── input │ └── pom.xml └── output │ └── pom.xml ├── input ├── HSFConsumerNonstandardConfig.java ├── HSFConsumerStandardConfig.java ├── HSFInterfaceService.java └── HSFInterfaceServiceImpl.java └── output ├── HSFConsumerNonstandardConfig.java ├── HSFConsumerStandardConfig.java ├── HSFInterfaceService.java └── HSFInterfaceServiceImpl.java /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: Java CI with Maven 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Set up JDK 1.8 20 | uses: actions/setup-java@v1 21 | with: 22 | java-version: 1.8 23 | - uses: actions/cache@v2 24 | with: 25 | path: ~/.m2/repository 26 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 27 | restore-keys: | 28 | ${{ runner.os }}-maven- 29 | - name: Compilation and Installation 30 | run: mvn clean install 31 | 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huaweicse/migrator/f38671ba495b6ea0c66467ca091ea82942f0c40f/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # migrator 2 | Tools set to migrate applications 3 | 4 | See [Wiki](https://github.com/huaweicse/migrator/wiki) for details 5 | 6 | # 迁移工具 7 | 本项目提供一系列工具迁移微服务应用。 8 | 9 | 详细说明请参考[Wiki](https://github.com/huaweicse/migrator/wiki) -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/Library/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 2.6.4 10 | 11 | 12 | 13 | com.huaweicse.tools 14 | migrator 15 | 0.0.1-SNAPSHOT 16 | migrator 17 | Tools set to migrate applications to Spring Boot 18 | 19 | 20 | 1.8 21 | 1.2.79 22 | 2.11.0 23 | 3.8.4 24 | 1.6.1 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter 31 | 32 | 33 | com.alibaba 34 | fastjson 35 | ${fastJson.version} 36 | 37 | 38 | commons-io 39 | commons-io 40 | ${commons-io.version} 41 | 42 | 43 | org.apache.maven 44 | maven-model 45 | ${maven-model.version} 46 | 47 | 48 | org.yaml 49 | snakeyaml 50 | 51 | 52 | dom4j 53 | dom4j 54 | ${dom4j.version} 55 | 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-starter-test 60 | test 61 | 62 | 63 | org.junit.platform 64 | junit-platform-launcher 65 | test 66 | 67 | 68 | org.junit.vintage 69 | junit-vintage-engine 70 | test 71 | 72 | 73 | 74 | 75 | 76 | 77 | org.springframework.boot 78 | spring-boot-maven-plugin 79 | 80 | 81 | maven-resources-plugin 82 | 83 | 84 | copy-templates 85 | process-sources 86 | 87 | copy-resources 88 | 89 | 90 | ${basedir}/target/templates 91 | 92 | 93 | ${basedir}/templates 94 | 95 | **/** 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/MigrateApplication.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator; 2 | 3 | import java.util.Map; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.Banner.Mode; 9 | import org.springframework.boot.CommandLineRunner; 10 | import org.springframework.boot.SpringApplication; 11 | import org.springframework.boot.autoconfigure.SpringBootApplication; 12 | import org.springframework.context.ApplicationContext; 13 | 14 | import com.huaweicse.tools.migrator.common.Action; 15 | 16 | @SpringBootApplication 17 | public class MigrateApplication implements CommandLineRunner { 18 | 19 | private static final Logger LOGGER = LoggerFactory.getLogger(MigrateApplication.class); 20 | 21 | public static void main(String[] args) { 22 | SpringApplication springApplication = new SpringApplication(MigrateApplication.class); 23 | springApplication.setBannerMode(Mode.OFF); 24 | springApplication.run(args); 25 | } 26 | 27 | @Autowired 28 | ApplicationContext applicationContext; 29 | 30 | @Override 31 | public void run(String... args) { 32 | Map beansOfType = applicationContext.getBeansOfType(Action.class); 33 | if (args.length < 2) { 34 | printUsage(beansOfType); 35 | return; 36 | } 37 | Action action = targetAction(args[0], beansOfType); 38 | if (action == null) { 39 | printUsage(beansOfType); 40 | return; 41 | } 42 | try { 43 | action.run(args[1]); 44 | } catch (Exception e) { 45 | LOGGER.error("run failed.", e); 46 | } 47 | LOGGER.info("MigrateApplication run finished."); 48 | } 49 | 50 | private Action targetAction(String arg, Map beansOfType) { 51 | for (Map.Entry entry : beansOfType.entrySet()) { 52 | if (entry.getValue().name().equals(arg)) { 53 | return entry.getValue(); 54 | } 55 | } 56 | return null; 57 | } 58 | 59 | private void printUsage(Map beansOfType) { 60 | LOGGER.error("Usage: "); 61 | LOGGER.error("java -jar migrator-0.0.1-SNAPSHOT.jar action [options]"); 62 | LOGGER.error("Available actions: "); 63 | beansOfType.forEach((k, v) -> LOGGER.error(v.name())); 64 | } 65 | } -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/common/Action.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.common; 2 | 3 | import java.io.CharArrayWriter; 4 | import java.io.File; 5 | import java.io.IOException; 6 | 7 | public interface Action { 8 | String ERROR_MESSAGE = "Manual processing is required. Cause is [{}]." 9 | + "File is [{}]. Line is [{}]"; 10 | 11 | String FILE_SEPARATOR = File.separator; 12 | 13 | default void writeLine(CharArrayWriter tempStream, String line) throws IOException { 14 | tempStream.write(line); 15 | tempStream.append(System.lineSeparator()); 16 | } 17 | 18 | default String name() { 19 | return this.getClass().getSimpleName(); 20 | } 21 | 22 | void run(String... args) throws Exception; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/common/AddBootstrapYamlAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.common; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.util.stream.Stream; 7 | 8 | import org.apache.commons.io.FileUtils; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | /** 13 | * 功能描述: 14 | * 在项目的 src/main/resources 目录下添加 bootstrap.yml 文件。 15 | */ 16 | public abstract class AddBootstrapYamlAction implements Action { 17 | 18 | private static final Logger LOGGER = LoggerFactory.getLogger(AddBootstrapYamlAction.class); 19 | 20 | public static final String BASE_PATH = System.getProperty("user.dir"); 21 | 22 | @Override 23 | public void run(String... args) { 24 | File folder = new File(args[0]); 25 | addYaml(folder); 26 | 27 | File[] files = folder.listFiles(); 28 | if (files == null) { 29 | return; 30 | } 31 | Stream.of(files).forEach(this::addYaml); 32 | } 33 | 34 | private void addYaml(File file) { 35 | File child = new File(file, "src" + FILE_SEPARATOR + "main" + FILE_SEPARATOR + "resources"); 36 | if (child.isDirectory()) { 37 | addYmlFile(new File(child, "bootstrap.yml")); 38 | } 39 | } 40 | 41 | private void addYmlFile(File file) { 42 | try { 43 | String originBootstrapContextPath = BASE_PATH + FILE_SEPARATOR + "templates"; 44 | FileInputStream fileInputStream = new FileInputStream( 45 | originBootstrapContextPath + FILE_SEPARATOR + "bootstrap.yml"); 46 | FileUtils.copyInputStreamToFile(fileInputStream, file); 47 | } catch (IOException ex) { 48 | // 如果添加配置文件失败,则后续进行手动添加 49 | LOGGER.error("add bootstrap.yml failed,need manual processing is required and message is {},", ex.getMessage()); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/common/Const.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.common; 2 | 3 | import org.springframework.beans.factory.InitializingBean; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | public class Const implements InitializingBean { 9 | 10 | @Value("${spring.responseBody.packageName:org.springframework.web.bind.annotation.ResponseBody}") 11 | private String responseBodyPackageName; 12 | 13 | @Value("${spring.postMapping.packageName:org.springframework.web.bind.annotation.PostMapping}") 14 | private String postMappingPackageName; 15 | 16 | @Value("${spring.requestParam.packageName:org.springframework.web.bind.annotation.RequestParam}") 17 | private String requestParamPackageName; 18 | 19 | @Value("${spring.requestBody.packageName:org.springframework.web.bind.annotation.RequestBody}") 20 | private String requestBodyPackageName; 21 | 22 | @Value("${spring.propertySource.packageName:org.springframework.context.annotation.PropertySource}") 23 | private String propertySourcePackageName; 24 | 25 | @Value("${spring.enableFeignClients.packageName:org.springframework.cloud.openfeign.EnableFeignClients}") 26 | private String enableFeignClientsPackageName; 27 | 28 | @Value("${spring.importResource.packageName:org.springframework.context.annotation.ImportResource}") 29 | private String importResourcePackageName; 30 | 31 | @Value("${spring.autowired.packageName:org.springframework.beans.factory.annotation.Autowired}") 32 | private String autowiredPackageName; 33 | 34 | @Value("${spring.feignClient.packageName:org.springframework.cloud.openfeign.FeignClient}") 35 | private String feignClientPackageName; 36 | 37 | @Value("${spring.configuration.packageName:org.springframework.context.annotation.Configuration}") 38 | private String configurationPackageName; 39 | 40 | @Value("${spring.requestMapping.packageName:org.springframework.web.bind.annotation.RequestMapping}") 41 | private String requestMappingPackageName; 42 | 43 | @Value("${spring.restController.packageName:org.springframework.web.bind.annotation.RestController}") 44 | private String restControllerPackageName; 45 | 46 | @Value("${spring.enableDiscoveryClient.packageName:org.springframework.cloud.client.discovery.EnableDiscoveryClient}") 47 | private String enableDiscoveryClientPackageName; 48 | 49 | @Value("${spring.enableEurekaClient.packageName:org.springframework.cloud.netflix.eureka.EnableEurekaClient}") 50 | private String enableEurekaClientPackageName; 51 | 52 | @Value("${spring.enableEurekaServer.packageName:org.springframework.cloud.netflix.eureka.server.EnableEurekaServer}") 53 | private String enableEurekaServerPackageName; 54 | 55 | @Value("${dubbo.enableDubbo.packageName:org.apache.dubbo.config.spring.context.annotation.EnableDubbo}") 56 | private String enableDubboPackageName; 57 | 58 | @Value("${dubbo.dubboReference.packageName:org.apache.dubbo.config.annotation.DubboReference}") 59 | private String dubboReferencePackageName; 60 | 61 | @Value("${dubbo.provider.packageName:org.apache.dubbo.config.annotation.DubboService}") 62 | private String dubboProviderPackageName; 63 | 64 | @Value("${hsf.consumer.packageName:com.alibaba.boot.hsf.annotation.HSFConsumer}") 65 | private String hsfConsumerPackageName; 66 | 67 | @Value("${hsf.provider.packageName:com.alibaba.boot.hsf.annotation.HSFProvider}") 68 | private String hSFProviderPackageName; 69 | 70 | @Value("${hsf.pandoraBootstrap.packageName:com.taobao.pandora.boot.PandoraBootstrap}") 71 | private String pandoraBootstrapPackageName; 72 | 73 | public static String ENABLE_DISCOVERY_CLIENT_PACKAGE_NAME; 74 | 75 | public static String ENABLE_FEIGN_CLIENTS_PACKAGE_NAME; 76 | 77 | public static String PROPERTY_SOURCE_PACKAGE_NAME; 78 | 79 | public static String IMPORT_RESOURCE_PACKAGE_NAME; 80 | 81 | public static String REST_CONTROLLER_PACKAGE_NAME; 82 | 83 | public static String REQUEST_MAPPING_PACKAGE_NAME; 84 | 85 | public static String RESPONSE_BODY_PACKAGE_NAME; 86 | 87 | public static String POST_MAPPING_PACKAGE_NAME; 88 | 89 | public static String REQUEST_PARAM_PACKAGE_NAME; 90 | 91 | public static String REQUEST_BODY_PACKAGE_NAME; 92 | 93 | public static String AUTOWIRED_PACKAGE_NAME; 94 | 95 | public static String FEIGN_CLIENT_PACKAGE_NAME; 96 | 97 | public static String CONFIGURATION_PACKAGE_NAME; 98 | 99 | public static String ENABLE_EUREKA_CLIENT_PACKAGE_NAME; 100 | 101 | public static String ENABLE_EUREKA_SERVER_PACKAGE_NAME; 102 | 103 | public static String ENABLE_DUBBO_PACKAGE_NAME; 104 | 105 | public static String DUBBO_REFERENCE_PACKAGE_NAME; 106 | 107 | public static String DUBBO_PROVIDER_PACKAGE_NAME; 108 | 109 | public static String HSF_CONSUMER_PACKAGE_NAME; 110 | 111 | public static String HSF_PROVIDER_PACKAGE_NAME; 112 | 113 | public static String PANDORA_BOOT_STRAP_PACKAGE_NAME; 114 | 115 | @Override 116 | public void afterPropertiesSet() { 117 | ENABLE_DISCOVERY_CLIENT_PACKAGE_NAME = enableDiscoveryClientPackageName; 118 | ENABLE_FEIGN_CLIENTS_PACKAGE_NAME = enableFeignClientsPackageName; 119 | PROPERTY_SOURCE_PACKAGE_NAME = propertySourcePackageName; 120 | IMPORT_RESOURCE_PACKAGE_NAME = importResourcePackageName; 121 | REST_CONTROLLER_PACKAGE_NAME = restControllerPackageName; 122 | REQUEST_MAPPING_PACKAGE_NAME = requestMappingPackageName; 123 | RESPONSE_BODY_PACKAGE_NAME = responseBodyPackageName; 124 | POST_MAPPING_PACKAGE_NAME = postMappingPackageName; 125 | REQUEST_PARAM_PACKAGE_NAME = requestParamPackageName; 126 | REQUEST_BODY_PACKAGE_NAME = requestBodyPackageName; 127 | AUTOWIRED_PACKAGE_NAME = autowiredPackageName; 128 | FEIGN_CLIENT_PACKAGE_NAME = feignClientPackageName; 129 | CONFIGURATION_PACKAGE_NAME = configurationPackageName; 130 | ENABLE_EUREKA_CLIENT_PACKAGE_NAME = enableEurekaClientPackageName; 131 | ENABLE_EUREKA_SERVER_PACKAGE_NAME = enableEurekaServerPackageName; 132 | ENABLE_DUBBO_PACKAGE_NAME = enableDubboPackageName; 133 | DUBBO_REFERENCE_PACKAGE_NAME = dubboReferencePackageName; 134 | DUBBO_PROVIDER_PACKAGE_NAME = dubboProviderPackageName; 135 | HSF_CONSUMER_PACKAGE_NAME = hsfConsumerPackageName; 136 | HSF_PROVIDER_PACKAGE_NAME = hSFProviderPackageName; 137 | PANDORA_BOOT_STRAP_PACKAGE_NAME = pandoraBootstrapPackageName; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/common/FileAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.common; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.nio.charset.StandardCharsets; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import org.apache.commons.io.FileUtils; 10 | 11 | public abstract class FileAction implements Action { 12 | protected List acceptedFiles(String folder) throws IOException { 13 | List result = new ArrayList<>(); 14 | File file = new File(folder); 15 | addFiles(file, result); 16 | return result; 17 | } 18 | 19 | private void addFiles(File file, List result) throws IOException { 20 | if (file.isDirectory()) { 21 | File[] children = file.listFiles(); 22 | assert children != null; 23 | for (File child : children) { 24 | addFiles(child, result); 25 | } 26 | return; 27 | } 28 | 29 | if (isAcceptedFile(file)) { 30 | result.add(file); 31 | } 32 | } 33 | 34 | protected abstract boolean isAcceptedFile(File file) throws IOException; 35 | 36 | protected boolean fileContains(File file, String pattern) throws IOException { 37 | String content = FileUtils.readFileToString(file, StandardCharsets.UTF_8); 38 | return content.contains(pattern); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/common/ModifyPomAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.common; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileOutputStream; 6 | import java.io.InputStreamReader; 7 | import java.io.OutputStreamWriter; 8 | import java.nio.charset.StandardCharsets; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | import java.util.Objects; 12 | import java.util.Properties; 13 | import java.util.stream.Stream; 14 | 15 | import org.apache.commons.io.IOUtils; 16 | import org.apache.maven.model.Build; 17 | import org.apache.maven.model.Dependency; 18 | import org.apache.maven.model.DependencyManagement; 19 | import org.apache.maven.model.Model; 20 | import org.apache.maven.model.Plugin; 21 | import org.apache.maven.model.io.xpp3.MavenXpp3Reader; 22 | import org.apache.maven.model.io.xpp3.MavenXpp3Writer; 23 | import org.slf4j.Logger; 24 | import org.slf4j.LoggerFactory; 25 | import org.springframework.util.ObjectUtils; 26 | 27 | import com.alibaba.fastjson.JSONArray; 28 | import com.alibaba.fastjson.JSONObject; 29 | 30 | public abstract class ModifyPomAction implements Action { 31 | 32 | private static final Logger LOGGER = LoggerFactory.getLogger(ModifyPomAction.class); 33 | 34 | public static final String BASE_PATH = System.getProperty("user.dir"); 35 | 36 | private List pomFileList = new ArrayList<>(); 37 | 38 | public abstract String getFrameType(); 39 | 40 | @Override 41 | public void run(String... args) { 42 | File folder = new File(args[0]); 43 | File[] files = folder.listFiles(); 44 | if (files == null) { 45 | return; 46 | } 47 | Stream.of(files).forEach(this::filterPomFile); 48 | modifyContent(); 49 | } 50 | 51 | private void filterPomFile(File file) { 52 | if ("pom.xml".equals(file.getName())) { 53 | pomFileList.add(file); 54 | } else { 55 | File child = new File(file, "pom.xml"); 56 | if (child.exists()) { 57 | pomFileList.add(child); 58 | } 59 | } 60 | } 61 | 62 | protected void modifyContent() { 63 | pomFileList.forEach(file -> { 64 | try { 65 | MavenXpp3Reader reader = new MavenXpp3Reader(); 66 | Model model = reader.read(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)); 67 | String pomJsonPath = BASE_PATH + FILE_SEPARATOR + "templates" + FILE_SEPARATOR + getFrameType() + ".pom.json"; 68 | String pomJsonString = IOUtils.toString(new FileInputStream(pomJsonPath), StandardCharsets.UTF_8); 69 | JSONObject pomJsonObject = JSONObject.parseObject(pomJsonString); 70 | //properties 71 | processProperties(model, pomJsonObject); 72 | //dependencyManagement.dependencies 73 | processDependencyManagement(model, pomJsonObject); 74 | //dependencies 75 | processDependencies(model, pomJsonObject); 76 | //build -> plugins 77 | processPlugins(model, pomJsonObject); 78 | OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(file), 79 | StandardCharsets.UTF_8); 80 | new MavenXpp3Writer().write(outputStreamWriter, model); 81 | IOUtils.close(outputStreamWriter); 82 | } catch (Exception ex) { 83 | LOGGER.error("Process pom.xml [{}] failed", file.getAbsolutePath(), ex); 84 | } 85 | }); 86 | } 87 | 88 | private void processPlugins(Model model, JSONObject pomJsonObject) { 89 | Object pluginsObj = pomJsonObject.get("build.plugins"); 90 | if (pluginsObj != null) { 91 | Build build = model.getBuild(); 92 | if (!ObjectUtils.isEmpty(build)) { 93 | List plugins = build.getPlugins(); 94 | JSONArray jsonPluginArrays = JSONArray.parseArray(pluginsObj.toString()); 95 | jsonPluginArrays.forEach(pluginData -> { 96 | JSONObject dependencyJsonObject = JSONObject.parseObject(pluginData.toString()); 97 | String sign = dependencyJsonObject.get("operation").toString(); 98 | JSONArray dataArrays = JSONArray.parseArray(dependencyJsonObject.get("data").toString()); 99 | if ("add".equals(sign)) { 100 | dataArrays.forEach(data -> { 101 | Plugin plugin = genPlugin(symbolValue(data, "groupId"), 102 | symbolValue(data, "artifactId"), 103 | symbolValue(data, "version")); 104 | plugins.add(plugin); 105 | }); 106 | } 107 | if ("delete".equals(sign)) { 108 | dataArrays.forEach(data -> plugins.removeIf( 109 | plugin -> ((JSONObject) data).get("artifactId").toString().equals(plugin.getArtifactId()))); 110 | } 111 | if ("replace".equals(sign)) { 112 | dataArrays.forEach(data -> { 113 | if (plugins.removeIf(plugin -> (((JSONObject) ((JSONObject) data).get("match")) 114 | .getString("artifactId").equals(plugin.getArtifactId())))) { 115 | JSONArray replacementArrays = JSONArray.parseArray(((JSONObject) data).getString("replacement")); 116 | replacementArrays.forEach(replacementArray -> { 117 | Plugin plugin = genPlugin(symbolValue(replacementArray, "groupId"), 118 | symbolValue(replacementArray, "artifactId"), 119 | symbolValue(replacementArray, "version")); 120 | plugins.add(plugin); 121 | }); 122 | } 123 | }); 124 | } 125 | }); 126 | } 127 | } 128 | } 129 | 130 | private void processDependencies(Model model, JSONObject pomJsonObject) { 131 | Object jsonPomDependencies = pomJsonObject.get("dependencies"); 132 | List dependencies = model.getDependencies(); 133 | if (!ObjectUtils.isEmpty(jsonPomDependencies) && !ObjectUtils.isEmpty(dependencies)) { 134 | JSONArray jsonDependencyArrays = JSONArray.parseArray(jsonPomDependencies.toString()); 135 | jsonDependencyArrays.forEach(dependencyData -> { 136 | JSONObject dependencyJsonObject = JSONObject.parseObject(dependencyData.toString()); 137 | String sign = dependencyJsonObject.get("operation").toString(); 138 | JSONArray dataArrays = JSONArray.parseArray(dependencyJsonObject.get("data").toString()); 139 | if ("add".equals(sign)) { 140 | dataArrays.forEach(data -> { 141 | Dependency dependency = genDependency(symbolValue(data, "groupId"), 142 | symbolValue(data, "artifactId"), 143 | symbolValue(data, "version"), 144 | null, null); 145 | dependencies.add(dependency); 146 | }); 147 | } 148 | if ("delete".equals(sign)) { 149 | dataArrays.forEach(data -> dependencies.removeIf( 150 | dependency -> ((JSONObject) data).get("artifactId").toString().equals(dependency.getArtifactId()))); 151 | } 152 | if ("replace".equals(sign)) { 153 | dataArrays.forEach(data -> { 154 | if (dependencies.removeIf(dependency -> (((JSONObject) ((JSONObject) data).get("match")) 155 | .getString("artifactId").equals(dependency.getArtifactId())))) { 156 | JSONArray replacementArrays = JSONArray.parseArray(((JSONObject) data).getString("replacement")); 157 | replacementArrays.forEach(replacementArray -> { 158 | Dependency replaceDependency = genDependency(symbolValue(replacementArray, "groupId"), 159 | symbolValue(replacementArray, "artifactId"), 160 | symbolValue(replacementArray, "version"), 161 | null, 162 | null); 163 | dependencies.add(replaceDependency); 164 | }); 165 | } 166 | }); 167 | } 168 | }); 169 | } 170 | } 171 | 172 | private void processDependencyManagement(Model model, JSONObject pomJsonObject) { 173 | Object jsonPomDependencyManagements = pomJsonObject.get("dependencyManagement.dependencies"); 174 | DependencyManagement dependencyManagement = model.getDependencyManagement(); 175 | if (!ObjectUtils.isEmpty(jsonPomDependencyManagements) && !ObjectUtils.isEmpty(dependencyManagement)) { 176 | List managementDependencies = dependencyManagement.getDependencies(); 177 | JSONArray jsonDependencyManagementArrays = JSONArray.parseArray(jsonPomDependencyManagements.toString()); 178 | jsonDependencyManagementArrays.forEach(management -> { 179 | JSONObject managementJsonObject = JSONObject.parseObject(management.toString()); 180 | String sign = managementJsonObject.get("operation").toString(); 181 | JSONArray dataArrays = JSONArray.parseArray(managementJsonObject.get("data").toString()); 182 | if ("add".equals(sign)) { 183 | dataArrays.forEach(data -> { 184 | Dependency dependency = genDependency(symbolValue(data, "groupId"), 185 | symbolValue(data, "artifactId"), 186 | symbolValue(data, "version"), 187 | symbolValue(data, "type"), 188 | symbolValue(data, "scope")); 189 | managementDependencies.add(dependency); 190 | }); 191 | } 192 | if ("delete".equals(sign)) { 193 | dataArrays.forEach(data -> managementDependencies.removeIf( 194 | dependency -> ((JSONObject) data).get("artifactId").toString().equals(dependency.getArtifactId()))); 195 | } 196 | if ("replace".equals(sign)) { 197 | dataArrays.forEach(data -> { 198 | if (managementDependencies.removeIf(managementDependency -> (((JSONObject) ((JSONObject) data).get("match")) 199 | .getString("artifactId").equals(managementDependency.getArtifactId())))) { 200 | JSONArray replacementArrays = JSONArray.parseArray(((JSONObject) data).getString("replacement")); 201 | replacementArrays.forEach(replacementArray -> { 202 | Dependency replaceDependency = genDependency(symbolValue(replacementArray, "groupId"), 203 | symbolValue(replacementArray, "artifactId"), 204 | symbolValue(replacementArray, "version"), 205 | symbolValue(replacementArray, "type"), 206 | symbolValue(replacementArray, "scope")); 207 | managementDependencies.add(replaceDependency); 208 | }); 209 | } 210 | }); 211 | } 212 | }); 213 | } 214 | } 215 | 216 | private void processProperties(Model model, JSONObject pomJsonObject) { 217 | Object jsonPomProperties = pomJsonObject.get("properties"); 218 | Properties mavenProperties = model.getProperties(); 219 | if (!ObjectUtils.isEmpty(jsonPomProperties) && !ObjectUtils.isEmpty(mavenProperties)) { 220 | JSONArray jsonPropertiesArrays = JSONArray.parseArray(jsonPomProperties.toString()); 221 | jsonPropertiesArrays.forEach(property -> { 222 | JSONObject propertyJsonObject = JSONObject.parseObject(property.toString()); 223 | JSONArray dataArrays = JSONArray.parseArray(propertyJsonObject.get("data").toString()); 224 | String sign = propertyJsonObject.get("operation").toString(); 225 | if ("add".equals(sign)) { 226 | dataArrays.forEach(data -> mavenProperties.putIfAbsent( 227 | Objects.requireNonNull(symbolValue(data, "property")), 228 | Objects.requireNonNull(symbolValue(data, "value")))); 229 | } 230 | if ("delete".equals(sign)) { 231 | dataArrays.forEach(data -> mavenProperties.remove(Objects.requireNonNull(symbolValue(data, "property")))); 232 | } 233 | if ("replace".equals(sign)) { 234 | dataArrays.forEach(data -> { 235 | String matchPropertyValue = ((JSONObject) ((JSONObject) data).get("match")).getString("property"); 236 | if (mavenProperties.containsKey(matchPropertyValue)) { 237 | mavenProperties.remove(matchPropertyValue); 238 | JSONArray replacementArrays = JSONArray.parseArray(((JSONObject) data).getString("replacement")); 239 | replacementArrays.forEach(replacementArray -> mavenProperties 240 | .putIfAbsent(Objects.requireNonNull(symbolValue(replacementArray, "property")), 241 | Objects.requireNonNull(symbolValue(replacementArray, "value")))); 242 | } 243 | }); 244 | } 245 | }); 246 | model.setProperties(new OrderedWriteProperties(mavenProperties)); 247 | } 248 | } 249 | 250 | private String symbolValue(Object data, String... symbol) { 251 | Object result = data; 252 | for (String s : symbol) { 253 | result = ((JSONObject) result).get(s); 254 | } 255 | return result == null ? null : result.toString(); 256 | } 257 | 258 | private Plugin genPlugin(String groupId, String artifactId, String version) { 259 | Plugin plugin = new Plugin(); 260 | plugin.setGroupId(groupId); 261 | plugin.setArtifactId(artifactId); 262 | if (!ObjectUtils.isEmpty(version)) { 263 | plugin.setVersion(version); 264 | } 265 | return plugin; 266 | } 267 | 268 | private Dependency genDependency(String groupId, String artifactId, String version, String type, String scope) { 269 | Dependency dependency = new Dependency(); 270 | dependency.setGroupId(groupId); 271 | dependency.setArtifactId(artifactId); 272 | if (!ObjectUtils.isEmpty(version)) { 273 | dependency.setVersion(version); 274 | } 275 | if (!ObjectUtils.isEmpty(type)) { 276 | dependency.setType(type); 277 | } 278 | if (!ObjectUtils.isEmpty(type)) { 279 | dependency.setScope(scope); 280 | } 281 | return dependency; 282 | } 283 | } 284 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/common/OrderedWriteProperties.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.common; 2 | 3 | import java.util.LinkedHashSet; 4 | import java.util.Properties; 5 | import java.util.Set; 6 | 7 | // ordered write properties 8 | public class OrderedWriteProperties extends Properties { 9 | public OrderedWriteProperties(Properties other) { 10 | super(); 11 | putAll(other); 12 | } 13 | 14 | @Override 15 | public Set keySet() { 16 | return new LinkedHashSet<>(super.keySet()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/common/ParamValueType.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.common; 2 | 3 | public enum ParamValueType { 4 | String, 5 | Byte, 6 | Short, 7 | Integer, 8 | Long, 9 | Float, 10 | Double, 11 | Boolean, 12 | Character 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/dubbo/ModifyDubboAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.dubbo; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Component; 5 | 6 | import com.huaweicse.tools.migrator.common.Action; 7 | 8 | @Component 9 | public class ModifyDubboAction implements Action { 10 | 11 | private ModifyDubboInterface2RestAction modifyDubboInterface2RestAction; 12 | 13 | private ModifyDubboAddBootstrapYamlAction modifyDubboAddBootstrapYamlAction; 14 | 15 | private ModifyDubboMainClassAction modifyDubboMainClassAction; 16 | 17 | private ModifyDubboPomAction modifyDubboPomAction; 18 | 19 | private ModifyDubboReferenceAction modifyDubboReferenceAction; 20 | 21 | private ModifyDubboServiceAction modifyDubboServiceAction; 22 | 23 | @Autowired 24 | public ModifyDubboAction( 25 | ModifyDubboInterface2RestAction modifyDubboInterface2RestAction, 26 | ModifyDubboAddBootstrapYamlAction modifyDubboAddBootstrapYamlAction, 27 | ModifyDubboMainClassAction modifyDubboMainClassAction, 28 | ModifyDubboPomAction modifyDubboPomAction, 29 | ModifyDubboReferenceAction modifyDubboReferenceAction, 30 | ModifyDubboServiceAction modifyDubboServiceAction) { 31 | this.modifyDubboInterface2RestAction = modifyDubboInterface2RestAction; 32 | this.modifyDubboAddBootstrapYamlAction = modifyDubboAddBootstrapYamlAction; 33 | this.modifyDubboMainClassAction = modifyDubboMainClassAction; 34 | this.modifyDubboPomAction = modifyDubboPomAction; 35 | this.modifyDubboReferenceAction = modifyDubboReferenceAction; 36 | this.modifyDubboServiceAction = modifyDubboServiceAction; 37 | } 38 | 39 | @Override 40 | public void run(String... args) throws Exception { 41 | Action[] actions = new Action[] {modifyDubboInterface2RestAction, modifyDubboAddBootstrapYamlAction 42 | , modifyDubboMainClassAction, modifyDubboPomAction, modifyDubboReferenceAction, modifyDubboServiceAction}; 43 | for (Action action : actions) { 44 | action.run(args); 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/dubbo/ModifyDubboAddBootstrapYamlAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.dubbo; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import com.huaweicse.tools.migrator.common.AddBootstrapYamlAction; 6 | 7 | /** 8 | * 功能描述: 9 | * 在项目的 src/main/resources 目录下添加 bootstrap.yml 文件。 10 | */ 11 | @Component 12 | public class ModifyDubboAddBootstrapYamlAction extends AddBootstrapYamlAction { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/dubbo/ModifyDubboInterface2RestAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.dubbo; 2 | 3 | import java.io.CharArrayWriter; 4 | import java.io.File; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.io.OutputStreamWriter; 8 | import java.nio.charset.StandardCharsets; 9 | import java.util.ArrayList; 10 | import java.util.Arrays; 11 | import java.util.Iterator; 12 | import java.util.List; 13 | import java.util.regex.Matcher; 14 | import java.util.regex.Pattern; 15 | import java.util.stream.Collectors; 16 | 17 | import org.apache.commons.io.FileUtils; 18 | import org.dom4j.DocumentException; 19 | import org.dom4j.Element; 20 | import org.dom4j.io.SAXReader; 21 | import org.slf4j.Logger; 22 | import org.slf4j.LoggerFactory; 23 | import org.springframework.stereotype.Component; 24 | import org.springframework.util.ObjectUtils; 25 | 26 | import com.huaweicse.tools.migrator.common.Const; 27 | import com.huaweicse.tools.migrator.common.FileAction; 28 | import com.huaweicse.tools.migrator.common.ParamValueType; 29 | 30 | /** 31 | * 功能描述: 32 | * 扫描目录下面的所有JAVA文件,首先扫描出包含 @DubboService 标签的文件,并从中解析出需要处理的 JAVA interface文件, 33 | * 然后将 interface 文件修改为 REST 风格。 替换过程中,会替换 import,一并修改 import。 34 | */ 35 | @Component 36 | public class ModifyDubboInterface2RestAction extends FileAction { 37 | 38 | private static final Logger LOGGER = LoggerFactory.getLogger(ModifyDubboInterface2RestAction.class); 39 | 40 | private static final String INTERFACE_REGEX_PATTERN = "implements [a-zA-Z][a-zA-Z0-9]*"; 41 | 42 | private static final String DUBBO_SERVICE = "@DubboService"; 43 | 44 | private static final String ROUTER_REGEX_PATTERN = "[/*{}]"; 45 | 46 | private List interfaceNameList = new ArrayList<>(); 47 | 48 | @Override 49 | public void run(String... args) throws Exception { 50 | List acceptedFiles = acceptedFiles(args[0]); 51 | List xmlFiles = acceptedFiles.stream().filter(file -> file.getName().endsWith(".xml")) 52 | .collect(Collectors.toList()); 53 | if (!ObjectUtils.isEmpty(xmlFiles)) { 54 | parseXmlGetInterfaceNameList(xmlFiles); 55 | acceptedFiles.removeAll(xmlFiles); 56 | } else { 57 | List interfaceExposeFiles = new ArrayList<>(); 58 | for (File file : acceptedFiles) { 59 | if (file.getName().endsWith("java") && fileContains(file, DUBBO_SERVICE)) { 60 | interfaceExposeFiles.add(file); 61 | } 62 | } 63 | targetInterfaceName(interfaceExposeFiles); 64 | acceptedFiles.removeAll(interfaceExposeFiles); 65 | } 66 | replaceContent(acceptedFiles, interfaceNameList); 67 | } 68 | 69 | private void parseXmlGetInterfaceNameList(List xmlFiles) { 70 | xmlFiles.forEach(file -> { 71 | try { 72 | SAXReader saxReader = new SAXReader(); 73 | Element rootElement = saxReader.read(file).getRootElement(); 74 | Iterator interfaceServices = rootElement.elementIterator("service"); 75 | while (interfaceServices.hasNext()) { 76 | Element next = (Element) interfaceServices.next(); 77 | String str = next.attribute("interface").getValue(); 78 | interfaceNameList.add(str.substring(str.lastIndexOf(".") + 1)); 79 | } 80 | } catch (DocumentException e) { 81 | LOGGER.error("Process xml file [{}] to get interfaceName failed", file.getAbsolutePath(), e); 82 | } 83 | }); 84 | } 85 | 86 | 87 | private void targetInterfaceName(List interfaceExposeFiles) throws IOException { 88 | for (File file : interfaceExposeFiles) { 89 | List lines = FileUtils.readLines(file, StandardCharsets.UTF_8); 90 | for (int i = 0; i < lines.size(); i++) { 91 | String line = lines.get(i); 92 | if (line.trim().startsWith(DUBBO_SERVICE)) { 93 | Pattern pattern = Pattern.compile(INTERFACE_REGEX_PATTERN); 94 | String nextLine = lines.get(i + 1); 95 | Matcher matcher = pattern.matcher(nextLine); 96 | String interfaceName = null; 97 | while (matcher.find()) { 98 | interfaceName = matcher.group().replace("implements ", ""); 99 | } 100 | if (interfaceName == null) { 101 | LOGGER.error(ERROR_MESSAGE, "@DubboSerivce not follow interface definition.", file.getAbsolutePath(), i); 102 | break; 103 | } 104 | interfaceNameList.add(interfaceName); 105 | break; 106 | } 107 | } 108 | } 109 | } 110 | 111 | @Override 112 | protected boolean isAcceptedFile(File file) throws IOException { 113 | if (file.getName().endsWith(".java") || file.getName().endsWith(".xml")) { 114 | return file.getName().endsWith(".xml") ? fileContains(file, "dubbo:service") 115 | : fileContains(file, DUBBO_SERVICE) || fileContains(file, "interface"); 116 | } 117 | return false; 118 | } 119 | 120 | private void replaceContent(List acceptedFiles, List interfaceData) { 121 | acceptedFiles.forEach(file -> { 122 | try { 123 | if (interfaceData.size() == 0) { 124 | return; 125 | } 126 | CharArrayWriter tempStream = new CharArrayWriter(); 127 | String tempInterfaceData = null; 128 | for (String data : interfaceData) { 129 | if (data.equals(file.getName().replace(".java", ""))) { 130 | List lines = FileUtils.readLines(file, StandardCharsets.UTF_8); 131 | for (String line : lines) { 132 | if (line.contains("package")) { 133 | writeLine(tempStream, line); 134 | writeLine(tempStream, ""); 135 | writeLine(tempStream, "import " + Const.RESPONSE_BODY_PACKAGE_NAME + ";"); 136 | writeLine(tempStream, "import " + Const.POST_MAPPING_PACKAGE_NAME + ";"); 137 | writeLine(tempStream, "import " + Const.REQUEST_PARAM_PACKAGE_NAME + ";"); 138 | writeLine(tempStream, "import " + Const.REQUEST_BODY_PACKAGE_NAME + ";"); 139 | continue; 140 | } 141 | if (!("".equals(line) || isEffectiveInterface(line))) { 142 | String[] strings = line.trim().replace("(", " ").split(" "); 143 | writeLine(tempStream, " @ResponseBody"); 144 | ArrayList paramList = paramHandling(line, file); 145 | if (paramList == null) { 146 | writeLine(tempStream, postMappingString(strings[0], strings[1], "0")); 147 | writeLine(tempStream, line); 148 | } else { 149 | writeLine(tempStream, 150 | postMappingString(strings[0], strings[1], paramList.get(paramList.size() - 1))); 151 | writeLine(tempStream, interfaceInfo(line, paramList)); 152 | } 153 | continue; 154 | } 155 | writeLine(tempStream, line); 156 | } 157 | tempInterfaceData = data; 158 | OutputStreamWriter fileWriter = new OutputStreamWriter(new FileOutputStream(file), 159 | StandardCharsets.UTF_8); 160 | tempStream.writeTo(fileWriter); 161 | fileWriter.close(); 162 | } 163 | } 164 | interfaceData.remove(tempInterfaceData); 165 | } catch (IOException e) { 166 | LOGGER.error("error modifying content and filePath is {}", file.getAbsolutePath()); 167 | } 168 | }); 169 | } 170 | 171 | private static ArrayList paramHandling(String line, File file) { 172 | String[] tempParams = line.substring(line.indexOf("(") + 1, line.lastIndexOf(")")) 173 | .replaceAll(",", " ").split(" "); 174 | if (tempParams.length == 1) { 175 | return null; 176 | } 177 | int requestBodyCount = 0; 178 | List paramStrings = Arrays.stream(tempParams) 179 | .filter(param -> !"".equals(param)) 180 | .collect(Collectors.toList()); 181 | ArrayList params = new ArrayList<>(paramStrings.size()); 182 | for (int i = 0; i < paramStrings.size(); i++) { 183 | String tempParam = paramStrings.get(i); 184 | if (i % 2 == 0) { 185 | if (isComplexType(tempParam)) { 186 | params.add("@RequestBody " + tempParam); 187 | requestBodyCount++; 188 | if (requestBodyCount >= 2) { 189 | String methodName = line.trim().substring(line.trim().indexOf(" ") + 1, line.trim().indexOf("(")); 190 | LOGGER.error("RequestBody too much, need to reconstruct parameters and method name is {} of {}", 191 | methodName, file.getName()); 192 | } 193 | } else { 194 | params.add("@RequestParam(value=\"" + paramStrings.get(i + 1) + "\") " + tempParam); 195 | } 196 | continue; 197 | } 198 | params.add(tempParam); 199 | } 200 | params.add(String.valueOf(requestBodyCount)); 201 | return params; 202 | } 203 | 204 | private static boolean isComplexType(String param) { 205 | ParamValueType[] values = ParamValueType.values(); 206 | for (ParamValueType value : values) { 207 | if (param.equalsIgnoreCase(value.name()) || "int".equals(value.name()) || "char".equals(value.name())) { 208 | return false; 209 | } 210 | } 211 | return true; 212 | } 213 | 214 | private String postMappingString(String resultTypeValue, String router, String bodyCount) { 215 | StringBuilder stringBuilder = new StringBuilder(); 216 | stringBuilder.append(" @PostMapping(value = \"/") 217 | .append(router) 218 | .append("\""); 219 | if (isComplexType(resultTypeValue)) { 220 | stringBuilder.append(", produces = \"x-application/hessian2\""); 221 | } 222 | if (Integer.parseInt(bodyCount) >= 1) { 223 | stringBuilder.append(", consumes = \"x-application/hessian2\""); 224 | } 225 | stringBuilder.append(")"); 226 | return new String(stringBuilder); 227 | } 228 | 229 | private String interfaceInfo(String line, ArrayList paramList) { 230 | String substring = line.substring(0, line.indexOf("(")); 231 | if (Integer.parseInt(paramList.get(paramList.size() - 1)) > 1) { 232 | return line; 233 | } 234 | paramList.remove(paramList.get(paramList.size() - 1)); 235 | StringBuilder stringBuilder = new StringBuilder(); 236 | stringBuilder.append(substring) 237 | .append("("); 238 | for (int i = 0; i < paramList.size(); i++) { 239 | if (i % 2 == 0) { 240 | stringBuilder.append(paramList.get(i)).append(" "); 241 | continue; 242 | } 243 | if (i == (paramList.size() - 1)) { 244 | stringBuilder.append(paramList.get(i)); 245 | continue; 246 | } 247 | stringBuilder.append(paramList.get(i)).append(", "); 248 | } 249 | stringBuilder.append(");"); 250 | return new String(stringBuilder); 251 | } 252 | 253 | private boolean isEffectiveInterface(String line) { 254 | Pattern pattern = Pattern.compile(ROUTER_REGEX_PATTERN); 255 | Matcher matcher = pattern.matcher(line); 256 | return matcher.find(); 257 | } 258 | } -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/dubbo/ModifyDubboMainClassAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.dubbo; 2 | 3 | import java.io.CharArrayWriter; 4 | import java.io.File; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.io.OutputStreamWriter; 8 | import java.nio.charset.StandardCharsets; 9 | import java.util.List; 10 | 11 | import org.apache.commons.io.FileUtils; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | import org.springframework.stereotype.Component; 15 | 16 | import com.huaweicse.tools.migrator.common.Const; 17 | import com.huaweicse.tools.migrator.common.FileAction; 18 | 19 | /** 20 | * 功能描述: 21 | * 扫描目录下面的所有JAVA文件,识别文件是否包含main函数,并将相关 @EnableDubbo 逻辑改为 Spring Boot。 22 | * 替换过程中,会替换 import,一并修改 import。 23 | */ 24 | @Component 25 | public class ModifyDubboMainClassAction extends FileAction { 26 | 27 | private static final Logger LOGGER = LoggerFactory.getLogger(ModifyDubboMainClassAction.class); 28 | 29 | private static final String ENABLE_DUBBO = "@EnableDubbo"; 30 | 31 | private static final String IMPORT_RESOURCE = "@ImportResource"; 32 | 33 | @Override 34 | public void run(String... args) throws Exception { 35 | List acceptedFiles = acceptedFiles(args[0]); 36 | replaceContent(acceptedFiles); 37 | } 38 | 39 | @Override 40 | protected boolean isAcceptedFile(File file) throws IOException { 41 | if (!file.getName().endsWith(".java")) { 42 | return false; 43 | } 44 | return fileContains(file, ENABLE_DUBBO) || fileContains(file, IMPORT_RESOURCE); 45 | } 46 | 47 | private void replaceContent(List acceptedFiles) { 48 | for (File file : acceptedFiles) { 49 | try { 50 | List lines = FileUtils.readLines(file, StandardCharsets.UTF_8); 51 | CharArrayWriter tempStream = new CharArrayWriter(); 52 | for (String line : lines) { 53 | if (line.contains(Const.PROPERTY_SOURCE_PACKAGE_NAME)) { 54 | continue; 55 | } 56 | if (line.startsWith("import") && (line.contains(Const.ENABLE_DUBBO_PACKAGE_NAME) || line 57 | .contains(Const.IMPORT_RESOURCE_PACKAGE_NAME))) { 58 | line = line.replace(Const.ENABLE_DUBBO_PACKAGE_NAME, Const.ENABLE_DISCOVERY_CLIENT_PACKAGE_NAME); 59 | line = line.replace(Const.IMPORT_RESOURCE_PACKAGE_NAME, Const.ENABLE_DISCOVERY_CLIENT_PACKAGE_NAME); 60 | writeLine(tempStream, line); 61 | writeLine(tempStream, "import " + Const.ENABLE_FEIGN_CLIENTS_PACKAGE_NAME + ";"); 62 | continue; 63 | } 64 | if (line.trim().startsWith("@PropertySource")) { 65 | continue; 66 | } 67 | if (line.trim().startsWith(ENABLE_DUBBO) || line.trim().startsWith(IMPORT_RESOURCE)) { 68 | writeLine(tempStream, "@EnableDiscoveryClient"); 69 | writeLine(tempStream, "@EnableFeignClients"); 70 | continue; 71 | } 72 | writeLine(tempStream, line); 73 | } 74 | OutputStreamWriter fileWriter = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); 75 | tempStream.writeTo(fileWriter); 76 | fileWriter.close(); 77 | } catch (Exception e) { 78 | LOGGER.error("Process file [{}] failed", file.getAbsolutePath(), e); 79 | } 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/dubbo/ModifyDubboPomAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.dubbo; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import com.huaweicse.tools.migrator.common.ModifyPomAction; 6 | 7 | /** 8 | * 功能描述: 9 | * 扫描目录下面的所有POM文件,删除Dubbo相关的依赖、插件,增加Spring Cloud相关的依赖、插件。 10 | */ 11 | @Component 12 | public class ModifyDubboPomAction extends ModifyPomAction { 13 | @Override 14 | public String getFrameType() { 15 | return "dubbo"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/dubbo/ModifyDubboServiceAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.dubbo; 2 | 3 | import java.io.CharArrayWriter; 4 | import java.io.File; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.io.OutputStreamWriter; 8 | import java.nio.charset.StandardCharsets; 9 | import java.util.List; 10 | import java.util.regex.Matcher; 11 | import java.util.regex.Pattern; 12 | 13 | import org.apache.commons.io.FileUtils; 14 | import org.slf4j.Logger; 15 | import org.slf4j.LoggerFactory; 16 | import org.springframework.stereotype.Component; 17 | 18 | import com.huaweicse.tools.migrator.common.Const; 19 | import com.huaweicse.tools.migrator.common.FileAction; 20 | 21 | /** 22 | * 功能描述: 23 | * 扫描目录下面的所有JAVA文件,识别文件是否包含 @DubboService 标签,如果存在,将其替换为 @RestController。 24 | * 替换过程中,会替换 import,一并修改 import。 25 | */ 26 | @Component 27 | public class ModifyDubboServiceAction extends FileAction { 28 | 29 | private static final Logger LOGGER = LoggerFactory.getLogger(ModifyDubboServiceAction.class); 30 | 31 | private static final String INTERFACE_REGEX_PATTERN = "implements [a-zA-Z][a-zA-Z0-9]*"; 32 | 33 | private static final String DUBBO_SERVICE = "@DubboService"; 34 | 35 | @Override 36 | public void run(String... args) throws Exception { 37 | List acceptedFiles = acceptedFiles(args[0]); 38 | replaceContent(acceptedFiles); 39 | } 40 | 41 | @Override 42 | protected boolean isAcceptedFile(File file) throws IOException { 43 | if (!file.getName().endsWith(".java")) { 44 | return false; 45 | } 46 | return fileContains(file, DUBBO_SERVICE); 47 | } 48 | 49 | private void replaceContent(List acceptedFiles) throws IOException { 50 | for (File file : acceptedFiles) { 51 | List lines = FileUtils.readLines(file, StandardCharsets.UTF_8); 52 | CharArrayWriter tempStream = new CharArrayWriter(); 53 | for (int i = 0; i < lines.size(); i++) { 54 | String line = lines.get(i); 55 | 56 | if (line.contains(Const.DUBBO_PROVIDER_PACKAGE_NAME)) { 57 | line = line.replace(Const.DUBBO_PROVIDER_PACKAGE_NAME, Const.REQUEST_MAPPING_PACKAGE_NAME); 58 | writeLine(tempStream, line); 59 | writeLine(tempStream, "import " + Const.REST_CONTROLLER_PACKAGE_NAME + ";"); 60 | continue; 61 | } 62 | if (line.trim().startsWith(DUBBO_SERVICE)) { 63 | Pattern pattern = Pattern.compile(INTERFACE_REGEX_PATTERN); 64 | String nextLine = lines.get(i + 1); 65 | Matcher matcher = pattern.matcher(nextLine); 66 | String interfaceName = null; 67 | while (matcher.find()) { 68 | interfaceName = matcher.group().replace("implements ", ""); 69 | } 70 | 71 | if (interfaceName == null) { 72 | LOGGER.error(ERROR_MESSAGE, "@DubboSerivce not follow interface definition.", file.getAbsolutePath(), 73 | i); 74 | continue; 75 | } 76 | writeLine(tempStream, "@RestController"); 77 | writeLine(tempStream, 78 | "@RequestMapping(\"/" + interfaceName.substring(0, 1).toLowerCase() + interfaceName.substring(1) 79 | + "\")"); 80 | continue; 81 | } 82 | writeLine(tempStream, line); 83 | } 84 | OutputStreamWriter fileWriter = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); 85 | tempStream.writeTo(fileWriter); 86 | fileWriter.close(); 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/eureka/ModifyEurekaAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.eureka; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Component; 5 | 6 | import com.huaweicse.tools.migrator.common.Action; 7 | 8 | @Component 9 | public class ModifyEurekaAction implements Action { 10 | 11 | private ModifyEurekaAddBootstrapYamlAction modifyEurekaAddBootstrapYamlAction; 12 | 13 | private ModifyEurekaMainClassAction modifyEurekaMainClassAction; 14 | 15 | private ModifyEurekaPomAction modifyEurekaPomAction; 16 | 17 | @Autowired 18 | public ModifyEurekaAction( 19 | ModifyEurekaAddBootstrapYamlAction modifyEurekaAddBootstrapYamlAction, 20 | ModifyEurekaMainClassAction modifyEurekaMainClassAction, 21 | ModifyEurekaPomAction modifyEurekaPomAction) { 22 | this.modifyEurekaAddBootstrapYamlAction = modifyEurekaAddBootstrapYamlAction; 23 | this.modifyEurekaMainClassAction = modifyEurekaMainClassAction; 24 | this.modifyEurekaPomAction = modifyEurekaPomAction; 25 | } 26 | 27 | @Override 28 | public void run(String... args) throws Exception { 29 | Action[] actions = new Action[] {modifyEurekaAddBootstrapYamlAction, modifyEurekaMainClassAction 30 | , modifyEurekaPomAction}; 31 | for (Action action : actions) { 32 | action.run(args); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/eureka/ModifyEurekaAddBootstrapYamlAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.eureka; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import com.huaweicse.tools.migrator.common.AddBootstrapYamlAction; 6 | 7 | /** 8 | * 功能描述: 9 | * 在项目的 src/main/resources 目录下添加 bootstrap.yml 文件。 10 | */ 11 | @Component 12 | public class ModifyEurekaAddBootstrapYamlAction extends AddBootstrapYamlAction { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/eureka/ModifyEurekaMainClassAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.eureka; 2 | 3 | import java.io.CharArrayWriter; 4 | import java.io.File; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.io.OutputStreamWriter; 8 | import java.nio.charset.StandardCharsets; 9 | import java.util.List; 10 | 11 | import org.apache.commons.io.FileUtils; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | import org.springframework.stereotype.Component; 15 | 16 | import com.huaweicse.tools.migrator.common.Const; 17 | import com.huaweicse.tools.migrator.common.FileAction; 18 | 19 | /** 20 | * 功能描述: 21 | * 扫描目录下面的所有JAVA文件,识别文件是否包含main函数,并将 @EnableEurekaServer 或者 @EnableEurekaClient 改为 @EnableDiscoveryClient。 22 | * 替换过程中,会替换 import,一并修改 import。 23 | */ 24 | @Component 25 | public class ModifyEurekaMainClassAction extends FileAction { 26 | 27 | private static final Logger LOGGER = LoggerFactory.getLogger(ModifyEurekaMainClassAction.class); 28 | 29 | private static final String ENABLE_EUREKA_SERVER = "@EnableEurekaClient"; 30 | 31 | private static final String ENABLE_EUREKA_CLIENT = "@EnableEurekaServer"; 32 | 33 | @Override 34 | public void run(String... args) throws Exception { 35 | List acceptedFiles = acceptedFiles(args[0]); 36 | replaceContent(acceptedFiles); 37 | } 38 | 39 | @Override 40 | protected boolean isAcceptedFile(File file) throws IOException { 41 | if (!file.getName().endsWith(".java")) { 42 | return false; 43 | } 44 | return fileContains(file, ENABLE_EUREKA_SERVER) || fileContains(file, ENABLE_EUREKA_CLIENT); 45 | } 46 | 47 | private void replaceContent(List acceptedFiles) { 48 | for (File file : acceptedFiles) { 49 | try { 50 | List lines = FileUtils.readLines(file, StandardCharsets.UTF_8); 51 | CharArrayWriter tempStream = new CharArrayWriter(); 52 | for (String line : lines) { 53 | if (line.startsWith("import")) { 54 | if (line.contains(Const.ENABLE_EUREKA_CLIENT_PACKAGE_NAME)) { 55 | line = line.replace(Const.ENABLE_EUREKA_CLIENT_PACKAGE_NAME, Const.ENABLE_DISCOVERY_CLIENT_PACKAGE_NAME); 56 | writeLine(tempStream, line); 57 | continue; 58 | } 59 | if (line.contains(Const.ENABLE_EUREKA_SERVER_PACKAGE_NAME)) { 60 | line = line.replace(Const.ENABLE_EUREKA_SERVER_PACKAGE_NAME, Const.ENABLE_DISCOVERY_CLIENT_PACKAGE_NAME); 61 | writeLine(tempStream, line); 62 | continue; 63 | } 64 | } 65 | if (line.trim().startsWith(ENABLE_EUREKA_SERVER) || line.trim().startsWith(ENABLE_EUREKA_CLIENT)) { 66 | writeLine(tempStream, "@EnableDiscoveryClient"); 67 | continue; 68 | } 69 | writeLine(tempStream, line); 70 | } 71 | OutputStreamWriter fileWriter = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); 72 | tempStream.writeTo(fileWriter); 73 | fileWriter.close(); 74 | } catch (Exception e) { 75 | LOGGER.error("Process file [{}] failed", file.getAbsolutePath(), e); 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/eureka/ModifyEurekaPomAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.eureka; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import com.huaweicse.tools.migrator.common.ModifyPomAction; 6 | 7 | /** 8 | * 功能描述: 9 | * 扫描目录下面的所有POM文件,删除Eureka相关的依赖、插件,增加Spring Cloud相关的依赖、插件。 10 | */ 11 | @Component 12 | public class ModifyEurekaPomAction extends ModifyPomAction { 13 | @Override 14 | public String getFrameType() { 15 | return "eureka"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/hsf/ModifyHSFAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.hsf; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Component; 5 | 6 | import com.huaweicse.tools.migrator.common.Action; 7 | 8 | @Component 9 | public class ModifyHSFAction implements Action { 10 | 11 | private ModifyHSFInterface2RestAction modifyHSFInterface2RestAction; 12 | 13 | private ModifyHSFProviderAction modifyHSFProviderAction; 14 | 15 | private ModifyHSFConsumerAction modifyHSFConsumerAction; 16 | 17 | private ModifyHSFAddBootstrapYamlAction modifyHSFAddBootstrapYamlAction; 18 | 19 | private ModifyHSFPomAction modifyHSFPomAction; 20 | 21 | private ModifyHSFMainClassAction modifyHSFMainClassAction; 22 | 23 | @Autowired 24 | public ModifyHSFAction(ModifyHSFInterface2RestAction modifyHSFInterface2RestAction, 25 | ModifyHSFProviderAction modifyHSFProviderAction, 26 | ModifyHSFConsumerAction modifyHSFConsumerAction, 27 | ModifyHSFAddBootstrapYamlAction modifyHSFAddBootstrapYamlAction, 28 | ModifyHSFPomAction modifyHSFPomAction, 29 | ModifyHSFMainClassAction modifyHSFMainClassAction) { 30 | this.modifyHSFInterface2RestAction = modifyHSFInterface2RestAction; 31 | this.modifyHSFProviderAction = modifyHSFProviderAction; 32 | this.modifyHSFConsumerAction = modifyHSFConsumerAction; 33 | this.modifyHSFAddBootstrapYamlAction = modifyHSFAddBootstrapYamlAction; 34 | this.modifyHSFPomAction = modifyHSFPomAction; 35 | this.modifyHSFMainClassAction = modifyHSFMainClassAction; 36 | } 37 | 38 | @Override 39 | public void run(String... args) throws Exception { 40 | Action[] actions = new Action[] {modifyHSFInterface2RestAction, modifyHSFProviderAction 41 | , modifyHSFConsumerAction, modifyHSFAddBootstrapYamlAction, modifyHSFPomAction, modifyHSFMainClassAction}; 42 | for (Action action : actions) { 43 | action.run(args); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/hsf/ModifyHSFAddBootstrapYamlAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.hsf; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import com.huaweicse.tools.migrator.common.AddBootstrapYamlAction; 6 | 7 | /** 8 | * 功能描述: 9 | * 在项目的 src/main/resources 目录下添加 bootstrap.yml 文件。 10 | */ 11 | @Component 12 | public class ModifyHSFAddBootstrapYamlAction extends AddBootstrapYamlAction { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/hsf/ModifyHSFConsumerAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.hsf; 2 | 3 | import java.io.CharArrayWriter; 4 | import java.io.File; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.io.OutputStreamWriter; 8 | import java.nio.charset.StandardCharsets; 9 | import java.util.List; 10 | 11 | import org.apache.commons.io.FileUtils; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | import org.springframework.stereotype.Component; 15 | 16 | import com.alibaba.fastjson.JSONObject; 17 | import com.huaweicse.tools.migrator.common.Const; 18 | import com.huaweicse.tools.migrator.common.FileAction; 19 | 20 | /** 21 | * 功能描述: 22 | * 扫描目录下面的所有JAVA文件,识别文件是否包含 @HSFConsumer 标签,如果存在,将其替换为 @FeignClient。 23 | * 替换过程中,会替换 import,一并修改 import。 24 | */ 25 | @Component 26 | public class ModifyHSFConsumerAction extends FileAction { 27 | 28 | private static final Logger LOGGER = LoggerFactory.getLogger(ModifyHSFConsumerAction.class); 29 | 30 | private static final String HSF_CONSUMER = "@HSFConsumer"; 31 | 32 | @Override 33 | protected boolean isAcceptedFile(File file) throws IOException { 34 | if (!file.getName().endsWith(".java")) { 35 | return false; 36 | } 37 | return fileContains(file, HSF_CONSUMER); 38 | } 39 | 40 | @Override 41 | public void run(String... args) throws Exception { 42 | List acceptedFiles = acceptedFiles(args[0]); 43 | replaceContent(acceptedFiles); 44 | } 45 | 46 | private void replaceContent(List acceptedFiles) { 47 | acceptedFiles.forEach(file -> { 48 | try { 49 | List lines = FileUtils.readLines(file, StandardCharsets.UTF_8); 50 | CharArrayWriter tempStream = new CharArrayWriter(); 51 | for (int i = 0; i < lines.size(); i++) { 52 | String line = lines.get(i); 53 | // 处理import中的包名 54 | line = line.replace(Const.HSF_CONSUMER_PACKAGE_NAME, Const.FEIGN_CLIENT_PACKAGE_NAME); 55 | // 处理@HSFConsumer注解信息及接口信息 56 | if (line.contains(HSF_CONSUMER)) { 57 | String nextLine = lines.get(i + 1); 58 | String[] interfaceLine = nextLine.trim().split(" "); 59 | if (interfaceLine.length < 3) { 60 | LOGGER.error(ERROR_MESSAGE, 61 | "Interface definition not valid under @HSFConsumer annotation.", 62 | file.getAbsolutePath(), i); 63 | 64 | writeLine(tempStream, line); 65 | } else { 66 | String interfaceName = interfaceLine[2].replace(";", ""); 67 | String feignClientInfo = feignClientInfo(line, interfaceName); 68 | if (feignClientInfo != null) { 69 | line = line.replace(line.trim(), feignClientInfo); 70 | nextLine = nextLine.replace(nextLine.trim(), interfaceExtension(nextLine)); 71 | writeLine(tempStream, line); 72 | writeLine(tempStream, nextLine); 73 | i++; 74 | } else { 75 | LOGGER.error(ERROR_MESSAGE, 76 | "Interface declaration missing serviceGroup and interfaceName.", 77 | file.getAbsolutePath(), i); 78 | writeLine(tempStream, line); 79 | } 80 | } 81 | continue; 82 | } 83 | writeLine(tempStream, line); 84 | } 85 | OutputStreamWriter fileWriter = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); 86 | tempStream.writeTo(fileWriter); 87 | fileWriter.close(); 88 | } catch (Exception e) { 89 | LOGGER.error("Process file [{}] failed", file.getAbsolutePath(), e); 90 | } 91 | }); 92 | } 93 | 94 | // FeignClient属性信息 95 | private String feignClientInfo(String line, String commonStr) { 96 | StringBuilder stringBuilder = new StringBuilder(); 97 | // 将目标字符串转化为JsonObject获取被调的微服务名称及进行属性信息拼接 98 | line = line.replace('=', ':'); 99 | String jsonString = "{" + line.substring(line.indexOf("(") + 1, line.lastIndexOf(")")) + "}"; 100 | Object serviceGroupValue = JSONObject.parseObject(jsonString).get("serviceGroup"); 101 | // 当开发者没有配置serviceGroup时,不抛出异常,保证后续内容正常修改,待内容修改全部完成后在error日志文件中查询相关不规范地方进行手动修改 102 | if (serviceGroupValue == null) { 103 | return null; 104 | } 105 | stringBuilder.append("@FeignClient(name = \"") 106 | .append(serviceGroupValue) 107 | .append("\"") 108 | .append(", contextId = \"") 109 | .append(commonStr) 110 | .append("\", ") 111 | .append("path = \"/") 112 | .append(commonStr) 113 | .append("\")"); 114 | return new String(stringBuilder); 115 | } 116 | 117 | // 接口拓展信息 118 | private String interfaceExtension(String line) { 119 | StringBuilder stringBuilder = new StringBuilder(); 120 | String[] s = line.trim().split(" "); 121 | stringBuilder.append("public interface ") 122 | .append(s[1]) 123 | .append("Ext extends ") 124 | .append(s[1]) 125 | .append("{}"); 126 | return new String(stringBuilder); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/hsf/ModifyHSFInterface2RestAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.hsf; 2 | 3 | import java.io.CharArrayWriter; 4 | import java.io.File; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.io.OutputStreamWriter; 8 | import java.nio.charset.StandardCharsets; 9 | import java.util.ArrayList; 10 | import java.util.Arrays; 11 | import java.util.List; 12 | import java.util.regex.Matcher; 13 | import java.util.regex.Pattern; 14 | import java.util.stream.Collectors; 15 | 16 | import org.apache.commons.io.FileUtils; 17 | import org.slf4j.Logger; 18 | import org.slf4j.LoggerFactory; 19 | import org.springframework.stereotype.Component; 20 | 21 | import com.huaweicse.tools.migrator.common.Const; 22 | import com.huaweicse.tools.migrator.common.FileAction; 23 | import com.huaweicse.tools.migrator.common.ParamValueType; 24 | 25 | /** 26 | * 功能描述: 27 | * 扫描目录下面的所有JAVA文件,首先扫描出包含 @HSFProvider 标签的文件,并从中解析出需要处理的 JAVA interface文件, 28 | * 然后将 interface 文件修改为 REST 风格。 替换过程中,会替换 import,一并修改 import。 29 | */ 30 | @Component 31 | public class ModifyHSFInterface2RestAction extends FileAction { 32 | 33 | private static final Logger LOGGER = LoggerFactory.getLogger(ModifyHSFInterface2RestAction.class); 34 | 35 | private static final String INTERFACE_REGEX_PATTERN = "[a-zA-Z]+(.class)"; 36 | 37 | private static final String ROUTER_REGEX_PATTERN = "[/*{}]"; 38 | 39 | private static final String HSF_PROVIDER = "@HSFProvider"; 40 | 41 | @Override 42 | public void run(String... args) throws Exception { 43 | List acceptedFiles = acceptedFiles(args[0]); 44 | List interfaceFileList = filterInterfaceFile(acceptedFiles); 45 | replaceContent(acceptedFiles, interfaceFileList); 46 | } 47 | 48 | @Override 49 | protected boolean isAcceptedFile(File file) { 50 | return file.getName().endsWith(".java"); 51 | } 52 | 53 | private List filterInterfaceFile(List acceptedFiles) throws IOException { 54 | List interfaceFileList = new ArrayList<>(); 55 | for (File file : acceptedFiles) { 56 | List lines = FileUtils.readLines(file, StandardCharsets.UTF_8); 57 | for (String line : lines) { 58 | if (line.contains(HSF_PROVIDER)) { 59 | Pattern pattern = Pattern.compile(INTERFACE_REGEX_PATTERN); 60 | Matcher matcher = pattern.matcher(line); 61 | while (matcher.find()) { 62 | interfaceFileList.add(matcher.group().replace(".class", ".java")); 63 | } 64 | break; 65 | } 66 | } 67 | } 68 | return interfaceFileList; 69 | } 70 | 71 | private void replaceContent(List acceptedFiles, List interfaceFileList) { 72 | acceptedFiles.forEach(file -> { 73 | try { 74 | if (interfaceFileList.size() == 0) { 75 | return; 76 | } 77 | CharArrayWriter tempStream = new CharArrayWriter(); 78 | String tempInterfaceFileName = null; 79 | for (String interfaceFileName : interfaceFileList) { 80 | if (interfaceFileName.equals(file.getName())) { 81 | List lines = FileUtils.readLines(file, StandardCharsets.UTF_8); 82 | for (String line : lines) { 83 | if (line.contains("package")) { 84 | writeLine(tempStream, line); 85 | writeLine(tempStream, ""); 86 | writeLine(tempStream, "import " + Const.RESPONSE_BODY_PACKAGE_NAME + ";"); 87 | writeLine(tempStream, "import " + Const.POST_MAPPING_PACKAGE_NAME + ";"); 88 | writeLine(tempStream, "import " + Const.REQUEST_PARAM_PACKAGE_NAME + ";"); 89 | writeLine(tempStream, "import " + Const.REQUEST_BODY_PACKAGE_NAME + ";"); 90 | continue; 91 | } 92 | if (!("".equals(line) || isEffectiveInterface(line))) { 93 | String[] strings = line.trim().replace("(", " ").split(" "); 94 | writeLine(tempStream, " @ResponseBody"); 95 | ArrayList paramList = paramHandling(line, file); 96 | if (paramList == null) { 97 | writeLine(tempStream, postMappingString(strings[0], strings[1], "0")); 98 | writeLine(tempStream, line); 99 | } else { 100 | writeLine(tempStream, postMappingString(strings[0], strings[1], paramList.get(paramList.size() - 1))); 101 | writeLine(tempStream, interfaceInfo(line, paramList)); 102 | } 103 | continue; 104 | } 105 | writeLine(tempStream, line); 106 | } 107 | tempInterfaceFileName = interfaceFileName; 108 | OutputStreamWriter fileWriter = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); 109 | tempStream.writeTo(fileWriter); 110 | fileWriter.close(); 111 | } 112 | } 113 | interfaceFileList.remove(tempInterfaceFileName); 114 | } catch (IOException e) { 115 | LOGGER.error("error modifying content and filePath is {}", file.getAbsolutePath()); 116 | } 117 | }); 118 | } 119 | 120 | private static ArrayList paramHandling(String line, File file) { 121 | String[] tempParams = line.substring(line.indexOf("(") + 1, line.lastIndexOf(")")) 122 | .replaceAll(",", " ").split(" "); 123 | if (tempParams.length == 1) { 124 | return null; 125 | } 126 | int requestBodyCount = 0; 127 | List paramStrings = Arrays.stream(tempParams) 128 | .filter(param -> !"".equals(param)) 129 | .collect(Collectors.toList()); 130 | ArrayList params = new ArrayList<>(paramStrings.size()); 131 | for (int i = 0; i < paramStrings.size(); i++) { 132 | String tempParam = paramStrings.get(i); 133 | if (i % 2 == 0) { 134 | if (isComplexType(tempParam)) { 135 | params.add("@RequestBody " + tempParam); 136 | requestBodyCount++; 137 | if (requestBodyCount >= 2) { 138 | String methodName = line.trim().substring(line.trim().indexOf(" ") + 1, line.trim().indexOf("(")); 139 | LOGGER.error("RequestBody too much, need to reconstruct parameters and method name is {} of {}", 140 | methodName, file.getName()); 141 | } 142 | } else { 143 | params.add("@RequestParam(value=\"" + paramStrings.get(i + 1) + "\") " + tempParam); 144 | } 145 | continue; 146 | } 147 | params.add(tempParam); 148 | } 149 | params.add(String.valueOf(requestBodyCount)); 150 | return params; 151 | } 152 | 153 | private static boolean isComplexType(String param) { 154 | ParamValueType[] values = ParamValueType.values(); 155 | for (ParamValueType value : values) { 156 | if (param.equalsIgnoreCase(value.name()) || "int".equals(value.name()) || "char".equals(value.name())) { 157 | return false; 158 | } 159 | } 160 | return true; 161 | } 162 | 163 | private String postMappingString(String resultTypeValue, String router, String bodyCount) { 164 | StringBuilder stringBuilder = new StringBuilder(); 165 | stringBuilder.append(" @PostMapping(value = \"/") 166 | .append(router) 167 | .append("\""); 168 | if (isComplexType(resultTypeValue)) { 169 | stringBuilder.append(", produces = \"x-application/hessian2\""); 170 | } 171 | if (Integer.parseInt(bodyCount) >= 1) { 172 | stringBuilder.append(", consumes = \"x-application/hessian2\""); 173 | } 174 | stringBuilder.append(")"); 175 | return new String(stringBuilder); 176 | } 177 | 178 | private String interfaceInfo(String line, ArrayList paramList) { 179 | String substring = line.substring(0, line.indexOf("(")); 180 | if (Integer.parseInt(paramList.get(paramList.size() - 1)) > 1) { 181 | return line; 182 | } 183 | paramList.remove(paramList.get(paramList.size() - 1)); 184 | StringBuilder stringBuilder = new StringBuilder(); 185 | stringBuilder.append(substring) 186 | .append("("); 187 | for (int i = 0; i < paramList.size(); i++) { 188 | if (i % 2 == 0) { 189 | stringBuilder.append(paramList.get(i)).append(" "); 190 | continue; 191 | } 192 | if (i == (paramList.size() - 1)) { 193 | stringBuilder.append(paramList.get(i)); 194 | continue; 195 | } 196 | stringBuilder.append(paramList.get(i)).append(", "); 197 | } 198 | stringBuilder.append(");"); 199 | return new String(stringBuilder); 200 | } 201 | 202 | private boolean isEffectiveInterface(String line) { 203 | Pattern pattern = Pattern.compile(ROUTER_REGEX_PATTERN); 204 | Matcher matcher = pattern.matcher(line); 205 | return matcher.find(); 206 | } 207 | } 208 | 209 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/hsf/ModifyHSFMainClassAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.hsf; 2 | 3 | import java.io.CharArrayWriter; 4 | import java.io.File; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.io.OutputStreamWriter; 8 | import java.nio.charset.StandardCharsets; 9 | import java.util.List; 10 | 11 | import org.apache.commons.io.FileUtils; 12 | import org.springframework.stereotype.Component; 13 | 14 | import com.huaweicse.tools.migrator.common.Const; 15 | import com.huaweicse.tools.migrator.common.FileAction; 16 | 17 | /** 18 | * 功能描述: 19 | * 扫描目录下面的所有JAVA文件,识别文件是否包含main函数,并将相关 pandora 逻辑改为 Spring Boot。 20 | * 替换过程中,会替换 import,一并修改 import。 21 | */ 22 | @Component 23 | public class ModifyHSFMainClassAction extends FileAction { 24 | @Override 25 | public void run(String... args) throws Exception { 26 | List acceptedFiles = acceptedFiles(args[0]); 27 | replaceContent(acceptedFiles); 28 | } 29 | 30 | private void replaceContent(List acceptedFiles) throws Exception { 31 | for (File file : acceptedFiles) { 32 | List lines = FileUtils.readLines(file, StandardCharsets.UTF_8); 33 | CharArrayWriter tempStream = new CharArrayWriter(); 34 | 35 | boolean importBegin = false; 36 | boolean classAnnotationBegin = false; 37 | boolean mainBegin = false; 38 | 39 | for (String line : lines) { 40 | // import section 41 | if (line.startsWith("import")) { 42 | if (!importBegin) { 43 | writeLine(tempStream, String.format("%s%s%s", "import ", Const.ENABLE_DISCOVERY_CLIENT_PACKAGE_NAME, ";")); 44 | writeLine(tempStream, String.format("%s%s%s", "import ", Const.ENABLE_FEIGN_CLIENTS_PACKAGE_NAME, ";")); 45 | importBegin = true; 46 | } 47 | 48 | if (line.contains(Const.PANDORA_BOOT_STRAP_PACKAGE_NAME) || 49 | line.contains(Const.ENABLE_DISCOVERY_CLIENT_PACKAGE_NAME) || 50 | line.contains(Const.ENABLE_FEIGN_CLIENTS_PACKAGE_NAME)) { 51 | continue; 52 | } 53 | 54 | writeLine(tempStream, line); 55 | continue; 56 | } 57 | 58 | // class annotation section 59 | if (line.startsWith("@")) { 60 | if (!classAnnotationBegin) { 61 | writeLine(tempStream, "@EnableDiscoveryClient"); 62 | writeLine(tempStream, "@EnableFeignClients"); 63 | classAnnotationBegin = true; 64 | } 65 | 66 | if (line.contains("EnableDiscoveryClient") || line.contains("EnableFeignClients")) { 67 | continue; 68 | } 69 | 70 | writeLine(tempStream, line); 71 | continue; 72 | } 73 | 74 | // main section 75 | if (line.contains("static void main")) { 76 | mainBegin = true; 77 | } 78 | 79 | if (mainBegin) { 80 | if (line.contains("PandoraBootstrap")) { 81 | continue; 82 | } 83 | } 84 | 85 | // other 86 | writeLine(tempStream, line); 87 | } 88 | 89 | OutputStreamWriter fileWriter = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); 90 | tempStream.writeTo(fileWriter); 91 | fileWriter.close(); 92 | } 93 | } 94 | 95 | @Override 96 | protected boolean isAcceptedFile(File file) throws IOException { 97 | if (!file.getName().endsWith(".java")) { 98 | return false; 99 | } 100 | return fileContains(file, "static void main"); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/hsf/ModifyHSFPomAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.hsf; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import com.huaweicse.tools.migrator.common.ModifyPomAction; 6 | 7 | /** 8 | * 功能描述: 9 | * 扫描目录下面的所有POM文件,删除HSF相关的依赖、插件,增加Spring Cloud相关的依赖、插件。 10 | */ 11 | @Component 12 | public class ModifyHSFPomAction extends ModifyPomAction { 13 | 14 | @Override 15 | public String getFrameType() { 16 | return "hsf"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/hsf/ModifyHSFProviderAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.hsf; 2 | 3 | import java.io.CharArrayWriter; 4 | import java.io.File; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.io.OutputStreamWriter; 8 | import java.nio.charset.StandardCharsets; 9 | import java.util.List; 10 | import java.util.regex.Matcher; 11 | import java.util.regex.Pattern; 12 | 13 | import org.apache.commons.io.FileUtils; 14 | import org.slf4j.Logger; 15 | import org.slf4j.LoggerFactory; 16 | import org.springframework.stereotype.Component; 17 | 18 | import com.huaweicse.tools.migrator.common.Const; 19 | import com.huaweicse.tools.migrator.common.FileAction; 20 | 21 | /** 22 | * 功能描述: 23 | * 扫描目录下面的所有JAVA文件,识别文件是否包含 @HSFProvider 标签,如果存在,将其替换为 @RestController。 24 | * 替换过程中,会替换 import,一并修改 import。 25 | */ 26 | @Component 27 | public class ModifyHSFProviderAction extends FileAction { 28 | 29 | private static final Logger LOGGER = LoggerFactory.getLogger(ModifyHSFProviderAction.class); 30 | 31 | private static final String INTERFACE_REGEX_PATTERN = "[a-zA-Z]+(.class)"; 32 | 33 | private static final String HSF_PROVIDER = "@HSFProvider"; 34 | 35 | @Override 36 | public void run(String... args) throws Exception { 37 | List acceptedFiles = acceptedFiles(args[0]); 38 | replaceContent(acceptedFiles); 39 | } 40 | 41 | @Override 42 | protected boolean isAcceptedFile(File file) throws IOException { 43 | if (!file.getName().endsWith(".java")) { 44 | return false; 45 | } 46 | return fileContains(file, HSF_PROVIDER); 47 | } 48 | 49 | private void replaceContent(List acceptedFiles) throws IOException { 50 | for (File file : acceptedFiles) { 51 | List lines = FileUtils.readLines(file, StandardCharsets.UTF_8); 52 | CharArrayWriter tempStream = new CharArrayWriter(); 53 | for (int i = 0; i < lines.size(); i++) { 54 | String line = lines.get(i); 55 | if (line.contains(Const.HSF_PROVIDER_PACKAGE_NAME)) { 56 | line = line.replace(Const.HSF_PROVIDER_PACKAGE_NAME, Const.REQUEST_MAPPING_PACKAGE_NAME); 57 | writeLine(tempStream, line); 58 | writeLine(tempStream, "import " + Const.REST_CONTROLLER_PACKAGE_NAME + ";"); 59 | continue; 60 | } 61 | if (line.trim().startsWith(HSF_PROVIDER)) { 62 | Pattern pattern = Pattern.compile(INTERFACE_REGEX_PATTERN); 63 | Matcher matcher = pattern.matcher(line); 64 | String tempRouter = null; 65 | while (matcher.find()) { 66 | tempRouter = matcher.group().replace(".class", ""); 67 | } 68 | if (tempRouter == null) { 69 | LOGGER.error(ERROR_MESSAGE, "@HSFProvicer not hava interface property.", 70 | file.getAbsolutePath(), 71 | i); 72 | continue; 73 | } 74 | writeLine(tempStream, "@RestController"); 75 | writeLine(tempStream, 76 | "@RequestMapping(\"/" + tempRouter.substring(0, 1).toLowerCase() + tempRouter.substring(1) + "\")"); 77 | continue; 78 | } 79 | writeLine(tempStream, line); 80 | } 81 | OutputStreamWriter fileWriter = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); 82 | tempStream.writeTo(fileWriter); 83 | fileWriter.close(); 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/nacos/ModifyNacosAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.nacos; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Component; 5 | 6 | import com.huaweicse.tools.migrator.common.Action; 7 | 8 | @Component 9 | public class ModifyNacosAction implements Action { 10 | 11 | private ModifyNacosAddBootstrapYamlAction modifyNacosAddBootstrapYamlAction; 12 | 13 | private ModifyNacosPomAction modifyNacosPomAction; 14 | 15 | @Autowired 16 | public ModifyNacosAction( 17 | ModifyNacosAddBootstrapYamlAction modifyNacosAddBootstrapYamlAction, 18 | ModifyNacosPomAction modifyNacosPomAction) { 19 | this.modifyNacosAddBootstrapYamlAction = modifyNacosAddBootstrapYamlAction; 20 | this.modifyNacosPomAction = modifyNacosPomAction; 21 | } 22 | 23 | @Override 24 | public void run(String... args) throws Exception { 25 | Action[] actions = new Action[] {modifyNacosAddBootstrapYamlAction, modifyNacosPomAction}; 26 | for (Action action : actions) { 27 | action.run(args); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/nacos/ModifyNacosAddBootstrapYamlAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.nacos; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import com.huaweicse.tools.migrator.common.AddBootstrapYamlAction; 6 | 7 | /** 8 | * 功能描述: 9 | * 在项目的 src/main/resources 目录下添加 bootstrap.yml 文件。 10 | */ 11 | @Component 12 | public class ModifyNacosAddBootstrapYamlAction extends AddBootstrapYamlAction { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/huaweicse/tools/migrator/nacos/ModifyNacosPomAction.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.nacos; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import com.huaweicse.tools.migrator.common.ModifyPomAction; 6 | 7 | /** 8 | * 功能描述: 9 | * 扫描目录下面的所有POM文件,删除Eureka相关的依赖、插件,增加Spring Cloud相关的依赖、插件。 10 | */ 11 | @Component 12 | public class ModifyNacosPomAction extends ModifyPomAction { 13 | @Override 14 | public String getFrameType() { 15 | return "nacos"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # spring相关注解 2 | # spring.responseBody.packageName=org.springframework.web.bind.annotation.ResponseBody 3 | # spring.postMapping.packageName=org.springframework.web.bind.annotation.PostMapping 4 | # spring.requestBody.packageName=org.springframework.web.bind.annotation.RequestBody 5 | # spring.requestParam.packageName=org.springframework.web.bind.annotation.RequestParam 6 | # spring.requestMapping.packageName=org.springframework.web.bind.annotation.RequestMapping; 7 | # spring.restController.packageName=org.springframework.web.bind.annotation.RestController; 8 | # spring.feignClient.packageName=org.springframework.cloud.openfeign.FeignClient 9 | # spring.enableDiscoveryClient.packageName=org.springframework.cloud.client.discovery.EnableDiscoveryClient 10 | # spring.enableFeignClients.packageName=org.springframework.cloud.openfeign.EnableFeignClients 11 | # spring.autowired.packageName=org.springframework.beans.factory.annotation.Autowired 12 | # spring.configuration.packageName=org.springframework.context.annotation.Configuration 13 | # spring.propertySource.packageName=org.springframework.context.annotation.PropertySource 14 | # spring.importResource.packageName=org.springframework.context.annotation.ImportResource 15 | # spring.enableEurekaClient.packageName=org.springframework.cloud.netflix.eureka.EnableEurekaClient 16 | # spring.enableEurekaServer.packageName=org.springframework.cloud.netflix.eureka.server.EnableEurekaServer 17 | 18 | # hsf框架下相关注解包名配置,不配置则使用默认值 19 | # hsf.consumer.packageName=com.alibaba.boot.hsf.annotation.HSFConsumer 20 | # hsf.provider.packageName=com.alibaba.boot.hsf.annotation.HSFProvider 21 | # hsf.pandoraBootstrap.packageName=com.taobao.pandora.boot.PandoraBootstrap 22 | 23 | # dubbo框架下相关注解包名配置,不配置则使用默认值 24 | # dubbo.provider.packageName=org.apache.dubbo.config.annotation.DubboService 25 | # dubbo.enableDubbo.packageName=org.apache.dubbo.config.spring.context.annotation.EnableDubbo 26 | # dubbo.dubboReference.packageName=org.apache.dubbo.config.annotation.DubboReference 27 | -------------------------------------------------------------------------------- /src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ${LOG_HOME}/migrate-error-%d{yyyy-MM-dd}.log 9 | 30 10 | 11 | 12 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 13 | UTF-8 14 | 15 | 16 | 10MB 17 | 18 | 19 | error 20 | ACCEPT 21 | DENY 22 | 23 | 24 | 25 | 26 | 27 | %d [%level] [%thread] - %msg (%F:%L\)%n 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/test/java/com/huaweicse/tools/migrator/Utils.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator; 2 | 3 | import java.io.File; 4 | import java.io.FileReader; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.apache.commons.io.IOUtils; 9 | 10 | public class Utils { 11 | public static void assertFileContentEquals(String file1, String file2) throws Exception { 12 | try (FileReader fis1 = new FileReader(file1)) { 13 | try (FileReader fis2 = new FileReader(file2)) { 14 | if (!IOUtils.contentEqualsIgnoreEOL(fis1, fis2)) { 15 | throw new AssertionError(String.format("file %s and %s not equal", file1, file2)); 16 | } 17 | } 18 | } 19 | } 20 | 21 | public static void assertFolderAllFileContentEquals(String inputFileDir, String outFileDir) throws Exception { 22 | ArrayList list = new ArrayList<>(); 23 | List inputFiles = allFiles(list, inputFileDir); 24 | List outputFiles = allFiles(list, outFileDir); 25 | for (int i = 0; i < inputFiles.size(); i++) { 26 | try (FileReader fis1 = new FileReader(inputFiles.get(i))) { 27 | try (FileReader fis2 = new FileReader(outputFiles.get(i))) { 28 | if (!IOUtils.contentEqualsIgnoreEOL(fis1, fis2)) { 29 | throw new AssertionError(String.format("file %s and %s not equal", outFileDir, outFileDir)); 30 | } 31 | } 32 | } 33 | } 34 | } 35 | 36 | private static List allFiles(List fileList, String fileDir) { 37 | File[] files = new File(fileDir).listFiles(); 38 | for (File file : files) { 39 | if (file.isDirectory()) { 40 | allFiles(fileList, file.getAbsolutePath()); 41 | continue; 42 | } 43 | fileList.add(file); 44 | } 45 | return fileList; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/com/huaweicse/tools/migrator/dubbo/ModifyDubboAddBootstrapYamlActionTest.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.dubbo; 2 | 3 | import java.io.File; 4 | import java.util.Random; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.junit.jupiter.api.AfterEach; 8 | import org.junit.jupiter.api.BeforeEach; 9 | import org.junit.jupiter.api.Test; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | 13 | import com.huaweicse.tools.migrator.Utils; 14 | 15 | @SpringBootTest 16 | public class ModifyDubboAddBootstrapYamlActionTest { 17 | 18 | private static final String BASE_PATH = System.getProperty("user.dir"); 19 | 20 | private String TEMP_DIR_PATH; 21 | 22 | private String fileSeparator = File.separator; 23 | 24 | @Autowired 25 | private ModifyDubboAddBootstrapYamlAction modifyDubboAddBootstrapYamlAction; 26 | 27 | @BeforeEach 28 | public void setUp() throws Exception { 29 | TEMP_DIR_PATH = System.getProperty("java.io.tmpdir") 30 | + File.separator + Math.abs(new Random().nextInt()); 31 | 32 | FileUtils.copyDirectoryToDirectory( 33 | new File(BASE_PATH + fileSeparator + "testfiles" + fileSeparator + "ModifyDubboAddBootstrapYamlActionTest"), 34 | new File(TEMP_DIR_PATH)); 35 | } 36 | 37 | @AfterEach 38 | public void tearDown() throws Exception { 39 | FileUtils.deleteDirectory(new File(TEMP_DIR_PATH)); 40 | } 41 | 42 | @Test 43 | public void testAddBootstrapFile() throws Exception { 44 | modifyDubboAddBootstrapYamlAction.run(TEMP_DIR_PATH + fileSeparator + "ModifyDubboAddBootstrapYamlActionTest"); 45 | String originBootstrapContextPath = BASE_PATH + fileSeparator + "templates" + fileSeparator + "bootstrap.yml"; 46 | String newBootstrapFilePath = 47 | TEMP_DIR_PATH + fileSeparator + "ModifyDubboAddBootstrapYamlActionTest" + fileSeparator + 48 | "src" + fileSeparator + "main" + fileSeparator + "resources" + fileSeparator + "bootstrap.yml"; 49 | Utils.assertFileContentEquals(originBootstrapContextPath, newBootstrapFilePath); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/huaweicse/tools/migrator/dubbo/ModifyDubboInterface2RestActionTest.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.dubbo; 2 | 3 | import java.io.File; 4 | import java.util.Random; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.junit.jupiter.api.AfterEach; 8 | import org.junit.jupiter.api.BeforeEach; 9 | import org.junit.jupiter.api.Test; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | 13 | import com.huaweicse.tools.migrator.Utils; 14 | 15 | @SpringBootTest 16 | public class ModifyDubboInterface2RestActionTest { 17 | 18 | private static final String BASE_PATH = System.getProperty("user.dir"); 19 | 20 | private String TEMP_DIR_PATH; 21 | 22 | private String fileSeparator = File.separator; 23 | 24 | @Autowired 25 | private ModifyDubboInterface2RestAction modifyDubboInterface2RestAction; 26 | 27 | @BeforeEach 28 | public void setUp() throws Exception { 29 | TEMP_DIR_PATH = System.getProperty("java.io.tmpdir") + fileSeparator + Math.abs(new Random().nextInt()); 30 | FileUtils.copyDirectoryToDirectory(new File(BASE_PATH + fileSeparator 31 | + "testfiles" + fileSeparator + "ModifyDubboInterface2RestActionTest" + fileSeparator + "input"), 32 | new File(TEMP_DIR_PATH)); 33 | } 34 | 35 | @AfterEach 36 | public void tearDown() throws Exception { 37 | FileUtils.deleteDirectory(new File(TEMP_DIR_PATH)); 38 | } 39 | 40 | 41 | @Test 42 | public void testModifyDubboInterface2RestActionTest() throws Exception { 43 | modifyDubboInterface2RestAction.run(TEMP_DIR_PATH); 44 | String fileName = "HelloService.java"; 45 | Utils.assertFileContentEquals( 46 | BASE_PATH + fileSeparator 47 | + "testfiles" + fileSeparator + "ModifyDubboInterface2RestActionTest" + fileSeparator 48 | + "output" + fileSeparator + fileName, 49 | TEMP_DIR_PATH + fileSeparator + "input" + fileSeparator + fileName); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/huaweicse/tools/migrator/dubbo/ModifyDubboMainClassActionTest.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.dubbo; 2 | 3 | import java.io.File; 4 | import java.util.Random; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.junit.jupiter.api.AfterEach; 8 | import org.junit.jupiter.api.BeforeEach; 9 | import org.junit.jupiter.api.Test; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | 13 | import com.huaweicse.tools.migrator.Utils; 14 | 15 | @SpringBootTest 16 | public class ModifyDubboMainClassActionTest { 17 | private static final String BASE_PATH = System.getProperty("user.dir"); 18 | 19 | private String TEMP_DIR_PATH; 20 | 21 | private String fileSeparator = File.separator; 22 | 23 | @Autowired 24 | private ModifyDubboMainClassAction modifyDubboMainClassAction; 25 | 26 | @BeforeEach 27 | public void setUp() throws Exception { 28 | TEMP_DIR_PATH = System.getProperty("java.io.tmpdir") 29 | + File.separator + Math.abs(new Random().nextInt()); 30 | 31 | FileUtils.copyDirectoryToDirectory( 32 | new File(BASE_PATH + fileSeparator + "testfiles" + fileSeparator + "ModifyDubboMainClassActionTest" 33 | + fileSeparator + "input"), 34 | new File(TEMP_DIR_PATH)); 35 | } 36 | 37 | @AfterEach 38 | public void tearDown() throws Exception { 39 | FileUtils.deleteDirectory(new File(TEMP_DIR_PATH)); 40 | } 41 | 42 | @Test 43 | public void testProcessMainClass() throws Exception { 44 | modifyDubboMainClassAction.run(TEMP_DIR_PATH); 45 | String fileName = "DubboConsumerApplication.java"; 46 | String outputFilePath = 47 | BASE_PATH + fileSeparator + "testfiles" + fileSeparator + "ModifyDubboMainClassActionTest" + fileSeparator + 48 | "output" + fileSeparator + fileName; 49 | Utils.assertFileContentEquals(inputTestFilePath("dubbo-annotation", fileName), outputFilePath); 50 | Utils.assertFileContentEquals(inputTestFilePath("dubbo-springboot", fileName), outputFilePath); 51 | Utils.assertFileContentEquals(inputTestFilePath("dubbo-xml", fileName), outputFilePath); 52 | } 53 | 54 | private String inputTestFilePath(String styleType, String fileName) { 55 | return TEMP_DIR_PATH + fileSeparator + "input" + fileSeparator + styleType + fileSeparator + fileName; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/huaweicse/tools/migrator/dubbo/ModifyDubboReferenceActionTest.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.dubbo; 2 | 3 | import java.io.File; 4 | import java.util.Random; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.junit.jupiter.api.AfterAll; 8 | import org.junit.jupiter.api.BeforeAll; 9 | import org.junit.jupiter.api.Test; 10 | import org.junit.jupiter.api.TestInstance; 11 | import org.junit.jupiter.api.TestInstance.Lifecycle; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.boot.test.context.SpringBootTest; 14 | 15 | import com.huaweicse.tools.migrator.Utils; 16 | 17 | @SpringBootTest 18 | @TestInstance(Lifecycle.PER_CLASS) 19 | public class ModifyDubboReferenceActionTest { 20 | 21 | private static final String BASE_PATH = System.getProperty("user.dir"); 22 | 23 | private String TEMP_DIR_PATH; 24 | 25 | private String fileSeparator = File.separator; 26 | 27 | @Autowired 28 | private ModifyDubboReferenceAction modifyDubboReferenceAction; 29 | 30 | @BeforeAll 31 | public void setUp() throws Exception { 32 | TEMP_DIR_PATH = System.getProperty("java.io.tmpdir") + fileSeparator + Math.abs(new Random().nextInt()); 33 | FileUtils.copyDirectoryToDirectory(new File(BASE_PATH + fileSeparator 34 | + "testfiles" + fileSeparator + "ModifyDubboReferenceActionTest" + fileSeparator + "input"), 35 | new File(TEMP_DIR_PATH)); 36 | } 37 | 38 | @AfterAll 39 | public void tearDown() throws Exception { 40 | FileUtils.deleteDirectory(new File(TEMP_DIR_PATH)); 41 | } 42 | 43 | @Test 44 | public void testModifyDubboReferenceActionTest_Springboot() throws Exception { 45 | modifyDubboReferenceAction.run(TEMP_DIR_PATH + fileSeparator + "input" + fileSeparator + "dubbo-springboot"); 46 | String consumerControllerFileName = "DubboSpringBootConsumerController.java"; 47 | String interfaceConfigFileName = "DubboInterfaceConfig.java"; 48 | Utils.assertFileContentEquals(outputTestFilePath("dubbo-springboot", consumerControllerFileName), 49 | modifiedTestFilePath("dubbo-springboot", "consumer") + "test" + fileSeparator + consumerControllerFileName); 50 | Utils.assertFileContentEquals(outputTestFilePath("dubbo-springboot", interfaceConfigFileName), 51 | modifiedTestFilePath("dubbo-springboot", "consumer") + "config" + fileSeparator + interfaceConfigFileName); 52 | } 53 | 54 | @Test 55 | public void testModifyDubboReferenceActionTest_Annotation() throws Exception { 56 | modifyDubboReferenceAction.run(TEMP_DIR_PATH + fileSeparator + "input" + fileSeparator + "dubbo-annotation"); 57 | String consumerControllerFileName = "DubboAnnotationConsumerController.java"; 58 | String interfaceConfigFileName = "DubboInterfaceConfig.java"; 59 | Utils.assertFileContentEquals(outputTestFilePath("dubbo-annotation", consumerControllerFileName), 60 | modifiedTestFilePath("dubbo-annotation", "consumer") + "test" + fileSeparator + consumerControllerFileName); 61 | Utils.assertFileContentEquals(outputTestFilePath("dubbo-annotation", interfaceConfigFileName), 62 | modifiedTestFilePath("dubbo-annotation", "consumer") + "config" + fileSeparator + interfaceConfigFileName); 63 | } 64 | 65 | @Test 66 | public void testModifyDubboReferenceActionTest_Xml() throws Exception { 67 | modifyDubboReferenceAction.run(TEMP_DIR_PATH + fileSeparator + "input" + fileSeparator + "dubbo-xml"); 68 | String interfaceImplFileName = "HelloXmlServiceImpl.java"; 69 | String interfaceConfigFileName = "DubboInterfaceConfig.java"; 70 | Utils.assertFileContentEquals(outputTestFilePath("dubbo-xml", interfaceImplFileName), 71 | modifiedTestFilePath("dubbo-xml", "provider") + "test" + fileSeparator + interfaceImplFileName); 72 | Utils.assertFileContentEquals(outputTestFilePath("dubbo-xml", interfaceConfigFileName), 73 | modifiedTestFilePath("dubbo-xml", "consumer") + "config" + fileSeparator + interfaceConfigFileName); 74 | } 75 | 76 | private String outputTestFilePath(String styleName, String fileName) { 77 | return BASE_PATH + fileSeparator + "testfiles" + fileSeparator + "ModifyDubboReferenceActionTest" + 78 | fileSeparator + "output" + fileSeparator + styleName + fileSeparator + fileName; 79 | } 80 | 81 | private String modifiedTestFilePath(String styleName, String roleName) { 82 | return TEMP_DIR_PATH + fileSeparator + "input" + fileSeparator + styleName + fileSeparator + roleName 83 | + fileSeparator + "src" + fileSeparator + "main" + fileSeparator + "java" + fileSeparator + 84 | "com" + fileSeparator + "huaweicse" + fileSeparator; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/test/java/com/huaweicse/tools/migrator/dubbo/ModifyDubboServiceActionTest.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.dubbo; 2 | 3 | import java.io.File; 4 | import java.util.Random; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.junit.jupiter.api.AfterEach; 8 | import org.junit.jupiter.api.BeforeEach; 9 | import org.junit.jupiter.api.Test; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | 13 | import com.huaweicse.tools.migrator.Utils; 14 | 15 | @SpringBootTest 16 | public class ModifyDubboServiceActionTest { 17 | 18 | private static final String BASE_PATH = System.getProperty("user.dir"); 19 | 20 | private String TEMP_DIR_PATH; 21 | 22 | private String fileSeparator = File.separator; 23 | 24 | @Autowired 25 | private ModifyDubboServiceAction modifyDubboServiceAction; 26 | 27 | @BeforeEach 28 | public void setUp() throws Exception { 29 | TEMP_DIR_PATH = System.getProperty("java.io.tmpdir") 30 | + File.separator + Math.abs(new Random().nextInt()); 31 | 32 | FileUtils.copyDirectoryToDirectory(new File(BASE_PATH + fileSeparator 33 | + "testfiles" + fileSeparator + "ModifyDubboServiceActionTest" + fileSeparator + "input"), 34 | new File(TEMP_DIR_PATH)); 35 | } 36 | 37 | @AfterEach 38 | public void tearDown() throws Exception { 39 | FileUtils.deleteDirectory(new File(TEMP_DIR_PATH)); 40 | } 41 | 42 | 43 | @Test 44 | public void testModifyDubboServiceActionTest() throws Exception { 45 | modifyDubboServiceAction.run(TEMP_DIR_PATH + fileSeparator + "input"); 46 | 47 | String fileName = "HelloServiceImpl.java"; 48 | Utils.assertFileContentEquals( 49 | BASE_PATH + fileSeparator 50 | + "testfiles" + fileSeparator + "ModifyDubboServiceActionTest" + fileSeparator 51 | + "output" + fileSeparator + fileName, 52 | TEMP_DIR_PATH + fileSeparator + "input" + fileSeparator + fileName); 53 | } 54 | } -------------------------------------------------------------------------------- /src/test/java/com/huaweicse/tools/migrator/eureka/ModifyEurekaMainClassActionTest.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.eureka; 2 | 3 | import java.io.File; 4 | import java.util.Random; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.junit.jupiter.api.AfterEach; 8 | import org.junit.jupiter.api.BeforeEach; 9 | import org.junit.jupiter.api.Test; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | 13 | import com.huaweicse.tools.migrator.Utils; 14 | 15 | @SpringBootTest 16 | public class ModifyEurekaMainClassActionTest { 17 | private static final String BASE_PATH = System.getProperty("user.dir"); 18 | 19 | private String TEMP_DIR_PATH; 20 | 21 | private String fileSeparator = File.separator; 22 | 23 | @Autowired 24 | private ModifyEurekaMainClassAction modifyEurekaMainClassAction; 25 | 26 | @BeforeEach 27 | public void setUp() throws Exception { 28 | TEMP_DIR_PATH = System.getProperty("java.io.tmpdir") 29 | + File.separator + Math.abs(new Random().nextInt()); 30 | 31 | FileUtils.copyDirectoryToDirectory( 32 | new File(BASE_PATH + fileSeparator + "testfiles" + fileSeparator + "ModifyEurekaMainClassActionTest" 33 | + fileSeparator + "input"), 34 | new File(TEMP_DIR_PATH)); 35 | } 36 | 37 | @AfterEach 38 | public void tearDown() throws Exception { 39 | FileUtils.deleteDirectory(new File(TEMP_DIR_PATH)); 40 | } 41 | 42 | @Test 43 | public void testProcessMainClass() throws Exception { 44 | modifyEurekaMainClassAction.run(TEMP_DIR_PATH); 45 | String providerFileName = "EurekaProviderApplication.java"; 46 | String consumerFileName = "EurekaConsumerApplication.java"; 47 | String inputConmonFilePath = TEMP_DIR_PATH + fileSeparator + "input" + fileSeparator; 48 | String outputCommonFilePath = 49 | BASE_PATH + fileSeparator + "testfiles" + fileSeparator + "ModifyEurekaMainClassActionTest" + fileSeparator + 50 | "output" + fileSeparator; 51 | Utils.assertFileContentEquals(inputConmonFilePath + providerFileName, outputCommonFilePath + providerFileName); 52 | Utils.assertFileContentEquals(inputConmonFilePath + consumerFileName, outputCommonFilePath + consumerFileName); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/com/huaweicse/tools/migrator/hsf/ModifyHSFAddBootstrapYamlActionTest.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.hsf; 2 | 3 | import java.io.File; 4 | import java.util.Random; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.junit.jupiter.api.AfterEach; 8 | import org.junit.jupiter.api.BeforeEach; 9 | import org.junit.jupiter.api.Test; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | 13 | import com.huaweicse.tools.migrator.Utils; 14 | import com.huaweicse.tools.migrator.hsf.ModifyHSFAddBootstrapYamlAction; 15 | 16 | @SpringBootTest 17 | public class ModifyHSFAddBootstrapYamlActionTest { 18 | 19 | private static final String BASE_PATH = System.getProperty("user.dir"); 20 | 21 | private String TEMP_DIR_PATH; 22 | 23 | private String fileSeparator = File.separator; 24 | 25 | @Autowired 26 | private ModifyHSFAddBootstrapYamlAction modifyHSFAddBootstrapYamlAction; 27 | 28 | @BeforeEach 29 | public void setUp() throws Exception { 30 | TEMP_DIR_PATH = System.getProperty("java.io.tmpdir") 31 | + File.separator + Math.abs(new Random().nextInt()); 32 | 33 | FileUtils.copyDirectoryToDirectory( 34 | new File(BASE_PATH + fileSeparator + "testfiles" + fileSeparator + "ModifyHSFAddBootstrapYamlActionTest"), 35 | new File(TEMP_DIR_PATH)); 36 | } 37 | 38 | @AfterEach 39 | public void tearDown() throws Exception { 40 | FileUtils.deleteDirectory(new File(TEMP_DIR_PATH)); 41 | } 42 | 43 | @Test 44 | public void testAddBootstrapFile() throws Exception { 45 | modifyHSFAddBootstrapYamlAction.run(TEMP_DIR_PATH + fileSeparator + "ModifyHSFAddBootstrapYamlActionTest"); 46 | String originBootstrapContextPath = BASE_PATH + fileSeparator + "templates" + fileSeparator + "bootstrap.yml"; 47 | String newBootstrapFilePath = 48 | TEMP_DIR_PATH + fileSeparator + "ModifyHSFAddBootstrapYamlActionTest" + fileSeparator + 49 | "src" + fileSeparator + "main" + fileSeparator + "resources" + fileSeparator + "bootstrap.yml"; 50 | Utils.assertFileContentEquals(originBootstrapContextPath, newBootstrapFilePath); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/huaweicse/tools/migrator/hsf/ModifyHSFConsumerActionTest.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.hsf; 2 | 3 | import java.io.File; 4 | import java.util.Random; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.junit.jupiter.api.AfterEach; 8 | import org.junit.jupiter.api.BeforeEach; 9 | import org.junit.jupiter.api.Test; 10 | import org.junit.jupiter.api.TestInstance; 11 | import org.junit.jupiter.api.TestInstance.Lifecycle; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.boot.test.context.SpringBootTest; 14 | 15 | import com.huaweicse.tools.migrator.Utils; 16 | import com.huaweicse.tools.migrator.hsf.ModifyHSFConsumerAction; 17 | 18 | @SpringBootTest 19 | @TestInstance(Lifecycle.PER_CLASS) 20 | public class ModifyHSFConsumerActionTest { 21 | 22 | private static final String BASE_PATH = System.getProperty("user.dir"); 23 | 24 | private String TEMP_DIR_PATH; 25 | 26 | private String fileSeparator = File.separator; 27 | 28 | private String localFileBasePath; 29 | 30 | @Autowired 31 | private ModifyHSFConsumerAction modifyHSFConsumerAction; 32 | 33 | 34 | @BeforeEach 35 | public void setUp() throws Exception { 36 | TEMP_DIR_PATH = System.getProperty("java.io.tmpdir") 37 | + File.separator + Math.abs(new Random().nextInt()); 38 | 39 | FileUtils.copyDirectoryToDirectory(new File(BASE_PATH + fileSeparator + "testfiles" + fileSeparator + "input"), 40 | new File(TEMP_DIR_PATH)); 41 | } 42 | 43 | @AfterEach 44 | public void tearDown() throws Exception { 45 | FileUtils.deleteDirectory(new File(TEMP_DIR_PATH)); 46 | } 47 | 48 | // 规范开发风格文件测试 49 | @Test 50 | public void testModifyHSFConsumerActionStandardConfig() throws Exception { 51 | localFileBasePath = BASE_PATH + fileSeparator + "testfiles"; 52 | FileUtils.copyDirectoryToDirectory(new File(localFileBasePath + fileSeparator + "input"), 53 | new File(TEMP_DIR_PATH)); 54 | modifyHSFConsumerAction.run(TEMP_DIR_PATH + fileSeparator + "input"); 55 | 56 | String fileName = "HSFConsumerStandardConfig.java"; 57 | Utils.assertFileContentEquals(genFilePath(TEMP_DIR_PATH, "input", fileName), 58 | genFilePath(localFileBasePath, "output", fileName)); 59 | } 60 | 61 | // 非规范开发风格文件测试 62 | @Test 63 | public void testModifyHSFConsumerActionNonstandardConfig() throws Exception { 64 | localFileBasePath = BASE_PATH + fileSeparator + "testfiles"; 65 | FileUtils.copyDirectoryToDirectory(new File(localFileBasePath + fileSeparator + "input"), 66 | new File(TEMP_DIR_PATH)); 67 | modifyHSFConsumerAction.run(TEMP_DIR_PATH + fileSeparator + "input"); 68 | 69 | String fileName = "HSFConsumerNonstandardConfig.java"; 70 | Utils.assertFileContentEquals(genFilePath(TEMP_DIR_PATH, "input", fileName), 71 | genFilePath(localFileBasePath, "output", fileName)); 72 | } 73 | 74 | private String genFilePath(String fileBasePath, String type, String fileName) { 75 | return fileBasePath + fileSeparator + type + fileSeparator + fileName; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/test/java/com/huaweicse/tools/migrator/hsf/ModifyHSFInterface2RestActionTest.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.hsf; 2 | 3 | import java.io.File; 4 | import java.util.Random; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.junit.jupiter.api.AfterEach; 8 | import org.junit.jupiter.api.BeforeEach; 9 | import org.junit.jupiter.api.Test; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | 13 | import com.huaweicse.tools.migrator.Utils; 14 | import com.huaweicse.tools.migrator.hsf.ModifyHSFInterface2RestAction; 15 | 16 | @SpringBootTest 17 | public class ModifyHSFInterface2RestActionTest { 18 | 19 | private static final String BASE_PATH = System.getProperty("user.dir"); 20 | 21 | private String TEMP_DIR_PATH; 22 | 23 | private String fileSeparator = File.separator; 24 | 25 | @Autowired 26 | private ModifyHSFInterface2RestAction modifyHSFInterface2RestAction; 27 | 28 | @BeforeEach 29 | public void setUp() throws Exception { 30 | TEMP_DIR_PATH = System.getProperty("java.io.tmpdir") 31 | + File.separator + Math.abs(new Random().nextInt()); 32 | 33 | FileUtils.copyDirectoryToDirectory(new File(BASE_PATH + fileSeparator + "testfiles" + fileSeparator + "input"), 34 | new File(TEMP_DIR_PATH)); 35 | } 36 | 37 | @AfterEach 38 | public void tearDown() throws Exception { 39 | FileUtils.deleteDirectory(new File(TEMP_DIR_PATH)); 40 | } 41 | 42 | 43 | @Test 44 | public void testInterface2Rest() throws Exception { 45 | String localBaseFilePath = BASE_PATH + fileSeparator + "testfiles"; 46 | String tempBaseFilePath = TEMP_DIR_PATH + fileSeparator + "input"; 47 | modifyHSFInterface2RestAction.run(tempBaseFilePath); 48 | String fileName = "HSFInterfaceService.java"; 49 | Utils.assertFileContentEquals(localBaseFilePath + fileSeparator + "output" + fileSeparator + fileName, 50 | tempBaseFilePath + fileSeparator + fileName); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/huaweicse/tools/migrator/hsf/ModifyHSFMainClassActionTest.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.hsf; 2 | 3 | import java.io.File; 4 | import java.util.Random; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.junit.jupiter.api.AfterEach; 8 | import org.junit.jupiter.api.BeforeEach; 9 | import org.junit.jupiter.api.Test; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | 13 | import com.huaweicse.tools.migrator.Utils; 14 | import com.huaweicse.tools.migrator.hsf.ModifyHSFMainClassAction; 15 | 16 | @SpringBootTest 17 | public class ModifyHSFMainClassActionTest { 18 | private static final String BASE_PATH = System.getProperty("user.dir"); 19 | 20 | private String TEMP_DIR_PATH; 21 | 22 | private String fileSeparator = File.separator; 23 | 24 | @Autowired 25 | private ModifyHSFMainClassAction modifyHSFMainClassAction; 26 | 27 | @BeforeEach 28 | public void setUp() throws Exception { 29 | TEMP_DIR_PATH = System.getProperty("java.io.tmpdir") 30 | + File.separator + Math.abs(new Random().nextInt()); 31 | 32 | FileUtils.copyDirectoryToDirectory( 33 | new File(BASE_PATH + fileSeparator + "testfiles" + fileSeparator + "ModifyHSFMainClassActionTest" 34 | + fileSeparator + "input"), 35 | new File(TEMP_DIR_PATH)); 36 | } 37 | 38 | @AfterEach 39 | public void tearDown() throws Exception { 40 | FileUtils.deleteDirectory(new File(TEMP_DIR_PATH)); 41 | } 42 | 43 | @Test 44 | public void testProcessMainClass() throws Exception { 45 | modifyHSFMainClassAction.run(new String[] {TEMP_DIR_PATH}); 46 | Utils.assertFileContentEquals( 47 | TEMP_DIR_PATH + fileSeparator + "input" + fileSeparator + "HSFConsumerApplication.java", 48 | BASE_PATH + fileSeparator + "testfiles" + fileSeparator + "ModifyHSFMainClassActionTest" + fileSeparator + 49 | "output" + fileSeparator + "HSFConsumerApplication.java"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/huaweicse/tools/migrator/hsf/ModifyHSFPomActionTest.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.hsf; 2 | 3 | import java.io.File; 4 | import java.util.Random; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.junit.jupiter.api.AfterEach; 8 | import org.junit.jupiter.api.BeforeEach; 9 | import org.junit.jupiter.api.Test; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | 13 | import com.huaweicse.tools.migrator.Utils; 14 | import com.huaweicse.tools.migrator.hsf.ModifyHSFPomAction; 15 | 16 | @SpringBootTest 17 | public class ModifyHSFPomActionTest { 18 | 19 | private static final String BASE_PATH = System.getProperty("user.dir"); 20 | 21 | private String TEMP_DIR_PATH; 22 | 23 | private String fileSeparator = File.separator; 24 | 25 | @Autowired 26 | private ModifyHSFPomAction modifyHSFPomAction; 27 | 28 | @BeforeEach 29 | public void setUp() throws Exception { 30 | TEMP_DIR_PATH = System.getProperty("java.io.tmpdir") + fileSeparator + Math.abs(new Random().nextInt()); 31 | FileUtils.copyDirectoryToDirectory( 32 | new File(BASE_PATH + fileSeparator + "testfiles" 33 | + fileSeparator + "ModifyPomActionTest" + fileSeparator + "input"), 34 | new File(TEMP_DIR_PATH)); 35 | } 36 | 37 | @AfterEach 38 | public void tearDown() throws Exception { 39 | FileUtils.forceDeleteOnExit(new File(TEMP_DIR_PATH)); 40 | } 41 | 42 | @Test 43 | public void testModifyHSFPomAction() throws Exception { 44 | modifyHSFPomAction.run(TEMP_DIR_PATH + fileSeparator + "input"); 45 | String targetPomFilePath = 46 | BASE_PATH + fileSeparator + "testfiles" + fileSeparator + "ModifyPomActionTest" + fileSeparator + "output" 47 | + fileSeparator + "pom.xml"; 48 | String modifiedPomFilePath = 49 | TEMP_DIR_PATH + fileSeparator + "input" + fileSeparator + "pom.xml"; 50 | Utils.assertFileContentEquals(targetPomFilePath, modifiedPomFilePath); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/huaweicse/tools/migrator/hsf/ModifyHSFProviderActionTest.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.hsf; 2 | 3 | import java.io.File; 4 | import java.util.Random; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.junit.jupiter.api.AfterEach; 8 | import org.junit.jupiter.api.BeforeEach; 9 | import org.junit.jupiter.api.Test; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | 13 | import com.huaweicse.tools.migrator.Utils; 14 | import com.huaweicse.tools.migrator.hsf.ModifyHSFProviderAction; 15 | 16 | @SpringBootTest 17 | public class ModifyHSFProviderActionTest { 18 | 19 | private static final String BASE_PATH = System.getProperty("user.dir"); 20 | 21 | private String TEMP_DIR_PATH; 22 | 23 | private String fileSeparator = File.separator; 24 | 25 | @Autowired 26 | private ModifyHSFProviderAction modifyHSFProviderAction; 27 | 28 | @BeforeEach 29 | public void setUp() throws Exception { 30 | TEMP_DIR_PATH = System.getProperty("java.io.tmpdir") 31 | + File.separator + Math.abs(new Random().nextInt()); 32 | 33 | FileUtils.copyDirectoryToDirectory(new File(BASE_PATH + fileSeparator + "testfiles" + fileSeparator + "input"), 34 | new File(TEMP_DIR_PATH)); 35 | } 36 | 37 | @AfterEach 38 | public void tearDown() throws Exception { 39 | FileUtils.deleteDirectory(new File(TEMP_DIR_PATH)); 40 | } 41 | 42 | 43 | @Test 44 | public void testModifyHSFProviderAction() throws Exception { 45 | String localBaseFilePath = BASE_PATH + fileSeparator + "testfiles"; 46 | String tempBaseFilePath = TEMP_DIR_PATH + fileSeparator + "input"; 47 | modifyHSFProviderAction.run(tempBaseFilePath); 48 | 49 | String fileName = "HSFInterfaceServiceImpl.java"; 50 | Utils.assertFileContentEquals( 51 | localBaseFilePath + fileSeparator + "output" + fileSeparator + fileName, 52 | tempBaseFilePath + fileSeparator + fileName); 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /src/test/java/com/huaweicse/tools/migrator/nacos/ModifyNacosActionTest.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.tools.migrator.nacos; 2 | 3 | import java.io.File; 4 | import java.util.Random; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.junit.jupiter.api.AfterEach; 8 | import org.junit.jupiter.api.BeforeEach; 9 | import org.junit.jupiter.api.Test; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | 13 | import com.huaweicse.tools.migrator.Utils; 14 | 15 | @SpringBootTest 16 | public class ModifyNacosActionTest { 17 | private static final String BASE_PATH = System.getProperty("user.dir"); 18 | 19 | private String TEMP_DIR_PATH; 20 | 21 | private String fileSeparator = File.separator; 22 | 23 | @Autowired 24 | private ModifyNacosAction modifyNacosAction; 25 | 26 | @BeforeEach 27 | public void setUp() throws Exception { 28 | TEMP_DIR_PATH = System.getProperty("java.io.tmpdir") 29 | + File.separator + Math.abs(new Random().nextInt()); 30 | 31 | FileUtils.copyDirectoryToDirectory( 32 | new File(BASE_PATH + fileSeparator + "testfiles" + fileSeparator + "ModifyNacosActionTest" 33 | + fileSeparator + "input"), 34 | new File(TEMP_DIR_PATH)); 35 | } 36 | 37 | @AfterEach 38 | public void tearDown() throws Exception { 39 | FileUtils.forceDeleteOnExit(new File(TEMP_DIR_PATH)); 40 | } 41 | 42 | @Test 43 | public void testModifyNacosAction() throws Exception { 44 | modifyNacosAction.run(TEMP_DIR_PATH + fileSeparator + "input"); 45 | Utils.assertFolderAllFileContentEquals(TEMP_DIR_PATH + fileSeparator + "input", 46 | BASE_PATH + fileSeparator + "testfiles" + fileSeparator + "ModifyNacosActionTest" + fileSeparator + "output"); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /templates/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | # 微服务名称,默认使用ServiceStage组件名称,建议修改为固定值,因为微服务名称会被客户端使用,不能轻易变化。 4 | name: ${CAS_COMPONENT_NAME} 5 | cloud: 6 | servicecomb: 7 | discovery: 8 | # 应用名称,默认使用ServiceStage组件名称,建议修改。可以使用环境变量值,只有应用名称相同的微服务才能够相互发现。 9 | appName: ${CAS_APPLICATION_NAME:default-application} 10 | serviceName: ${spring.application.name} 11 | address: ${PAAS_CSE_SC_ENDPOINT:http://127.0.0.1:30100} 12 | version: 0.0.1 13 | config: 14 | serverAddr: ${PAAS_CSE_CC_ENDPOINT:http://127.0.0.1:30110} 15 | serverType: kie -------------------------------------------------------------------------------- /templates/dubbo.pom.json: -------------------------------------------------------------------------------- 1 | { 2 | "/**/": "模板文件,项目中必须以xxx.pom.json命名并放置在templates文件夹下,严格遵循以下格式", 3 | "properties" : [ 4 | { 5 | "operation" : "delete", 6 | "data" : [ 7 | { 8 | "property" : "dubbo-version" 9 | }, 10 | { 11 | "property" : "spring-boot.version" 12 | } 13 | ] 14 | }, 15 | { 16 | "operation" : "add", 17 | "data" : [ 18 | { 19 | "property" : "spring-boot.version", 20 | "value" : "2.5.3" 21 | }, 22 | { 23 | "property" : "spring-cloud.version", 24 | "value" : "2020.0.3" 25 | }, 26 | { "property" : "spring-cloud-huawei.version", 27 | "value" : "1.8.0-2020.0.x" 28 | } 29 | ] 30 | } 31 | ], 32 | "dependencyManagement.dependencies" : [ 33 | { 34 | "operation" : "delete", 35 | "data" : [ 36 | { 37 | "artifactId" : "dubbo-dependencies-bom" 38 | }, 39 | { 40 | "artifactId" : "spring-boot-dependencies" 41 | } 42 | ] 43 | }, 44 | { 45 | "operation" : "add", 46 | "data" : [ 47 | { 48 | "groupId" : "org.springframework.boot", 49 | "artifactId" : "spring-boot-dependencies", 50 | "version" : "${spring-boot.version}", 51 | "type" : "pom", 52 | "scope" : "import" 53 | }, 54 | { 55 | "groupId" : "com.huaweicloud", 56 | "artifactId" : "spring-cloud-huawei-bom", 57 | "version" : "${spring-cloud-huawei.version}", 58 | "type" : "pom", 59 | "scope" : "import" 60 | }, 61 | { 62 | "groupId" : "org.springframework.cloud", 63 | "artifactId" : "spring-cloud-dependencies", 64 | "version" : "${spring-cloud.version}", 65 | "type" : "pom", 66 | "scope" : "import" 67 | } 68 | ] 69 | } 70 | ], 71 | "dependencies" : [ 72 | { 73 | "operation" : "delete", 74 | "data" : [ 75 | { 76 | "artifactId" : "dubbo-spring-boot-starter" 77 | }, 78 | { 79 | "artifactId" : "dubbo-config-spring" 80 | }, 81 | { 82 | "artifactId" : "dubbo-metadata-report-zookeeper" 83 | }, 84 | { 85 | "artifactId" : "dubbo-configcenter-zookeeper" 86 | }, 87 | { 88 | "artifactId" : "dubbo-registry-zookeeper" 89 | } 90 | ] 91 | }, 92 | { 93 | "operation" : "add", 94 | "data" : [ 95 | { 96 | "groupId" : "com.huaweicloud", 97 | "artifactId" : "spring-cloud-starter-huawei-service-engine", 98 | "version" : "" 99 | }, 100 | { 101 | "groupId" : "org.springframework.cloud", 102 | "artifactId" : "spring-cloud-starter-openfeign", 103 | "version" : "" 104 | } 105 | ] 106 | } 107 | ], 108 | "build.plugins" : [ 109 | { 110 | "operation" : "replace", 111 | "data" : [ 112 | { 113 | "match" : { 114 | "artifactId": "pandora-boot-maven-plugin" 115 | }, 116 | "replacement": [ 117 | { 118 | "groupId" : "org.springframework.boot", 119 | "artifactId" : "spring-boot-maven-plugin" 120 | } 121 | ] 122 | } 123 | ] 124 | } 125 | ] 126 | } -------------------------------------------------------------------------------- /templates/eureka.pom.json: -------------------------------------------------------------------------------- 1 | { 2 | "/**/": "模板文件,项目中必须以xxx.pom.json命名并放置在templates文件夹下,严格遵循以下格式", 3 | "properties" : [ 4 | { 5 | "operation" : "delete", 6 | "data" : [ 7 | { 8 | "property" : "spring-cloud.version" 9 | }, 10 | { 11 | "property" : "spring-boot.version" 12 | } 13 | ] 14 | }, 15 | { 16 | "operation" : "add", 17 | "data" : [ 18 | { 19 | "property" : "spring-boot.version", 20 | "value" : "2.5.3" 21 | }, 22 | { 23 | "property" : "spring-cloud.version", 24 | "value" : "2020.0.3" 25 | }, 26 | { "property" : "spring-cloud-huawei.version", 27 | "value" : "1.8.0-2020.0.x" 28 | } 29 | ] 30 | } 31 | ], 32 | "dependencyManagement.dependencies" : [ 33 | { 34 | "operation" : "delete", 35 | "data" : [ 36 | { 37 | "artifactId" : "" 38 | }, 39 | { 40 | "artifactId" : "" 41 | } 42 | ] 43 | }, 44 | { 45 | "operation" : "add", 46 | "data" : [ 47 | { 48 | "groupId" : "com.huaweicloud", 49 | "artifactId" : "spring-cloud-huawei-bom", 50 | "version" : "${spring-cloud-huawei.version}", 51 | "type" : "pom", 52 | "scope" : "import" 53 | } 54 | ] 55 | } 56 | ], 57 | "dependencies" : [ 58 | { 59 | "operation" : "delete", 60 | "data" : [ 61 | { 62 | "artifactId" : "spring-cloud-starter-netflix-eureka-client" 63 | } 64 | ] 65 | }, 66 | { 67 | "operation" : "add", 68 | "data" : [ 69 | { 70 | "groupId" : "com.huaweicloud", 71 | "artifactId" : "spring-cloud-starter-huawei-service-engine", 72 | "version" : "" 73 | } 74 | ] 75 | }, 76 | { 77 | "operation" : "replace", 78 | "data" : [ 79 | { 80 | "match" : { 81 | "artifactId": "spring-cloud-starter-netflix-eureka-server" 82 | }, 83 | "replacement": [ 84 | { 85 | "groupId" : "com.huaweicloud", 86 | "artifactId" : "spring-cloud-starter-huawei-service-engine", 87 | "version" : "" 88 | } 89 | ] 90 | } 91 | ] 92 | } 93 | ], 94 | "build.plugins" : [ 95 | { 96 | "operation" : "", 97 | "data" : [ 98 | { 99 | "match" : { 100 | "artifactId": "" 101 | }, 102 | "replacement": [ 103 | { 104 | "groupId" : "", 105 | "artifactId" : "" 106 | } 107 | ] 108 | } 109 | ] 110 | } 111 | ] 112 | } -------------------------------------------------------------------------------- /templates/hsf.pom.json: -------------------------------------------------------------------------------- 1 | { 2 | "/**/": "模板文件,项目中必须以xxx.pom.json命名并放置在templates文件夹下,严格遵循以下格式", 3 | "properties" : [ 4 | { 5 | "operation" : "delete", 6 | "data" : [ 7 | { 8 | "property" : "pandora-boot.version" 9 | }, 10 | { 11 | "property" : "spring-boot.version" 12 | } 13 | ] 14 | }, 15 | { 16 | "operation" : "add", 17 | "data" : [ 18 | { 19 | "property" : "spring-boot.version", 20 | "value" : "2.5.3" 21 | }, 22 | { 23 | "property" : "spring-cloud.version", 24 | "value" : "2020.0.3" 25 | }, 26 | { "property" : "spring-cloud-huawei.version", 27 | "value" : "1.8.0-2020.0.x" 28 | } 29 | ] 30 | } 31 | ], 32 | "dependencyManagement.dependencies" : [ 33 | { 34 | "operation" : "delete", 35 | "data" : [ 36 | { 37 | "artifactId" : "spring-boot-dependencies" 38 | } 39 | ] 40 | }, 41 | { 42 | "operation" : "replace", 43 | "data" : [ 44 | { 45 | "match" : { 46 | "artifactId": "pandora-boot-starter-bom" 47 | }, 48 | "replacement": [ 49 | { 50 | "groupId" : "org.springframework.boot", 51 | "artifactId" : "spring-boot-dependencies", 52 | "version" : "${spring-boot.version}", 53 | "type" : "pom", 54 | "scope" : "import" 55 | }, 56 | { 57 | "groupId" : "com.huaweicloud", 58 | "artifactId" : "spring-cloud-huawei-bom", 59 | "version" : "${spring-cloud-huawei.version}", 60 | "type" : "pom", 61 | "scope" : "import" 62 | }, 63 | { 64 | "groupId" : "org.springframework.cloud", 65 | "artifactId" : "spring-cloud-dependencies", 66 | "version" : "${spring-cloud.version}", 67 | "type" : "pom", 68 | "scope" : "import" 69 | } 70 | ] 71 | } 72 | ] 73 | } 74 | ], 75 | "dependencies" : [ 76 | { 77 | "operation" : "delete", 78 | "data" : [ 79 | { 80 | "artifactId" : "taobao-hsf.sar" 81 | }, 82 | { 83 | "artifactId" : "pandora-boot-test" 84 | } 85 | ] 86 | }, 87 | { 88 | "operation" : "replace", 89 | "data" : [ 90 | { 91 | "match" : { 92 | "artifactId": "pandora-hsf-spring-boot-starter" 93 | }, 94 | "replacement": [ 95 | { 96 | "groupId" : "com.huaweicloud", 97 | "artifactId" : "spring-cloud-starter-huawei-service-engine", 98 | "version" : "" 99 | }, 100 | { 101 | "groupId" : "org.springframework.cloud", 102 | "artifactId" : "spring-cloud-starter-openfeign", 103 | "version" : "" 104 | } 105 | ] 106 | } 107 | ] 108 | } 109 | ], 110 | "build.plugins" : [ 111 | { 112 | "operation" : "replace", 113 | "data" : [ 114 | { 115 | "match" : { 116 | "artifactId": "pandora-boot-maven-plugin" 117 | }, 118 | "replacement": [ 119 | { 120 | "groupId" : "org.springframework.boot", 121 | "artifactId" : "spring-boot-maven-plugin" 122 | } 123 | ] 124 | } 125 | ] 126 | } 127 | ] 128 | } -------------------------------------------------------------------------------- /templates/nacos.pom.json: -------------------------------------------------------------------------------- 1 | { 2 | "/**/": "模板文件,项目中必须以xxx.pom.json命名并放置在templates文件夹下,严格遵循以下格式", 3 | "properties" : [ 4 | { 5 | "operation" : "delete", 6 | "data" : [ 7 | { 8 | "property" : "spring-cloud.version" 9 | }, 10 | { 11 | "property" : "spring-boot.version" 12 | }, 13 | { 14 | "property" : "spring-cloud-alibaba.version" 15 | } 16 | ] 17 | }, 18 | { 19 | "operation" : "add", 20 | "data" : [ 21 | { 22 | "property" : "spring-boot.version", 23 | "value" : "2.5.3" 24 | }, 25 | { 26 | "property" : "spring-cloud.version", 27 | "value" : "2020.0.3" 28 | }, 29 | { "property" : "spring-cloud-huawei.version", 30 | "value" : "1.8.0-2020.0.x" 31 | } 32 | ] 33 | } 34 | ], 35 | "dependencyManagement.dependencies" : [ 36 | { 37 | "operation" : "delete", 38 | "data" : [ 39 | { 40 | "artifactId" : "spring-cloud-alibaba-dependencies" 41 | } 42 | ] 43 | }, 44 | { 45 | "operation" : "add", 46 | "data" : [ 47 | { 48 | "groupId" : "com.huaweicloud", 49 | "artifactId" : "spring-cloud-huawei-bom", 50 | "version" : "${spring-cloud-huawei.version}", 51 | "type" : "pom", 52 | "scope" : "import" 53 | } 54 | ] 55 | } 56 | ], 57 | "dependencies" : [ 58 | { 59 | "operation" : "delete", 60 | "data" : [ 61 | { 62 | "artifactId" : "spring-cloud-starter-alibaba-nacos-config" 63 | } 64 | ] 65 | }, 66 | { 67 | "operation" : "replace", 68 | "data" : [ 69 | { 70 | "match" : { 71 | "artifactId": "spring-cloud-starter-alibaba-nacos-discovery" 72 | }, 73 | "replacement": [ 74 | { 75 | "groupId" : "com.huaweicloud", 76 | "artifactId" : "spring-cloud-starter-huawei-service-engine", 77 | "version" : "" 78 | } 79 | ] 80 | } 81 | ] 82 | } 83 | ] 84 | } -------------------------------------------------------------------------------- /testfiles/ModifyDubboAddBootstrapYamlActionTest/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # test -------------------------------------------------------------------------------- /testfiles/ModifyDubboInterface2RestActionTest/input/HelloService.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test.api; 2 | 3 | public interface HelloService { 4 | String hello(String name); 5 | } -------------------------------------------------------------------------------- /testfiles/ModifyDubboInterface2RestActionTest/input/HelloServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test.api; 2 | 3 | import org.apache.dubbo.config.annotation.DubboService; 4 | 5 | import com.huaweicloud.sample.api.HelloService; 6 | 7 | @DubboService 8 | public class HelloServiceImpl implements HelloService { 9 | @Override 10 | public String hello(String name) { 11 | return "Hello " + name + ", I am from provider"; 12 | } 13 | } -------------------------------------------------------------------------------- /testfiles/ModifyDubboInterface2RestActionTest/output/HelloService.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test.api; 2 | 3 | import org.springframework.web.bind.annotation.ResponseBody; 4 | import org.springframework.web.bind.annotation.PostMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | import org.springframework.web.bind.annotation.RequestBody; 7 | 8 | public interface HelloService { 9 | @ResponseBody 10 | @PostMapping(value = "/hello") 11 | String hello(@RequestParam(value="name") String name); 12 | } 13 | -------------------------------------------------------------------------------- /testfiles/ModifyDubboMainClassActionTest/input/dubbo-annotation/DubboConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.huaweicloud.sample; 2 | 3 | import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.annotation.PropertySource; 7 | 8 | @SpringBootApplication 9 | @EnableDubbo 10 | @PropertySource("classpath:/spring/dubbo-consumer.properties") 11 | public class DubboConsumerApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(DubboConsumerApplication.class, args); 14 | } 15 | } -------------------------------------------------------------------------------- /testfiles/ModifyDubboMainClassActionTest/input/dubbo-springboot/DubboConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.huaweicloud.sample; 2 | 3 | import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | @EnableDubbo 9 | public class DubboConsumerApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(DubboConsumerApplication.class, args); 12 | } 13 | } -------------------------------------------------------------------------------- /testfiles/ModifyDubboMainClassActionTest/input/dubbo-xml/DubboConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.huaweicloud.sample; 2 | 3 | import org.springframework.context.annotation.ImportResource; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | @ImportResource("consumer.xml") 9 | public class DubboConsumerApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(DubboConsumerApplication.class, args); 12 | } 13 | } -------------------------------------------------------------------------------- /testfiles/ModifyDubboMainClassActionTest/output/DubboConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.huaweicloud.sample; 2 | 3 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 4 | import org.springframework.cloud.openfeign.EnableFeignClients; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @SpringBootApplication 9 | @EnableDiscoveryClient 10 | @EnableFeignClients 11 | public class DubboConsumerApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(DubboConsumerApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-annotation/consumer/src/main/java/com/huaweicse/test/DubboAnnotationConsumerController.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import org.apache.dubbo.config.annotation.DubboReference; 4 | 5 | import com.huaweicse.test.api.HelloAnnotationService; 6 | 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | @RestController 13 | public class DubboAnnotationConsumerController { 14 | 15 | @DubboReference 16 | private HelloAnnotationService helloAnnotationService; 17 | 18 | @RequestMapping(value = "/hello", method = RequestMethod.GET) 19 | public String hello(@RequestParam("name") String name) { 20 | return helloAnnotationService.hello(name); 21 | } 22 | } -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-annotation/consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8886 -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-annotation/consumer/src/main/resources/spring/dubbo-consumer.properties: -------------------------------------------------------------------------------- 1 | dubbo.application.name=dubbo-annotation-consumer 2 | dubbo.protocol.name=dubbo 3 | dubbo.protocol.port=20880 4 | dubbo.registry.id=zk-registry 5 | dubbo.registry.address=zookeeper://127.0.0.1:2181 6 | dubbo.config-center.address=zookeeper://127.0.0.1:2181 7 | dubbo.metadata-report.address=zookeeper://127.0.0.1:2181 -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-annotation/provider/src/main/java/com/huaweicse/test/HelloAnnotationServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import org.apache.dubbo.config.annotation.DubboService; 4 | 5 | import com.huaweicse.test.api.HelloAnnotationService; 6 | 7 | @DubboService 8 | public class HelloAnnotationServiceImpl implements HelloAnnotationService { 9 | @Override 10 | public String hello(String name) { 11 | return "Hello " + name + ", I am from provider"; 12 | } 13 | } -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-annotation/provider/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8868 -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-annotation/provider/src/main/resources/spring/dubbo-provider.properties: -------------------------------------------------------------------------------- 1 | dubbo.application.name=dubbo-annotation-provider 2 | dubbo.protocol.name=dubbo 3 | dubbo.protocol.port=20880 4 | dubbo.registry.id=zk-registry 5 | dubbo.registry.address=zookeeper://127.0.0.1:2181 6 | dubbo.config-center.address=zookeeper://127.0.0.1:2181 7 | dubbo.metadata-report.address=zookeeper://127.0.0.1:2181 -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-springboot/consumer/src/main/java/com/huaweicse/test/DubboSpringBootConsumerController.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import org.apache.dubbo.config.annotation.DubboReference; 4 | 5 | import com.huaweicse.test.api.HelloSpringBootService; 6 | import com.huaweicse.test.api.HelloSpringBootAccountService; 7 | 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.RequestParam; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | @RestController 14 | public class DubboSpringBootConsumerController { 15 | 16 | @DubboReference 17 | private HelloSpringBootService helloSpringBootService; 18 | 19 | @DubboReference 20 | HelloSpringBootAccountService helloSpringBootAccountService; 21 | 22 | @RequestMapping(value = "/hello", method = RequestMethod.GET) 23 | public String hello(@RequestParam("name") String name) { 24 | return helloSpringBootService.hello(name); 25 | } 26 | 27 | @RequestMapping(value = "/accountInfo", method = RequestMethod.GET) 28 | public String accountInfo(@RequestParam("name") String name) { 29 | return helloSpringBootAccountService.accountInfo(name); 30 | } 31 | } -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-springboot/consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8886 3 | 4 | dubbo: 5 | application: 6 | name: dubbo-springboot-consumer 7 | protocol: 8 | name: dubbo 9 | port: 20880 10 | registry: 11 | id: zk-registry 12 | address: zookeeper://127.0.0.1:2181 13 | config-center: 14 | address: zookeeper://127.0.0.1:2181 15 | metadata-report: 16 | address: zookeeper://127.0.0.1:2181 -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-springboot/provider/src/main/java/com/huaweicse/test/HelloSpringBootAccountServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import org.apache.dubbo.config.annotation.DubboService; 4 | 5 | import com.huaweicse.test.api.HelloSpringBootAccountService; 6 | 7 | @DubboService 8 | public class HelloSpringBootAccountServiceImpl implements HelloSpringBootAccountService { 9 | @Override 10 | public String accountInfo(String name) { 11 | return "account info"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-springboot/provider/src/main/java/com/huaweicse/test/HelloSpringBootServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import org.apache.dubbo.config.annotation.DubboService; 4 | 5 | import com.huaweicse.test.api.HelloSpringBootService; 6 | 7 | @DubboService 8 | public class HelloSpringBootServiceImpl implements HelloSpringBootService { 9 | @Override 10 | public String hello(String name) { 11 | return "Hello " + name + ", I am from provider"; 12 | } 13 | } -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-springboot/provider/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8868 3 | 4 | dubbo: 5 | application: 6 | name: dubbo-springboot-provider 7 | protocol: 8 | name: dubbo 9 | port: 20880 10 | registry: 11 | id: zk-registry 12 | address: zookeeper://127.0.0.1:2181 13 | config-center: 14 | address: zookeeper://127.0.0.1:2181 15 | metadata-report: 16 | address: zookeeper://127.0.0.1:2181 -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-xml/common-api/src/main/java/com/huaweicse/test/api/HelloXmlService.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test.api; 2 | 3 | public interface HelloXmlService { 4 | String sayHello(); 5 | } 6 | -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-xml/consumer/src/main/java/com/huaweicse/test/DubboXmlConsumerController.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import com.huaweicse.test.api.HelloXmlService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | public class DubboXmlConsumerController { 10 | 11 | @Autowired 12 | private HelloXmlService helloXmlService; 13 | 14 | @RequestMapping("/sayHello") 15 | public String sayHello() { 16 | return helloXmlService.sayHello(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-xml/consumer/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8802 -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-xml/consumer/src/main/resources/consumer.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-xml/provider/src/main/java/com/huaweicse/test/HelloXmlServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import com.huaweicse.test.api.HelloXmlService; 4 | 5 | public class HelloXmlServiceImpl implements HelloXmlService { 6 | public String sayHello() { 7 | return "hello, the demo is for dubbo-xml."; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-xml/provider/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8801 -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/input/dubbo-xml/provider/src/main/resources/provider.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/output/dubbo-annotation/DubboAnnotationConsumerController.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | 5 | import com.huaweicse.test.api.HelloAnnotationService; 6 | 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | @RestController 13 | public class DubboAnnotationConsumerController { 14 | 15 | @Autowired 16 | private HelloAnnotationService helloAnnotationService; 17 | 18 | @RequestMapping(value = "/hello", method = RequestMethod.GET) 19 | public String hello(@RequestParam("name") String name) { 20 | return helloAnnotationService.hello(name); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/output/dubbo-annotation/DubboInterfaceConfig.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.config; 2 | 3 | import com.huaweicse.test.api.HelloAnnotationService; 4 | 5 | import org.springframework.cloud.openfeign.FeignClient; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | @Configuration 9 | public class DubboInterfaceConfig { 10 | 11 | @FeignClient(name = "dubbo-annotation-provider", contextId = "helloAnnotationService", path = "/helloAnnotationService") 12 | public interface HelloAnnotationServiceExt extends HelloAnnotationService{} 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/output/dubbo-springboot/DubboInterfaceConfig.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.config; 2 | 3 | import com.huaweicse.test.api.HelloSpringBootAccountService; 4 | import com.huaweicse.test.api.HelloSpringBootService; 5 | 6 | import org.springframework.cloud.openfeign.FeignClient; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | @Configuration 10 | public class DubboInterfaceConfig { 11 | 12 | @FeignClient(name = "dubbo-springboot-provider", contextId = "helloSpringBootAccountService", path = "/helloSpringBootAccountService") 13 | public interface HelloSpringBootAccountServiceExt extends HelloSpringBootAccountService{} 14 | 15 | @FeignClient(name = "dubbo-springboot-provider", contextId = "helloSpringBootService", path = "/helloSpringBootService") 16 | public interface HelloSpringBootServiceExt extends HelloSpringBootService{} 17 | 18 | } 19 | -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/output/dubbo-springboot/DubboSpringBootConsumerController.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | 5 | import com.huaweicse.test.api.HelloSpringBootService; 6 | import com.huaweicse.test.api.HelloSpringBootAccountService; 7 | 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.RequestParam; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | @RestController 14 | public class DubboSpringBootConsumerController { 15 | 16 | @Autowired 17 | private HelloSpringBootService helloSpringBootService; 18 | 19 | @Autowired 20 | HelloSpringBootAccountService helloSpringBootAccountService; 21 | 22 | @RequestMapping(value = "/hello", method = RequestMethod.GET) 23 | public String hello(@RequestParam("name") String name) { 24 | return helloSpringBootService.hello(name); 25 | } 26 | 27 | @RequestMapping(value = "/accountInfo", method = RequestMethod.GET) 28 | public String accountInfo(@RequestParam("name") String name) { 29 | return helloSpringBootAccountService.accountInfo(name); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/output/dubbo-xml/DubboInterfaceConfig.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.config; 2 | 3 | import com.huaweicse.test.api.HelloXmlService; 4 | 5 | import org.springframework.cloud.openfeign.FeignClient; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | @Configuration 9 | public class DubboInterfaceConfig { 10 | 11 | @FeignClient(name = "dubbo-xml-provider", contextId = "helloXmlService", path = "/helloXmlService") 12 | public interface HelloXmlServiceExt extends HelloXmlService{} 13 | 14 | } 15 | -------------------------------------------------------------------------------- /testfiles/ModifyDubboReferenceActionTest/output/dubbo-xml/HelloXmlServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import com.huaweicse.test.api.HelloXmlService; 4 | 5 | import org.springframework.web.bind.annotation.RestController; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | 8 | @RestController 9 | @RequestMapping("/helloXmlService") 10 | public class HelloXmlServiceImpl implements HelloXmlService { 11 | public String sayHello() { 12 | return "hello, the demo is for dubbo-xml."; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /testfiles/ModifyDubboServiceActionTest/input/HelloServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.huaweicloud.sample; 2 | 3 | import org.apache.dubbo.config.annotation.DubboService; 4 | 5 | import com.huaweicloud.sample.api.HelloService; 6 | 7 | @DubboService 8 | public class HelloServiceImpl implements HelloService { 9 | @Override 10 | public String hello(String name) { 11 | return "Hello " + name + ", I am from provider"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /testfiles/ModifyDubboServiceActionTest/output/HelloServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.huaweicloud.sample; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | import com.huaweicloud.sample.api.HelloService; 7 | 8 | @RestController 9 | @RequestMapping("/helloService") 10 | public class HelloServiceImpl implements HelloService { 11 | @Override 12 | public String hello(String name) { 13 | return "Hello " + name + ", I am from provider"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /testfiles/ModifyEurekaMainClassActionTest/input/EurekaConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.springcloud.eureka.samples; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | @SpringBootApplication 11 | @EnableEurekaClient 12 | public class EurekaConsumerApplication { 13 | public static void main(String[] args) { 14 | SpringApplication.run(EurekaConsumerApplication.class, args); 15 | } 16 | 17 | @LoadBalanced 18 | @Bean 19 | public RestTemplate restTemplate() { 20 | return new RestTemplate(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /testfiles/ModifyEurekaMainClassActionTest/input/EurekaProviderApplication.java: -------------------------------------------------------------------------------- 1 | package com.springcloud.eureka.samples; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class EurekaProviderApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(EurekaProviderApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /testfiles/ModifyEurekaMainClassActionTest/output/EurekaConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.springcloud.eureka.samples; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | @SpringBootApplication 11 | @EnableDiscoveryClient 12 | public class EurekaConsumerApplication { 13 | public static void main(String[] args) { 14 | SpringApplication.run(EurekaConsumerApplication.class, args); 15 | } 16 | 17 | @LoadBalanced 18 | @Bean 19 | public RestTemplate restTemplate() { 20 | return new RestTemplate(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /testfiles/ModifyEurekaMainClassActionTest/output/EurekaProviderApplication.java: -------------------------------------------------------------------------------- 1 | package com.springcloud.eureka.samples; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @SpringBootApplication 8 | @EnableDiscoveryClient 9 | public class EurekaProviderApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(EurekaProviderApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /testfiles/ModifyHSFAddBootstrapYamlActionTest/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # test -------------------------------------------------------------------------------- /testfiles/ModifyHSFMainClassActionTest/input/HSFConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.edas; 2 | 3 | import com.taobao.pandora.boot.PandoraBootstrap; 4 | 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @SpringBootApplication 9 | public class HSFConsumerApplication { 10 | 11 | public static void main(String[] args) { 12 | PandoraBootstrap.run(args); 13 | SpringApplication.run(HSFConsumerApplication.class, args); 14 | PandoraBootstrap.markStartupAndWait(); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /testfiles/ModifyHSFMainClassActionTest/output/HSFConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.edas; 2 | 3 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 4 | import org.springframework.cloud.openfeign.EnableFeignClients; 5 | 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | 9 | @EnableDiscoveryClient 10 | @EnableFeignClients 11 | @SpringBootApplication 12 | public class HSFConsumerApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(HSFConsumerApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/input/consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | nacos-demo 7 | com.huaweicse.test 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | consumer 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-web 18 | 19 | 20 | 21 | com.alibaba.cloud 22 | spring-cloud-starter-alibaba-nacos-discovery 23 | 24 | 25 | 26 | org.springframework.cloud 27 | spring-cloud-starter-openfeign 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-actuator 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-maven-plugin 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/input/consumer/src/main/java/com/huaweicse/test/ConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.openfeign.EnableFeignClients; 7 | 8 | @SpringBootApplication 9 | @EnableFeignClients 10 | @EnableDiscoveryClient 11 | public class ConsumerApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(ConsumerApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/input/consumer/src/main/java/com/huaweicse/test/ConsumerController.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | public class ConsumerController { 10 | 11 | @Autowired 12 | private ProviderService providerService; 13 | 14 | @GetMapping("sayHello") 15 | public String sayHello(@RequestParam("name") String name) { 16 | return providerService.sayHello(name); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/input/consumer/src/main/java/com/huaweicse/test/ProviderService.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | 7 | @FeignClient(value = "nacos-provider",contextId = "providerService") 8 | public interface ProviderService { 9 | @GetMapping(value = "/sayHello") 10 | String sayHello(@RequestParam("name") String name); 11 | } 12 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/input/consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | server: 3 | port: 18080 4 | 5 | management: 6 | endpoint: 7 | health: 8 | show-details: always 9 | endpoints: 10 | web: 11 | exposure: 12 | include: '*' 13 | 14 | spring: 15 | application: 16 | name: nacos-consumer 17 | cloud: 18 | nacos: 19 | discovery: 20 | server-addr: http://127.0.0.1:8848 21 | config: 22 | server-addr: http://127.0.0.1:8848 23 | 24 | feign: 25 | client: 26 | config: 27 | default: 28 | connectTimeout: 10000 29 | readTimeout: 10000 -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/input/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.huaweicse.test 8 | nacos-demo 9 | pom 10 | 11 | 1.0-SNAPSHOT 12 | 13 | 14 | provider 15 | consumer 16 | 17 | 18 | 19 | 1.8 20 | Hoxton.SR8 21 | 2.3.4.RELEASE 22 | 2.1.2.RELEASE 23 | 24 | 25 | 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-dependencies 30 | ${spring-cloud.version} 31 | pom 32 | import 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-dependencies 37 | ${spring-boot.version} 38 | pom 39 | import 40 | 41 | 42 | com.alibaba.cloud 43 | spring-cloud-alibaba-dependencies 44 | ${spring-cloud-alibaba.version} 45 | pom 46 | import 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/input/provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | nacos-demo 7 | com.huaweicse.test 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | provider 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-web 18 | 19 | 20 | 21 | com.alibaba.cloud 22 | spring-cloud-starter-alibaba-nacos-discovery 23 | 24 | 25 | 26 | com.alibaba.cloud 27 | spring-cloud-starter-alibaba-nacos-config 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-actuator 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-maven-plugin 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/input/provider/src/main/java/com/huaweicse/test/ProviderApplication.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @SpringBootApplication 8 | @EnableDiscoveryClient 9 | public class ProviderApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ProviderApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/input/provider/src/main/java/com/huaweicse/test/ProviderController.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RequestParam; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class ProviderController implements ProviderService { 9 | 10 | @GetMapping("sayHello") 11 | public String sayHello(@RequestParam("name") String name) { 12 | return "hello " + name + ", the demo is for nacos."; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/input/provider/src/main/java/com/huaweicse/test/ProviderService.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | public interface ProviderService { 4 | String sayHello(String name); 5 | } 6 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/input/provider/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | server: 3 | port: 18081 4 | 5 | management: 6 | endpoint: 7 | health: 8 | show-details: always 9 | endpoints: 10 | web: 11 | exposure: 12 | include: '*' 13 | 14 | spring: 15 | application: 16 | name: nacos-provider 17 | cloud: 18 | nacos: 19 | discovery: 20 | server-addr: http://127.0.0.1:8848 21 | config: 22 | server-addr: http://127.0.0.1:8848 -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/output/consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.huaweicse.test 7 | nacos-demo 8 | 1.0-SNAPSHOT 9 | 10 | consumer 11 | 12 | 13 | org.springframework.boot 14 | spring-boot-starter-web 15 | 16 | 17 | org.springframework.cloud 18 | spring-cloud-starter-openfeign 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-actuator 23 | 24 | 25 | com.huaweicloud 26 | spring-cloud-starter-huawei-service-engine 27 | 28 | 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-maven-plugin 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/output/consumer/src/main/java/com/huaweicse/test/ConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.openfeign.EnableFeignClients; 7 | 8 | @SpringBootApplication 9 | @EnableFeignClients 10 | @EnableDiscoveryClient 11 | public class ConsumerApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(ConsumerApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/output/consumer/src/main/java/com/huaweicse/test/ConsumerController.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | public class ConsumerController { 10 | 11 | @Autowired 12 | private ProviderService providerService; 13 | 14 | @GetMapping("sayHello") 15 | public String sayHello(@RequestParam("name") String name) { 16 | return providerService.sayHello(name); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/output/consumer/src/main/java/com/huaweicse/test/ProviderService.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | 7 | @FeignClient(value = "nacos-provider",contextId = "providerService") 8 | public interface ProviderService { 9 | @GetMapping(value = "/sayHello") 10 | String sayHello(@RequestParam("name") String name); 11 | } 12 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/output/consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | server: 3 | port: 18080 4 | 5 | management: 6 | endpoint: 7 | health: 8 | show-details: always 9 | endpoints: 10 | web: 11 | exposure: 12 | include: '*' 13 | 14 | spring: 15 | application: 16 | name: nacos-consumer 17 | cloud: 18 | nacos: 19 | discovery: 20 | server-addr: http://127.0.0.1:8848 21 | config: 22 | server-addr: http://127.0.0.1:8848 23 | 24 | feign: 25 | client: 26 | config: 27 | default: 28 | connectTimeout: 10000 29 | readTimeout: 10000 -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/output/consumer/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | # 微服务名称,默认使用ServiceStage组件名称,建议修改为固定值,因为微服务名称会被客户端使用,不能轻易变化。 4 | name: ${CAS_COMPONENT_NAME} 5 | cloud: 6 | servicecomb: 7 | discovery: 8 | # 应用名称,默认使用ServiceStage组件名称,建议修改。可以使用环境变量值,只有应用名称相同的微服务才能够相互发现。 9 | appName: ${CAS_APPLICATION_NAME:default-application} 10 | serviceName: ${spring.application.name} 11 | address: ${PAAS_CSE_SC_ENDPOINT:http://127.0.0.1:30100} 12 | version: 0.0.1 13 | config: 14 | serverAddr: ${PAAS_CSE_CC_ENDPOINT:http://127.0.0.1:30110} 15 | serverType: kie -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/output/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | com.huaweicse.test 6 | nacos-demo 7 | 1.0-SNAPSHOT 8 | pom 9 | 10 | provider 11 | consumer 12 | 13 | 14 | 2.5.3 15 | 2020.0.3 16 | 1.8 17 | 1.8.0-2020.0.x 18 | 19 | 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-dependencies 24 | ${spring-cloud.version} 25 | pom 26 | import 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-dependencies 31 | ${spring-boot.version} 32 | pom 33 | import 34 | 35 | 36 | com.huaweicloud 37 | spring-cloud-huawei-bom 38 | ${spring-cloud-huawei.version} 39 | pom 40 | import 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/output/provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.huaweicse.test 7 | nacos-demo 8 | 1.0-SNAPSHOT 9 | 10 | provider 11 | 12 | 13 | org.springframework.boot 14 | spring-boot-starter-web 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-actuator 19 | 20 | 21 | com.huaweicloud 22 | spring-cloud-starter-huawei-service-engine 23 | 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-maven-plugin 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/output/provider/src/main/java/com/huaweicse/test/ProviderApplication.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @SpringBootApplication 8 | @EnableDiscoveryClient 9 | public class ProviderApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ProviderApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/output/provider/src/main/java/com/huaweicse/test/ProviderController.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RequestParam; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class ProviderController implements ProviderService { 9 | 10 | @GetMapping("sayHello") 11 | public String sayHello(@RequestParam("name") String name) { 12 | return "hello " + name + ", the demo is for nacos."; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/output/provider/src/main/java/com/huaweicse/test/ProviderService.java: -------------------------------------------------------------------------------- 1 | package com.huaweicse.test; 2 | 3 | public interface ProviderService { 4 | String sayHello(String name); 5 | } 6 | -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/output/provider/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | server: 3 | port: 18081 4 | 5 | management: 6 | endpoint: 7 | health: 8 | show-details: always 9 | endpoints: 10 | web: 11 | exposure: 12 | include: '*' 13 | 14 | spring: 15 | application: 16 | name: nacos-provider 17 | cloud: 18 | nacos: 19 | discovery: 20 | server-addr: http://127.0.0.1:8848 21 | config: 22 | server-addr: http://127.0.0.1:8848 -------------------------------------------------------------------------------- /testfiles/ModifyNacosActionTest/output/provider/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | # 微服务名称,默认使用ServiceStage组件名称,建议修改为固定值,因为微服务名称会被客户端使用,不能轻易变化。 4 | name: ${CAS_COMPONENT_NAME} 5 | cloud: 6 | servicecomb: 7 | discovery: 8 | # 应用名称,默认使用ServiceStage组件名称,建议修改。可以使用环境变量值,只有应用名称相同的微服务才能够相互发现。 9 | appName: ${CAS_APPLICATION_NAME:default-application} 10 | serviceName: ${spring.application.name} 11 | address: ${PAAS_CSE_SC_ENDPOINT:http://127.0.0.1:30100} 12 | version: 0.0.1 13 | config: 14 | serverAddr: ${PAAS_CSE_CC_ENDPOINT:http://127.0.0.1:30110} 15 | serverType: kie -------------------------------------------------------------------------------- /testfiles/ModifyPomActionTest/input/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 2.6.4 10 | 11 | 12 | 13 | com.huawei.tools 14 | migrate-application 15 | 0.0.1-SNAPSHOT 16 | pom-test 17 | pom test for ModifyHSFPomAction 18 | 19 | 20 | 1.8 21 | 2.1.6.RELEASE 22 | 2019-06-stable 23 | 24 | 25 | 26 | 27 | com.alibaba.boot 28 | pandora-hsf-spring-boot-starter 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-web 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-dependencies 41 | ${spring-boot.version} 42 | pom 43 | import 44 | 45 | 46 | com.taobao.pandora 47 | pandora-boot-starter-bom 48 | ${pandora-boot.version} 49 | pom 50 | import 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | org.apache.maven.plugins 59 | maven-compiler-plugin 60 | 3.7.0 61 | 62 | 1.8 63 | 1.8 64 | 65 | 66 | 67 | com.taobao.pandora 68 | pandora-boot-maven-plugin 69 | 2.1.11.8 70 | 71 | 72 | package 73 | 74 | repackage 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /testfiles/ModifyPomActionTest/output/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.6.4 9 | 10 | 11 | com.huawei.tools 12 | migrate-application 13 | 0.0.1-SNAPSHOT 14 | pom-test 15 | pom test for ModifyHSFPomAction 16 | 17 | 2.5.3 18 | 2020.0.3 19 | 1.8 20 | 1.8.0-2020.0.x 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-dependencies 27 | ${spring-boot.version} 28 | pom 29 | import 30 | 31 | 32 | com.huaweicloud 33 | spring-cloud-huawei-bom 34 | ${spring-cloud-huawei.version} 35 | pom 36 | import 37 | 38 | 39 | org.springframework.cloud 40 | spring-cloud-dependencies 41 | ${spring-cloud.version} 42 | pom 43 | import 44 | 45 | 46 | 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-starter-web 51 | 52 | 53 | com.huaweicloud 54 | spring-cloud-starter-huawei-service-engine 55 | 56 | 57 | org.springframework.cloud 58 | spring-cloud-starter-openfeign 59 | 60 | 61 | 62 | 63 | 64 | maven-compiler-plugin 65 | 3.7.0 66 | 67 | 1.8 68 | 1.8 69 | 70 | 71 | 72 | org.springframework.boot 73 | spring-boot-maven-plugin 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /testfiles/input/HSFConsumerNonstandardConfig.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.huaweicse.tools.migrator; 4 | 5 | import com.alibaba.boot.hsf.annotation.HSFConsumer; 6 | 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | 10 | @Configuration 11 | public class HSFConsumerNonstandardConfig { 12 | 13 | @HSFConsumer(clientTimeout = 3000, serviceVersion = "1.0.0") 14 | private MissGroupService missGroupService; 15 | 16 | @HSFConsumer(clientTimeout = 3000, serviceGroup = "nomal", serviceVersion = "1.0.0") 17 | private NomalService nomalService; 18 | } 19 | -------------------------------------------------------------------------------- /testfiles/input/HSFConsumerStandardConfig.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.huaweicse.tools.migrator; 4 | 5 | import com.alibaba.boot.hsf.annotation.HSFConsumer; 6 | 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | 10 | @Configuration 11 | public class HSFConsumerStandardConfig { 12 | 13 | @HSFConsumer(clientTimeout = 3000, serviceGroup = "travel", serviceVersion = "1.0.0") 14 | private TravelService travelService; 15 | 16 | @HSFConsumer(clientTimeout = 3000, serviceGroup = "finance", serviceVersion = "1.0.0") 17 | private FinanceService financeService; 18 | 19 | @HSFConsumer(clientTimeout = 3000, serviceGroup = "user", serviceVersion = "1.0.0") 20 | private UserService userService; 21 | } 22 | -------------------------------------------------------------------------------- /testfiles/input/HSFInterfaceService.java: -------------------------------------------------------------------------------- 1 | 2 | package com.huaweicse.tools.migrator; 3 | 4 | public interface HSFInterfaceService { 5 | 6 | String hello(String str); 7 | 8 | // 无参数 9 | List noArg(); 10 | 11 | List str(String string); 12 | 13 | // 单行注释 14 | List slComment(List list); 15 | 16 | /** 17 | * 18 | * @param map 19 | * @return 20 | */ 21 | Map muComment(Map map); 22 | 23 | String mix(List stringList, Integer num); 24 | 25 | ResultBody single(EntityBody entityBody, Long count, Double num); 26 | 27 | // 该情况下打印error日志,稍后手动进行参数重构 28 | ResultBody manyBody(BodyOne bodyOne, BodyTwo bodyTwo, Long count, Double num); 29 | } -------------------------------------------------------------------------------- /testfiles/input/HSFInterfaceServiceImpl.java: -------------------------------------------------------------------------------- 1 | 2 | package com.huaweicse.tools.migrator; 3 | 4 | import com.alibaba.boot.hsf.annotation.HSFProvider; 5 | 6 | 7 | @HSFProvider(serviceInterface = HSFInterfaceService.class, serviceVersion = "1.0.0") 8 | public class HSFInterfaceServiceImpl implements HSFInterfaceService { 9 | 10 | @Override 11 | public String hello(String name) { 12 | return name; 13 | } 14 | 15 | } -------------------------------------------------------------------------------- /testfiles/output/HSFConsumerNonstandardConfig.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.huaweicse.tools.migrator; 4 | 5 | import org.springframework.cloud.openfeign.FeignClient; 6 | 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | 10 | @Configuration 11 | public class HSFConsumerNonstandardConfig { 12 | 13 | @HSFConsumer(clientTimeout = 3000, serviceVersion = "1.0.0") 14 | private MissGroupService missGroupService; 15 | 16 | @FeignClient(name = "nomal", contextId = "nomalService", path = "/nomalService") 17 | public interface NomalServiceExt extends NomalService{} 18 | } 19 | -------------------------------------------------------------------------------- /testfiles/output/HSFConsumerStandardConfig.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.huaweicse.tools.migrator; 4 | 5 | import org.springframework.cloud.openfeign.FeignClient; 6 | 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | 10 | @Configuration 11 | public class HSFConsumerStandardConfig { 12 | 13 | @FeignClient(name = "travel", contextId = "travelService", path = "/travelService") 14 | public interface TravelServiceExt extends TravelService{} 15 | 16 | @FeignClient(name = "finance", contextId = "financeService", path = "/financeService") 17 | public interface FinanceServiceExt extends FinanceService{} 18 | 19 | @FeignClient(name = "user", contextId = "userService", path = "/userService") 20 | public interface UserServiceExt extends UserService{} 21 | } 22 | -------------------------------------------------------------------------------- /testfiles/output/HSFInterfaceService.java: -------------------------------------------------------------------------------- 1 | 2 | package com.huaweicse.tools.migrator; 3 | 4 | import org.springframework.web.bind.annotation.ResponseBody; 5 | import org.springframework.web.bind.annotation.PostMapping; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | import org.springframework.web.bind.annotation.RequestBody; 8 | 9 | public interface HSFInterfaceService { 10 | 11 | @ResponseBody 12 | @PostMapping(value = "/hello") 13 | String hello(@RequestParam(value="str") String str); 14 | 15 | // 无参数 16 | @ResponseBody 17 | @PostMapping(value = "/noArg", produces = "x-application/hessian2") 18 | List noArg(); 19 | 20 | @ResponseBody 21 | @PostMapping(value = "/str", produces = "x-application/hessian2") 22 | List str(@RequestParam(value="string") String string); 23 | 24 | // 单行注释 25 | @ResponseBody 26 | @PostMapping(value = "/slComment", produces = "x-application/hessian2", consumes = "x-application/hessian2") 27 | List slComment(@RequestBody List list); 28 | 29 | /** 30 | * 31 | * @param map 32 | * @return 33 | */ 34 | @ResponseBody 35 | @PostMapping(value = "/muComment", produces = "x-application/hessian2", consumes = "x-application/hessian2") 36 | Map muComment(@RequestBody Map map); 37 | 38 | @ResponseBody 39 | @PostMapping(value = "/mix", consumes = "x-application/hessian2") 40 | String mix(@RequestBody List stringList, @RequestParam(value="num") Integer num); 41 | 42 | @ResponseBody 43 | @PostMapping(value = "/single", produces = "x-application/hessian2", consumes = "x-application/hessian2") 44 | ResultBody single(@RequestBody EntityBody entityBody, @RequestParam(value="count") Long count, @RequestParam(value="num") Double num); 45 | 46 | // 该情况下打印error日志,稍后手动进行参数重构 47 | @ResponseBody 48 | @PostMapping(value = "/manyBody", produces = "x-application/hessian2", consumes = "x-application/hessian2") 49 | ResultBody manyBody(BodyOne bodyOne, BodyTwo bodyTwo, Long count, Double num); 50 | } 51 | -------------------------------------------------------------------------------- /testfiles/output/HSFInterfaceServiceImpl.java: -------------------------------------------------------------------------------- 1 | 2 | package com.huaweicse.tools.migrator; 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | 8 | @RestController 9 | @RequestMapping("/hSFInterfaceService") 10 | public class HSFInterfaceServiceImpl implements HSFInterfaceService { 11 | 12 | @Override 13 | public String hello(String name) { 14 | return name; 15 | } 16 | 17 | } 18 | --------------------------------------------------------------------------------