├── .gitattributes ├── .github ├── stale.yml └── workflows │ └── maven.yml ├── .gitignore ├── LICENSE ├── README.md ├── deploy-image.bat ├── deploy-image.sh ├── deploy.bat ├── install-docker.bat ├── install-docker.sh ├── install.bat ├── install.sh ├── pmd.xml ├── pom.xml ├── skeleton-engine ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── nepxion │ │ └── skeleton │ │ └── engine │ │ ├── config │ │ └── SkeletonConfig.java │ │ ├── constant │ │ └── SkeletonConstant.java │ │ ├── context │ │ └── SkeletonContext.java │ │ ├── entity │ │ ├── SkeletonEntity.java │ │ ├── SkeletonEntityType.java │ │ ├── SkeletonFileType.java │ │ ├── SkeletonGroup.java │ │ ├── SkeletonGroupLayoutType.java │ │ └── SkeletonGroupType.java │ │ ├── exception │ │ └── SkeletonException.java │ │ ├── generator │ │ ├── AbstractSkeletonGenerator.java │ │ ├── SkeletonFileGenerator.java │ │ └── SkeletonJavaGenerator.java │ │ ├── model │ │ ├── CharacterCaseModel.java │ │ └── CharacterCaseWriter.java │ │ ├── parser │ │ └── SkeletonXmlParser.java │ │ ├── property │ │ ├── SkeletonContent.java │ │ └── SkeletonProperties.java │ │ ├── transport │ │ ├── SkeletonConfigTransport.java │ │ └── SkeletonDataTransport.java │ │ ├── util │ │ ├── FileUtil.java │ │ ├── IOUtil.java │ │ ├── MathsUtil.java │ │ ├── SkeletonUtil.java │ │ ├── StringUtil.java │ │ └── ZipUtil.java │ │ └── xml │ │ ├── Dom4JParser.java │ │ ├── Dom4JReader.java │ │ └── Dom4JWriter.java │ └── resources │ └── com │ └── nepxion │ └── skeleton │ └── resource │ └── logo.txt ├── skeleton-framework ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── nepxion │ └── skeleton │ └── framework │ ├── annotation │ └── SkeletonPlugin.java │ ├── aop │ └── SkeletonBeanPostProcessor.java │ ├── configuration │ ├── CorsRegistryConfiguration.java │ ├── SkeletonConfiguration.java │ └── SwaggerConfiguration.java │ ├── controller │ └── SkeletonController.java │ ├── service │ └── SkeletonService.java │ └── transport │ └── SkeletonTransport.java ├── skeleton-plugin-springcloud ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── nepxion │ │ │ └── skeleton │ │ │ └── plugin │ │ │ └── springcloud │ │ │ ├── configuration │ │ │ └── SpringCloudPluginConfiguration.java │ │ │ ├── generator │ │ │ ├── InstallDockerShellGenerator.java │ │ │ ├── PomXmlGenerator.java │ │ │ ├── client │ │ │ │ ├── PomXmlGenerator.java │ │ │ │ ├── java │ │ │ │ │ ├── AbstractClientTestClassGenerator.java │ │ │ │ │ ├── ClientApplicationClassGenerator.java │ │ │ │ │ ├── ClientContextAwareClassGenerator.java │ │ │ │ │ ├── ClientControllerClassGenerator.java │ │ │ │ │ ├── ClientRestTestClassGenerator.java │ │ │ │ │ ├── ClientRpcTestClassGenerator.java │ │ │ │ │ └── ClientServiceClassGenerator.java │ │ │ │ └── resources │ │ │ │ │ └── ApplicationPropertiesGenerator.java │ │ │ ├── eureka │ │ │ │ ├── PomXmlGenerator.java │ │ │ │ ├── java │ │ │ │ │ └── EurekaApplicationClassGenerator.java │ │ │ │ └── resources │ │ │ │ │ └── ApplicationPropertiesGenerator.java │ │ │ ├── server │ │ │ │ ├── PomXmlGenerator.java │ │ │ │ ├── java │ │ │ │ │ ├── ServerApplicationClassGenerator.java │ │ │ │ │ ├── ServerConfigClassGenerator.java │ │ │ │ │ ├── ServerControllerClassGenerator.java │ │ │ │ │ └── TestServerApplicationClassGenerator.java │ │ │ │ └── resources │ │ │ │ │ └── ApplicationPropertiesGenerator.java │ │ │ └── shared │ │ │ │ ├── GitAttributesGenerator.java │ │ │ │ ├── GitIgnoreGenerator.java │ │ │ │ └── resources │ │ │ │ └── LogbackXmlGenerator.java │ │ │ └── impl │ │ │ ├── ClientProjectServiceImpl.java │ │ │ ├── EurekaProjectServiceImpl.java │ │ │ ├── ParentProjectServiceImpl.java │ │ │ ├── ServerProjectServiceImpl.java │ │ │ └── SpringcloudServiceImpl.java │ └── resources │ │ └── springcloud │ │ ├── config │ │ ├── skeleton-context.properties │ │ ├── skeleton-data.properties │ │ └── skeleton-description.xml │ │ └── template │ │ ├── client │ │ ├── java │ │ │ ├── AbstractClientTest.java.template │ │ │ ├── ClientApplication.java.template │ │ │ ├── ClientContextAware.java.template │ │ │ ├── ClientController.java.template │ │ │ ├── ClientRestTest.java.template │ │ │ ├── ClientRpcTest.java.template │ │ │ └── ClientService.java.template │ │ ├── pom.xml.template │ │ └── resources │ │ │ └── application.properties.template │ │ ├── eureka │ │ ├── java │ │ │ └── EurekaApplication.java.template │ │ ├── pom.xml.template │ │ └── resources │ │ │ └── application.properties.template │ │ ├── install-docker.bat.template │ │ ├── install-docker.sh.template │ │ ├── pom.xml.template │ │ ├── server │ │ ├── java │ │ │ ├── ServerApplication.java.template │ │ │ ├── ServerConfig.java.template │ │ │ ├── ServerController.java.template │ │ │ └── TestServerApplication.java.template │ │ ├── pom.xml.template │ │ └── resources │ │ │ └── application.properties.template │ │ └── shared │ │ ├── file.gitattributes.template │ │ ├── file.gitignore.template │ │ └── resources │ │ └── logback.xml.template │ └── test │ ├── java │ └── com │ │ └── nepxion │ │ └── skeleton │ │ └── plugin │ │ └── springcloud │ │ └── SkeletonTest.java │ └── resources │ └── logback.xml ├── skeleton-service ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── nepxion │ │ └── skeleton │ │ └── service │ │ └── SkeletonApplication.java │ └── resources │ ├── application.properties │ └── logback.xml ├── skeleton-starter ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── nepxion │ │ └── skeleton │ │ ├── annotation │ │ └── EnableSkeleton.java │ │ └── aop │ │ └── SkeletonImportSelector.java │ └── resources │ └── META-INF │ └── spring.factories └── version.bat /.gitattributes: -------------------------------------------------------------------------------- 1 | # Declare files that will always have UNIX line endings on checkout. 2 | *.sh text eol=lf -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # General configuration 2 | # Number of days of inactivity before an issue becomes stale 3 | daysUntilStale: 60 4 | # Issues with these labels will never be considered stale 5 | exemptLabels: 6 | - good first issue 7 | - contribution welcome 8 | - bug 9 | - discussion 10 | - enhancement 11 | - feature 12 | - feature request 13 | - help wanted 14 | - info 15 | - need investigation 16 | - tips 17 | 18 | # Set to true to ignore issues in a project (defaults to false) 19 | exemptProjects: true 20 | # Set to true to ignore issues in a milestone (defaults to false) 21 | exemptMilestones: true 22 | # Set to true to ignore issues with an assignee (defaults to false) 23 | exemptAssignees: true 24 | # Label to use when marking an issue as stale 25 | staleLabel: stale 26 | 27 | # Pull request specific configuration 28 | pulls: 29 | # Number of days of inactivity before a stale Issue or Pull Request is closed. 30 | # Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale. 31 | daysUntilClose: 30 32 | # Comment to post when marking as stale. Set to `false` to disable 33 | markComment: > 34 | This pull request has been automatically marked as stale because it has not had activity 35 | in the last 90 days. It will be closed in 30 days if no further activity occurs. Please 36 | feel free to give a status update now, ping for review, or re-open when it's ready. 37 | Thank you for your contributions! 38 | # Comment to post when closing a stale Issue or Pull Request. 39 | closeComment: > 40 | This pull request has been automatically closed because it has not had 41 | activity in the last 30 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. 42 | Thank you for your contributions! 43 | # Limit the number of actions per hour, from 1-30. Default is 30 44 | limitPerRun: 1 45 | 46 | # Issue specific configuration 47 | issues: 48 | # Number of days of inactivity before a stale Issue or Pull Request is closed. 49 | daysUntilClose: 14 50 | # Comment to post when marking as stale. Set to `false` to disable 51 | markComment: > 52 | This issue has been automatically marked as stale because it has not had activity in the 53 | last 90 days. It will be closed in 14 days unless it is tagged "help wanted" or other activity 54 | occurs. Thank you for your contributions. 55 | # Comment to post when closing a stale Issue or Pull Request. 56 | closeComment: > 57 | This issue has been automatically closed because it has not had activity in the 58 | last 14 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted". 59 | Thank you for your contributions. 60 | # Limit the number of actions per hour, from 1-30. Default is 30 61 | limitPerRun: 1 -------------------------------------------------------------------------------- /.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: build 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Set up JDK 8 20 | uses: actions/setup-java@v2 21 | with: 22 | java-version: '8' 23 | distribution: 'adopt' 24 | - name: Build with Maven 25 | run: mvn -B package --file pom.xml -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | .classpath 4 | .springBeans 5 | .factorypath 6 | # Mobile Tools for Java (J2ME) 7 | .mtj.tmp/ 8 | 9 | *.class 10 | *.classpath 11 | *.project 12 | *.springBeans 13 | bin/ 14 | log/ 15 | test-output/ 16 | 17 | # Package Files # 18 | *.jar 19 | *.war 20 | *.ear 21 | *.zip 22 | *.tar.gz 23 | *.rar 24 | *.swp 25 | *.log 26 | *.ctxt 27 | # nodejs local modules 28 | .tags* 29 | .idea/ 30 | *.iml 31 | .gradle/ 32 | .settings/ 33 | target/ 34 | hs_err_pid* -------------------------------------------------------------------------------- /deploy-image.bat: -------------------------------------------------------------------------------- 1 | @echo on 2 | @echo ============================================================= 3 | @echo $ $ 4 | @echo $ Nepxion Skeleton $ 5 | @echo $ $ 6 | @echo $ $ 7 | @echo $ $ 8 | @echo $ Nepxion Studio All Right Reserved $ 9 | @echo $ Copyright (C) 2017-2050 $ 10 | @echo $ $ 11 | @echo ============================================================= 12 | @echo. 13 | @echo off 14 | 15 | @title Nepxion Skeleton 16 | @color 0a 17 | 18 | @set REGISTRY_URL=registry.cn-hangzhou.aliyuncs.com 19 | @set REPOSITORY_NAME=nepxion/skeleton 20 | @set USER_NAME=nepxion 21 | @set IMAGE_NAME=skeleton-service 22 | @set IMAGE_VERSION=latest 23 | 24 | @echo Please input password of username=%USER_NAME% for %REGISTRY_URL%: 25 | call docker login --username=%USER_NAME% %REGISTRY_URL% 26 | call docker rmi %REGISTRY_URL%/%REPOSITORY_NAME%:%IMAGE_VERSION% 27 | call docker tag %IMAGE_NAME%:%IMAGE_VERSION% %REGISTRY_URL%/%REPOSITORY_NAME%:%IMAGE_VERSION% 28 | call docker push %REGISTRY_URL%/%REPOSITORY_NAME%:%IMAGE_VERSION% 29 | 30 | pause -------------------------------------------------------------------------------- /deploy-image.sh: -------------------------------------------------------------------------------- 1 | echo 'on' 2 | echo '=============================================================' 3 | echo '$ $' 4 | echo '$ Nepxion Skeleton $' 5 | echo '$ $' 6 | echo '$ $' 7 | echo '$ $' 8 | echo '$ Nepxion Studio All Right Reserved $' 9 | echo '$ Copyright (C) 2017-2050 $' 10 | echo '$ $' 11 | echo '=============================================================' 12 | echo '.' 13 | echo 'off' 14 | 15 | title=Nepxion Skeleton 16 | color=0a 17 | 18 | REGISTRY_URL=registry.cn-hangzhou.aliyuncs.com 19 | REPOSITORY_NAME=nepxion/skeleton 20 | USER_NAME=nepxion 21 | IMAGE_NAME=skeleton-service 22 | IMAGE_VERSION=latest 23 | 24 | # Please input password of username=${USER_NAME} for ${REGISTRY_URL}: 25 | docker login --username=${USER_NAME} ${REGISTRY_URL} 26 | docker rmi ${REGISTRY_URL}/${REPOSITORY_NAME}:${IMAGE_VERSION} 27 | docker tag ${IMAGE_NAME}:${IMAGE_VERSION} ${REGISTRY_URL}/${REPOSITORY_NAME}:${IMAGE_VERSION} 28 | docker push ${REGISTRY_URL}/${REPOSITORY_NAME}:${IMAGE_VERSION} -------------------------------------------------------------------------------- /deploy.bat: -------------------------------------------------------------------------------- 1 | @echo on 2 | @echo ============================================================= 3 | @echo $ $ 4 | @echo $ Nepxion Skeleton $ 5 | @echo $ $ 6 | @echo $ $ 7 | @echo $ $ 8 | @echo $ Nepxion Studio All Right Reserved $ 9 | @echo $ Copyright (C) 2017-2050 $ 10 | @echo $ $ 11 | @echo ============================================================= 12 | @echo. 13 | @echo off 14 | 15 | @title Nepxion Skeleton 16 | @color 0a 17 | 18 | call mvn clean deploy -DskipTests -e -P release -pl skeleton-starter -am 19 | 20 | pause -------------------------------------------------------------------------------- /install-docker.bat: -------------------------------------------------------------------------------- 1 | @echo on 2 | @echo ============================================================= 3 | @echo $ $ 4 | @echo $ Nepxion Skeleton $ 5 | @echo $ $ 6 | @echo $ $ 7 | @echo $ $ 8 | @echo $ Nepxion Studio All Right Reserved $ 9 | @echo $ Copyright (C) 2017-2050 $ 10 | @echo $ $ 11 | @echo ============================================================= 12 | @echo. 13 | @echo off 14 | 15 | @title Nepxion Skeleton 16 | @color 0a 17 | 18 | @set PROJECT_NAME=skeleton-service 19 | 20 | @set DOCKER_HOST=tcp://localhost:2375 21 | @rem @set DOCKER_CERT_PATH=C:\Users\Neptune\.docker\machine\certs 22 | @set IMAGE_NAME=skeleton-service 23 | @set MACHINE_PORT=2222 24 | @set CONTAINER_PORT=2222 25 | @set RUN_MODE=-i -t 26 | @rem @set RUN_MODE=-d 27 | 28 | if exist %PROJECT_NAME%\target rmdir /s/q %PROJECT_NAME%\target 29 | 30 | @rem 执行相关模块的Maven Install 31 | call mvn clean install -DskipTests -pl %PROJECT_NAME% -am 32 | 33 | @rem 停止和删除Docker容器 34 | call docker stop %IMAGE_NAME% 35 | @rem call docker kill %IMAGE_NAME% 36 | call docker rm %IMAGE_NAME% 37 | 38 | @rem 删除Docker镜像 39 | call docker rmi %IMAGE_NAME% 40 | 41 | cd %PROJECT_NAME% 42 | 43 | @rem 安装Docker镜像 44 | call mvn package docker:build -DskipTests -DImageName=%IMAGE_NAME% -DExposePort=%CONTAINER_PORT% 45 | 46 | @rem 安装和启动Docker容器,并自动执行端口映射 47 | call docker run %RUN_MODE% -p %MACHINE_PORT%:%CONTAINER_PORT% -h %IMAGE_NAME% --name %IMAGE_NAME% %IMAGE_NAME%:latest 48 | 49 | pause -------------------------------------------------------------------------------- /install-docker.sh: -------------------------------------------------------------------------------- 1 | echo 'on' 2 | echo '=============================================================' 3 | echo '$ $' 4 | echo '$ Nepxion Skeleton $' 5 | echo '$ $' 6 | echo '$ $' 7 | echo '$ $' 8 | echo '$ Nepxion Studio All Right Reserved $' 9 | echo '$ Copyright (C) 2017-2050 $' 10 | echo '$ $' 11 | echo '=============================================================' 12 | echo '.' 13 | echo 'off' 14 | 15 | title=Nepxion Skeleton 16 | color=0a 17 | 18 | PROJECT_NAME=skeleton-service 19 | 20 | DOCKER_HOST=tcp://localhost:2375 21 | # DOCKER_CERT_PATH=/User/Neptune/.docker/machine/certs 22 | IMAGE_NAME=skeleton-service 23 | MACHINE_PORT=2222 24 | CONTAINER_PORT=2222 25 | RUN_MODE=-i -t 26 | # RUN_MODE=-d 27 | 28 | if [ ! -d ${PROJECT_NAME}/target];then 29 | rmdir /s/q ${PROJECT_NAME}/target 30 | fi 31 | 32 | # 执行相关模块的Maven Install 33 | mvn clean install -DskipTests -pl ${PROJECT_NAME} -am 34 | 35 | # 停止和删除Docker容器 36 | docker stop ${IMAGE_NAME} 37 | # docker kill ${IMAGE_NAME} 38 | docker rm ${IMAGE_NAME} 39 | 40 | # 删除Docker镜像 41 | docker rmi ${IMAGE_NAME} 42 | 43 | cd ${PROJECT_NAME} 44 | 45 | # 安装Docker镜像 46 | mvn package docker:build -DskipTests -DImageName=${IMAGE_NAME} -DExposePort=${CONTAINER_PORT} 47 | 48 | # 安装和启动Docker容器,并自动执行端口映射 49 | docker run ${RUN_MODE} -p ${MACHINE_PORT}:${CONTAINER_PORT} -h ${IMAGE_NAME} --name ${IMAGE_NAME} ${IMAGE_NAME}:latest -------------------------------------------------------------------------------- /install.bat: -------------------------------------------------------------------------------- 1 | @echo on 2 | @echo ============================================================= 3 | @echo $ $ 4 | @echo $ Nepxion Skeleton $ 5 | @echo $ $ 6 | @echo $ $ 7 | @echo $ $ 8 | @echo $ Nepxion Studio All Right Reserved $ 9 | @echo $ Copyright (C) 2017-2050 $ 10 | @echo $ $ 11 | @echo ============================================================= 12 | @echo. 13 | @echo off 14 | 15 | @title Nepxion Skeleton 16 | @color 0a 17 | 18 | call mvn clean install -DskipTests 19 | 20 | pause -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | echo 'on' 2 | echo '=============================================================' 3 | echo '$ $' 4 | echo '$ Nepxion Skeleton $' 5 | echo '$ $' 6 | echo '$ $' 7 | echo '$ $' 8 | echo '$ Nepxion Studio All Right Reserved $' 9 | echo '$ Copyright (C) 2017-2050 $' 10 | echo '$ $' 11 | echo '=============================================================' 12 | echo '.' 13 | echo 'off' 14 | 15 | title=Nepxion Skeleton 16 | color=0a 17 | 18 | mvn clean install -DskipTests -------------------------------------------------------------------------------- /pmd.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | Exclude noisy rules. 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /skeleton-engine/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | skeleton-engine 5 | Nepxion Skeleton Engine 6 | jar 7 | 4.0.0 8 | Nepxion Skeleton is a generic codes and files generator based on freemaker for any text formats 9 | http://www.nepxion.com 10 | 11 | 12 | com.nepxion 13 | skeleton 14 | 2.2.2 15 | 16 | 17 | 18 | 19 | ${project.groupId} 20 | banner 21 | 22 | 23 | 24 | org.apache.commons 25 | commons-lang3 26 | 27 | 28 | 29 | org.apache.commons 30 | commons-collections4 31 | 32 | 33 | 34 | commons-io 35 | commons-io 36 | 37 | 38 | 39 | org.freemarker 40 | freemarker 41 | 42 | 43 | 44 | org.dom4j 45 | dom4j 46 | 47 | 48 | 49 | net.lingala.zip4j 50 | zip4j 51 | 52 | 53 | -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/config/SkeletonConfig.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.config; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 13 | import com.nepxion.skeleton.engine.model.CharacterCaseModel; 14 | 15 | import freemarker.template.Configuration; 16 | 17 | public class SkeletonConfig extends Configuration { 18 | private String templatePath; 19 | 20 | public SkeletonConfig(String templatePath) { 21 | super(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); 22 | 23 | // 指定模板所在的classpath目录 24 | setClassForTemplateLoading(SkeletonConfig.class, templatePath); 25 | 26 | // 指定文件编码 27 | setDefaultEncoding(SkeletonConstant.ENCODING_UTF_8); 28 | 29 | // 添加一个“宏”共享变量,用来将属性名首字母大写 30 | setSharedVariable(SkeletonConstant.UPPER_CASE, new CharacterCaseModel(true)); 31 | 32 | // 添加一个“宏”共享变量,用来将属性名首字母小写 33 | setSharedVariable(SkeletonConstant.LOWER_CASE, new CharacterCaseModel(false)); 34 | 35 | this.templatePath = templatePath; 36 | } 37 | 38 | public String getTemplatePath() { 39 | return templatePath; 40 | } 41 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/constant/SkeletonConstant.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.constant; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | public class SkeletonConstant { 13 | public static final String SKELETON_VERSION = "2.2.2"; 14 | 15 | public static final String HTTP = "http://"; 16 | public static final String FILE_SEPARATOR = "/"; // File.separator 17 | public static final String FILE_ZIP = "zip"; 18 | 19 | public static final String ENCODING_UTF_8 = "UTF-8"; 20 | public static final String ENCODING_GBK = "GBK"; 21 | public static final String ENCODING_ISO_8859_1 = "ISO-8859-1"; 22 | 23 | public static final String SKELETON = "skeleton"; 24 | public static final String SKELETON_ENABLED = "skeleton.enabled"; 25 | 26 | public static final String UPPER_CASE = "upperCase"; 27 | public static final String LOWER_CASE = "lowerCase"; 28 | 29 | public static final String GROUP = "group"; 30 | public static final String KEY = "key"; 31 | public static final String LABEL = "label"; 32 | public static final String DESCRIPTION = "description"; 33 | public static final String NOTE = "note"; 34 | public static final String LAYOUT = "layout"; 35 | public static final String TITLED_BORDER = "titledBorder"; 36 | 37 | public static final String ENTITY = "entity"; 38 | public static final String TYPE = "type"; 39 | public static final String OPTIONS = "options"; 40 | public static final String HIGHLIGHTABLE = "highlightable"; 41 | public static final String DEFAULTABLE = "defaultable"; 42 | public static final String EMPTIABLE = "emptiable"; 43 | public static final String EDITABLE = "editable"; 44 | 45 | public static final String TITLE = "title"; 46 | public static final String COPYRIGHT = "copyright"; 47 | public static final String COMPANY = "company"; 48 | public static final String AUTHOR = "author"; 49 | public static final String EMAIL = "email"; 50 | public static final String VERSION = "version"; 51 | 52 | public static final String POM_ARTIFACT_ID = "pomArtifactId"; 53 | public static final String PACKAGE = "package"; 54 | public static final String BASE_PACKAGE = "basePackage"; 55 | public static final String TOP_BASE_PACKAGE = "topBasePackage"; 56 | public static final String CLASS_NAME = "className"; 57 | public static final String CLASS_PATH = "classPath"; 58 | 59 | public static final String JAVA = "java"; 60 | public static final String RESOURCES = "resources"; 61 | public static final String DOCKER = "docker"; 62 | public static final String ROOT = ""; 63 | public static final String META_INF = "META-INF"; 64 | 65 | public static final String MAIN_JAVA_CODE_PATH = "src" + FILE_SEPARATOR + "main" + FILE_SEPARATOR + "java" + FILE_SEPARATOR; 66 | public static final String MAIN_RESOURCES_FILE_PATH = "src" + FILE_SEPARATOR + "main" + FILE_SEPARATOR + "resources" + FILE_SEPARATOR; 67 | public static final String MAIN_DOCKER_CODE_PATH = "src" + FILE_SEPARATOR + "main" + FILE_SEPARATOR + "docker" + FILE_SEPARATOR; 68 | public static final String TEST_JAVA_CODE_PATH = "src" + FILE_SEPARATOR + "test" + FILE_SEPARATOR + "java" + FILE_SEPARATOR; 69 | public static final String TEST_RESOURCES_FILE_PATH = "src" + FILE_SEPARATOR + "test" + FILE_SEPARATOR + "resources" + FILE_SEPARATOR; 70 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/context/SkeletonContext.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.context; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import org.apache.commons.lang3.StringUtils; 13 | 14 | import com.nepxion.skeleton.engine.config.SkeletonConfig; 15 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 16 | import com.nepxion.skeleton.engine.entity.SkeletonFileType; 17 | import com.nepxion.skeleton.engine.util.SkeletonUtil; 18 | 19 | public class SkeletonContext { 20 | private String generatePath; 21 | private String projectType; 22 | 23 | private String prefixTemplatePath; 24 | private String reducedTemplatePath; 25 | private Class generatorClass; 26 | 27 | private String baseTemplatePath; 28 | private SkeletonFileType fileType; 29 | 30 | private SkeletonConfig config; 31 | 32 | public SkeletonContext(String generatePath, String projectType, String prefixTemplatePath, String reducedTemplatePath, Class generatorClass) { 33 | this.generatePath = generatePath; 34 | this.projectType = projectType; 35 | this.prefixTemplatePath = prefixTemplatePath; 36 | this.reducedTemplatePath = reducedTemplatePath; 37 | this.generatorClass = generatorClass; 38 | this.config = new SkeletonConfig(generateTemplatePath()); 39 | } 40 | 41 | public SkeletonContext(String generatePath, String prefixTemplatePath, String reducedTemplatePath) { 42 | this.generatePath = generatePath; 43 | this.prefixTemplatePath = prefixTemplatePath; 44 | this.reducedTemplatePath = reducedTemplatePath; 45 | } 46 | 47 | public SkeletonContext(String generatePath, String projectType, String baseTemplatePath, SkeletonFileType fileType) { 48 | this.generatePath = generatePath; 49 | this.projectType = projectType; 50 | this.baseTemplatePath = baseTemplatePath; 51 | this.fileType = fileType; 52 | this.config = new SkeletonConfig(generateTemplatePath()); 53 | } 54 | 55 | public SkeletonContext(String generatePath, String baseTemplatePath) { 56 | this.generatePath = generatePath; 57 | this.baseTemplatePath = baseTemplatePath; 58 | } 59 | 60 | public String getGeneratePath() { 61 | return generatePath; 62 | } 63 | 64 | public String getProjectType() { 65 | return projectType; 66 | } 67 | 68 | public String getPrefixTemplatePath() { 69 | return prefixTemplatePath; 70 | } 71 | 72 | public String getReducedTemplatePath() { 73 | return reducedTemplatePath; 74 | } 75 | 76 | public Class getGeneratorClass() { 77 | return generatorClass; 78 | } 79 | 80 | public String getBaseTemplatePath() { 81 | return baseTemplatePath; 82 | } 83 | 84 | public SkeletonFileType getFileType() { 85 | return fileType; 86 | } 87 | 88 | public SkeletonConfig getConfig() { 89 | return config; 90 | } 91 | 92 | public SkeletonContext clone(String projectType, Class generatorClass) { 93 | return new SkeletonContext(generatePath, projectType, prefixTemplatePath, reducedTemplatePath, generatorClass); 94 | } 95 | 96 | public SkeletonContext clone(String projectType, SkeletonFileType fileType) { 97 | return new SkeletonContext(generatePath, projectType, baseTemplatePath, fileType); 98 | } 99 | 100 | private String generateTemplatePath() { 101 | if (generatorClass != null) { 102 | return SkeletonConstant.FILE_SEPARATOR + (StringUtils.isNotEmpty(prefixTemplatePath) ? prefixTemplatePath + SkeletonConstant.FILE_SEPARATOR : "") + SkeletonUtil.formatGeneratePath(generatorClass, reducedTemplatePath); 103 | } 104 | 105 | return SkeletonConstant.FILE_SEPARATOR + SkeletonUtil.formatGeneratePath(baseTemplatePath) + (StringUtils.isNotEmpty(projectType) ? projectType : "") + SkeletonConstant.FILE_SEPARATOR + fileType; 106 | } 107 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/entity/SkeletonEntity.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.entity; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.Serializable; 13 | 14 | import org.apache.commons.lang3.builder.EqualsBuilder; 15 | import org.apache.commons.lang3.builder.HashCodeBuilder; 16 | import org.apache.commons.lang3.builder.ToStringBuilder; 17 | import org.apache.commons.lang3.builder.ToStringStyle; 18 | 19 | public class SkeletonEntity implements Serializable { 20 | private static final long serialVersionUID = 4973597750877880158L; 21 | 22 | private String key; 23 | private String label; 24 | private String description; 25 | private String note; 26 | private String value; 27 | private SkeletonEntityType type = SkeletonEntityType.TEXTFIELD; 28 | private String[] options; 29 | private boolean highlightable = false; 30 | private boolean defaultable = false; 31 | private boolean emptiable = false; 32 | private boolean editable = true; 33 | 34 | public String getKey() { 35 | return key; 36 | } 37 | 38 | public void setKey(String key) { 39 | this.key = key; 40 | } 41 | 42 | public String getLabel() { 43 | return label; 44 | } 45 | 46 | public void setLabel(String label) { 47 | this.label = label; 48 | } 49 | 50 | public String getDescription() { 51 | return description; 52 | } 53 | 54 | public void setDescription(String description) { 55 | this.description = description; 56 | } 57 | 58 | public String getNote() { 59 | return note; 60 | } 61 | 62 | public void setNote(String note) { 63 | this.note = note; 64 | } 65 | 66 | public String getValue() { 67 | return value; 68 | } 69 | 70 | public void setValue(String value) { 71 | this.value = value; 72 | } 73 | 74 | public SkeletonEntityType getType() { 75 | return type; 76 | } 77 | 78 | public void setType(SkeletonEntityType type) { 79 | this.type = type; 80 | } 81 | 82 | public String[] getOptions() { 83 | return options; 84 | } 85 | 86 | public void setOptions(String[] options) { 87 | this.options = options; 88 | } 89 | 90 | public boolean isHighlightable() { 91 | return highlightable; 92 | } 93 | 94 | public void setHighlightable(boolean highlightable) { 95 | this.highlightable = highlightable; 96 | } 97 | 98 | public boolean isDefaultable() { 99 | return defaultable; 100 | } 101 | 102 | public void setDefaultable(boolean defaultable) { 103 | this.defaultable = defaultable; 104 | } 105 | 106 | public boolean isEmptiable() { 107 | return emptiable; 108 | } 109 | 110 | public void setEmptiable(boolean emptiable) { 111 | this.emptiable = emptiable; 112 | } 113 | 114 | public boolean isEditable() { 115 | return editable; 116 | } 117 | 118 | public void setEditable(boolean editable) { 119 | this.editable = editable; 120 | } 121 | 122 | @Override 123 | public int hashCode() { 124 | return HashCodeBuilder.reflectionHashCode(this); 125 | } 126 | 127 | @Override 128 | public boolean equals(Object object) { 129 | return EqualsBuilder.reflectionEquals(this, object); 130 | } 131 | 132 | @Override 133 | public String toString() { 134 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); 135 | } 136 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/entity/SkeletonEntityType.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.entity; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | public enum SkeletonEntityType { 13 | TEXTFIELD("TEXTFIELD"), 14 | TOGGLEBUTTON("TOGGLEBUTTON"), 15 | CHECKBOX("CHECKBOX"), 16 | RADIO("RADIO"), 17 | COMBOBOX("COMBOBOX"), 18 | EDITABLE_COMBOBOX("EDITABLE_COMBOBOX"); 19 | 20 | private String value; 21 | 22 | private SkeletonEntityType(String value) { 23 | this.value = value; 24 | } 25 | 26 | public String getValue() { 27 | return value; 28 | } 29 | 30 | public static SkeletonEntityType fromString(String value) { 31 | for (SkeletonEntityType type : SkeletonEntityType.values()) { 32 | if (type.getValue().equalsIgnoreCase(value.trim())) { 33 | return type; 34 | } 35 | } 36 | 37 | throw new IllegalArgumentException("Mismatched type with value=" + value); 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return value; 43 | } 44 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/entity/SkeletonFileType.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.entity; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 13 | 14 | public enum SkeletonFileType { 15 | JAVA(SkeletonConstant.JAVA), 16 | RESOURCES(SkeletonConstant.RESOURCES), 17 | DOCKER(SkeletonConstant.DOCKER), 18 | ROOT(SkeletonConstant.ROOT); 19 | 20 | private String value; 21 | 22 | private SkeletonFileType(String value) { 23 | this.value = value; 24 | } 25 | 26 | public String getValue() { 27 | return value; 28 | } 29 | 30 | public static SkeletonFileType fromString(String value) { 31 | for (SkeletonFileType type : SkeletonFileType.values()) { 32 | if (type.getValue().equalsIgnoreCase(value.trim())) { 33 | return type; 34 | } 35 | } 36 | 37 | throw new IllegalArgumentException("Mismatched type with value=" + value); 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return value; 43 | } 44 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/entity/SkeletonGroup.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.entity; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.Serializable; 13 | import java.util.List; 14 | 15 | import org.apache.commons.lang3.builder.EqualsBuilder; 16 | import org.apache.commons.lang3.builder.HashCodeBuilder; 17 | import org.apache.commons.lang3.builder.ToStringBuilder; 18 | import org.apache.commons.lang3.builder.ToStringStyle; 19 | 20 | public class SkeletonGroup implements Serializable { 21 | private static final long serialVersionUID = -7892454279861098493L; 22 | 23 | private String key; 24 | private String label; 25 | private String description; 26 | private SkeletonGroupType type = SkeletonGroupType.MIX_GROUP; 27 | private SkeletonGroupLayoutType layoutType = SkeletonGroupLayoutType.VERTICAL; 28 | private boolean titledBorder = true; 29 | 30 | private List entityList; 31 | 32 | public String getKey() { 33 | return key; 34 | } 35 | 36 | public void setKey(String key) { 37 | this.key = key; 38 | } 39 | 40 | public String getLabel() { 41 | return label; 42 | } 43 | 44 | public void setLabel(String label) { 45 | this.label = label; 46 | } 47 | 48 | public String getDescription() { 49 | return description; 50 | } 51 | 52 | public void setDescription(String description) { 53 | this.description = description; 54 | } 55 | 56 | public SkeletonGroupType getType() { 57 | return type; 58 | } 59 | 60 | public void setType(SkeletonGroupType type) { 61 | this.type = type; 62 | } 63 | 64 | public SkeletonGroupLayoutType getLayoutType() { 65 | return layoutType; 66 | } 67 | 68 | public void setLayoutType(SkeletonGroupLayoutType layoutType) { 69 | this.layoutType = layoutType; 70 | } 71 | 72 | public List getEntityList() { 73 | return entityList; 74 | } 75 | 76 | public void setEntityList(List entityList) { 77 | this.entityList = entityList; 78 | } 79 | 80 | public boolean isTitledBorder() { 81 | return titledBorder; 82 | } 83 | 84 | public void setTitledBorder(boolean titledBorder) { 85 | this.titledBorder = titledBorder; 86 | } 87 | 88 | @Override 89 | public int hashCode() { 90 | return HashCodeBuilder.reflectionHashCode(this); 91 | } 92 | 93 | @Override 94 | public boolean equals(Object object) { 95 | return EqualsBuilder.reflectionEquals(this, object); 96 | } 97 | 98 | @Override 99 | public String toString() { 100 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); 101 | } 102 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/entity/SkeletonGroupLayoutType.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.entity; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | public enum SkeletonGroupLayoutType { 13 | VERTICAL("VERTICAL"), 14 | HORIZONTAL("HORIZONTAL"); 15 | 16 | private String value; 17 | 18 | private SkeletonGroupLayoutType(String value) { 19 | this.value = value; 20 | } 21 | 22 | public String getValue() { 23 | return value; 24 | } 25 | 26 | public static SkeletonGroupLayoutType fromString(String value) { 27 | for (SkeletonGroupLayoutType type : SkeletonGroupLayoutType.values()) { 28 | if (type.getValue().equalsIgnoreCase(value.trim())) { 29 | return type; 30 | } 31 | } 32 | 33 | throw new IllegalArgumentException("Mismatched type with value=" + value); 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return value; 39 | } 40 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/entity/SkeletonGroupType.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.entity; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | public enum SkeletonGroupType { 13 | MIX_GROUP("MIX_GROUP"), 14 | CHECKBOX_GROUP("CHECKBOX_GROUP"), 15 | RADIO_GROUP("RADIO_GROUP"), 16 | COMBOBOX_GROUP("COMBOBOX_GROUP"); 17 | 18 | private String value; 19 | 20 | private SkeletonGroupType(String value) { 21 | this.value = value; 22 | } 23 | 24 | public String getValue() { 25 | return value; 26 | } 27 | 28 | public static SkeletonGroupType fromString(String value) { 29 | for (SkeletonGroupType type : SkeletonGroupType.values()) { 30 | if (type.getValue().equalsIgnoreCase(value.trim())) { 31 | return type; 32 | } 33 | } 34 | 35 | throw new IllegalArgumentException("Mismatched type with value=" + value); 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return value; 41 | } 42 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/exception/SkeletonException.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.exception; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | public class SkeletonException extends RuntimeException { 13 | private static final long serialVersionUID = 8031213882044757635L; 14 | 15 | public SkeletonException() { 16 | super(); 17 | } 18 | 19 | public SkeletonException(String message) { 20 | super(message); 21 | } 22 | 23 | public SkeletonException(String message, Throwable cause) { 24 | super(message, cause); 25 | } 26 | 27 | public SkeletonException(Throwable cause) { 28 | super(cause); 29 | } 30 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/generator/AbstractSkeletonGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.generator; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.File; 13 | import java.io.FileOutputStream; 14 | import java.io.IOException; 15 | import java.io.OutputStreamWriter; 16 | 17 | import org.apache.commons.io.IOUtils; 18 | 19 | import com.nepxion.skeleton.engine.config.SkeletonConfig; 20 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 21 | import com.nepxion.skeleton.engine.context.SkeletonContext; 22 | import com.nepxion.skeleton.engine.entity.SkeletonFileType; 23 | import com.nepxion.skeleton.engine.exception.SkeletonException; 24 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 25 | 26 | import freemarker.template.Template; 27 | import freemarker.template.TemplateException; 28 | 29 | public abstract class AbstractSkeletonGenerator { 30 | protected SkeletonContext skeletonContext; 31 | protected SkeletonProperties skeletonProperties; 32 | 33 | public AbstractSkeletonGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 34 | this.skeletonContext = skeletonContext; 35 | this.skeletonProperties = skeletonProperties; 36 | } 37 | 38 | public AbstractSkeletonGenerator(String generatePath, String projectType, String prefixTemplatePath, String reducedTemplatePath, Class generatorClass, SkeletonProperties skeletonProperties) { 39 | this(new SkeletonContext(generatePath, projectType, prefixTemplatePath, reducedTemplatePath, generatorClass), skeletonProperties); 40 | } 41 | 42 | public AbstractSkeletonGenerator(String generatePath, String projectType, String baseTemplatePath, SkeletonFileType fileType, SkeletonProperties skeletonProperties) { 43 | this(new SkeletonContext(generatePath, projectType, baseTemplatePath, fileType), skeletonProperties); 44 | } 45 | 46 | public SkeletonContext getSkeletonContext() { 47 | return skeletonContext; 48 | } 49 | 50 | public SkeletonProperties getSkeletonProperties() { 51 | return skeletonProperties; 52 | } 53 | 54 | public Template getTemplate() throws IOException { 55 | SkeletonConfig skeletonConfig = skeletonContext.getConfig(); 56 | String templateName = getTemplateName(); 57 | 58 | return skeletonConfig.getTemplate(templateName); 59 | } 60 | 61 | public String getFullTemplatePath() { 62 | SkeletonConfig skeletonConfig = skeletonContext.getConfig(); 63 | String templatePath = skeletonConfig.getTemplatePath(); 64 | String templateName = getTemplateName(); 65 | String fullTemplatePath = templatePath.endsWith(SkeletonConstant.FILE_SEPARATOR) ? templatePath + templateName : templatePath + SkeletonConstant.FILE_SEPARATOR + templateName; 66 | 67 | return fullTemplatePath; 68 | } 69 | 70 | public void generate() throws SkeletonException, TemplateException, IOException { 71 | String path = getPath(); 72 | 73 | File file = new File(path); 74 | generate(file); 75 | } 76 | 77 | public void generate(File file) throws SkeletonException, TemplateException, IOException { 78 | Template template = getTemplate(); 79 | Object dataModel = null; 80 | try { 81 | dataModel = getDataModel(); 82 | } catch (Exception e) { 83 | throw new SkeletonException(e.getMessage(), e); 84 | } 85 | 86 | generate(file, template, dataModel); 87 | } 88 | 89 | public void generate(File file, Template template, Object dataModel) throws TemplateException, IOException { 90 | String filePath = file.getCanonicalPath(); 91 | filePath = filePath.replace("\\", SkeletonConstant.FILE_SEPARATOR); 92 | String directoryPath = filePath.substring(0, filePath.lastIndexOf(SkeletonConstant.FILE_SEPARATOR)); 93 | 94 | File directory = new File(directoryPath); 95 | if (!directory.exists() || !directory.isDirectory()) { 96 | directory.mkdirs(); 97 | } 98 | 99 | FileOutputStream outputStream = null; 100 | OutputStreamWriter outputStreamWriter = null; 101 | try { 102 | outputStream = new FileOutputStream(file); 103 | 104 | outputStreamWriter = new OutputStreamWriter(outputStream, SkeletonConstant.ENCODING_UTF_8); 105 | template.process(dataModel, outputStreamWriter); 106 | } catch (TemplateException e) { 107 | throw e; 108 | } catch (IOException e) { 109 | throw e; 110 | } finally { 111 | if (outputStreamWriter != null) { 112 | IOUtils.closeQuietly(outputStreamWriter); 113 | } 114 | 115 | if (outputStream != null) { 116 | outputStream.flush(); 117 | IOUtils.closeQuietly(outputStream); 118 | } 119 | } 120 | } 121 | 122 | protected abstract String getTemplateName(); 123 | 124 | protected abstract String getPath() throws SkeletonException; 125 | 126 | protected abstract Object getDataModel(); 127 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/generator/SkeletonFileGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.generator; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import org.apache.commons.lang3.StringUtils; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | import com.nepxion.skeleton.engine.context.SkeletonContext; 17 | import com.nepxion.skeleton.engine.entity.SkeletonFileType; 18 | import com.nepxion.skeleton.engine.exception.SkeletonException; 19 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 20 | import com.nepxion.skeleton.engine.util.SkeletonUtil; 21 | 22 | public abstract class SkeletonFileGenerator extends AbstractSkeletonGenerator { 23 | private static final Logger LOG = LoggerFactory.getLogger(SkeletonFileGenerator.class); 24 | 25 | protected String defaultOutputPath; 26 | 27 | public SkeletonFileGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 28 | super(skeletonContext, skeletonProperties); 29 | 30 | initialize(); 31 | } 32 | 33 | public SkeletonFileGenerator(String generatePath, String projectType, String prefixTemplatePath, String reducedTemplatePath, Class generatorClass, SkeletonProperties skeletonProperties) { 34 | super(generatePath, projectType, prefixTemplatePath, reducedTemplatePath, generatorClass, skeletonProperties); 35 | 36 | initialize(); 37 | } 38 | 39 | public SkeletonFileGenerator(String generatePath, String projectType, String baseTemplatePath, SkeletonFileType fileType, SkeletonProperties skeletonProperties) { 40 | super(generatePath, projectType, baseTemplatePath, fileType, skeletonProperties); 41 | 42 | initialize(); 43 | } 44 | 45 | private void initialize() { 46 | // SkeletonFileType fileType = skeletonContext.getFileType(); 47 | // if (fileType != null && fileType == SkeletonFileType.JAVA) { 48 | // throw new SkeletonException("Invalid file type for " + fileType); 49 | // } 50 | 51 | String generatePath = skeletonContext.getGeneratePath(); 52 | String projectType = skeletonContext.getProjectType(); 53 | 54 | defaultOutputPath = SkeletonUtil.getOutputPath(generatePath, projectType, skeletonProperties); 55 | } 56 | 57 | public String getDefaultOutputPath() { 58 | return defaultOutputPath; 59 | } 60 | 61 | @Override 62 | protected String getPath() throws SkeletonException { 63 | String fileName = null; 64 | String outputPath = null; 65 | Object dataModel = null; 66 | 67 | try { 68 | fileName = getFileName(); 69 | outputPath = getOutputPath(); 70 | dataModel = getDataModel(); 71 | } catch (Exception e) { 72 | throw new SkeletonException(e.getMessage(), e); 73 | } 74 | 75 | String fullTemplatePath = getFullTemplatePath(); 76 | String fullOutputPath = SkeletonUtil.formatGeneratePath(outputPath) + fileName; 77 | 78 | LOG.debug("--------------- File Generator Information ---------------"); 79 | LOG.debug("Template Path : {}", fullTemplatePath); 80 | LOG.debug("Output Path : {}", fullOutputPath); 81 | LOG.debug("Data Model : {}", dataModel); 82 | LOG.debug("----------------------------------------------------------"); 83 | 84 | return fullOutputPath; 85 | } 86 | 87 | protected String getOutputPath() { 88 | if (StringUtils.isEmpty(defaultOutputPath)) { 89 | throw new IllegalArgumentException("Default output path is null or empty"); 90 | } 91 | 92 | return defaultOutputPath; 93 | } 94 | 95 | protected abstract String getFileName(); 96 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/model/CharacterCaseModel.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.model; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.IOException; 13 | import java.util.Map; 14 | 15 | import freemarker.core.Environment; 16 | import freemarker.template.TemplateDirectiveBody; 17 | import freemarker.template.TemplateDirectiveModel; 18 | import freemarker.template.TemplateException; 19 | import freemarker.template.TemplateModel; 20 | import freemarker.template.TemplateModelException; 21 | 22 | public class CharacterCaseModel implements TemplateDirectiveModel { 23 | private boolean upperCase = true; 24 | 25 | public CharacterCaseModel(boolean upperCase) { 26 | this.upperCase = upperCase; 27 | } 28 | 29 | @SuppressWarnings("rawtypes") 30 | @Override 31 | public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { 32 | if (!params.isEmpty()) { 33 | throw new TemplateModelException("Params should be empty"); 34 | } 35 | 36 | if (loopVars.length != 0) { 37 | throw new TemplateModelException("LoopVars should be empty"); 38 | } 39 | 40 | if (body == null) { 41 | throw new TemplateModelException("Body can't be null"); 42 | } 43 | 44 | body.render(new CharacterCaseWriter(env.getOut(), upperCase)); 45 | } 46 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/model/CharacterCaseWriter.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.model; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.IOException; 13 | import java.io.Writer; 14 | 15 | public class CharacterCaseWriter extends Writer { 16 | private Writer out; 17 | private boolean upperCase = true; 18 | 19 | public CharacterCaseWriter(Writer out, boolean upperCase) { 20 | this.out = out; 21 | this.upperCase = upperCase; 22 | } 23 | 24 | @Override 25 | public void write(char[] cbuf, int off, int len) throws IOException { 26 | if (upperCase) { 27 | cbuf[0] = Character.toUpperCase(cbuf[0]); 28 | } else { 29 | cbuf[0] = Character.toLowerCase(cbuf[0]); 30 | } 31 | 32 | out.write(String.valueOf(cbuf).trim()); 33 | } 34 | 35 | @Override 36 | public void flush() throws IOException { 37 | out.flush(); 38 | } 39 | 40 | @Override 41 | public void close() throws IOException { 42 | out.close(); 43 | } 44 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/property/SkeletonContent.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.property; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.File; 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | 16 | import org.apache.commons.io.FileUtils; 17 | import org.apache.commons.io.IOUtils; 18 | 19 | import com.nepxion.skeleton.engine.util.IOUtil; 20 | 21 | public class SkeletonContent { 22 | private String content; 23 | 24 | public SkeletonContent(String path, String encoding) throws IOException { 25 | InputStream inputStream = null; 26 | try { 27 | inputStream = IOUtil.getInputStream(path); 28 | this.content = IOUtils.toString(inputStream, encoding); 29 | } finally { 30 | if (inputStream != null) { 31 | IOUtils.closeQuietly(inputStream); 32 | } 33 | } 34 | } 35 | 36 | public SkeletonContent(File file, String encoding) throws IOException { 37 | this.content = FileUtils.readFileToString(file, encoding); 38 | } 39 | 40 | public SkeletonContent(StringBuilder stringBuilder) throws IOException { 41 | this.content = stringBuilder.toString(); 42 | } 43 | 44 | public String getContent() { 45 | return content; 46 | } 47 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/transport/SkeletonConfigTransport.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.transport; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.IOException; 13 | import java.io.UnsupportedEncodingException; 14 | import java.net.URLEncoder; 15 | import java.util.List; 16 | 17 | import org.apache.commons.lang3.StringUtils; 18 | import org.dom4j.DocumentException; 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | 22 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 23 | import com.nepxion.skeleton.engine.entity.SkeletonGroup; 24 | import com.nepxion.skeleton.engine.exception.SkeletonException; 25 | import com.nepxion.skeleton.engine.parser.SkeletonXmlParser; 26 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 27 | import com.nepxion.skeleton.engine.util.SkeletonUtil; 28 | 29 | public class SkeletonConfigTransport { 30 | private static final Logger LOG = LoggerFactory.getLogger(SkeletonConfigTransport.class); 31 | 32 | private static final String SKELETON_CONTEXT_FILE = "config/skeleton-context.properties"; 33 | private static final String SKELETON_DATA_FILE = "config/skeleton-data.properties"; 34 | private static final String SKELETON_DESCRIPTION_FILE = "config/skeleton-description.xml"; 35 | 36 | private SkeletonProperties skeletonContextProperties; 37 | private SkeletonProperties skeletonDataProperties; 38 | private SkeletonXmlParser skeletonXmlParser; 39 | 40 | public SkeletonConfigTransport(String skeletonPlugin) { 41 | String plugin = ""; 42 | if (StringUtils.isNotEmpty(skeletonPlugin)) { 43 | plugin = skeletonPlugin + "/"; 44 | } 45 | 46 | try { 47 | skeletonContextProperties = new SkeletonProperties(plugin + SKELETON_CONTEXT_FILE, SkeletonConstant.ENCODING_GBK, SkeletonConstant.ENCODING_UTF_8); 48 | } catch (IOException e) { 49 | LOG.error("Parse context properties failed", e); 50 | throw new SkeletonException("Parse context properties failed", e); 51 | } 52 | 53 | try { 54 | skeletonDataProperties = new SkeletonProperties(plugin + SKELETON_DATA_FILE, SkeletonConstant.ENCODING_GBK, SkeletonConstant.ENCODING_UTF_8); 55 | } catch (IOException e) { 56 | LOG.error("Parse data properties failed", e); 57 | throw new SkeletonException("Parse data properties failed", e); 58 | } 59 | 60 | try { 61 | skeletonXmlParser = new SkeletonXmlParser(skeletonDataProperties); 62 | skeletonXmlParser.parsePath(plugin + SKELETON_DESCRIPTION_FILE, SkeletonConstant.ENCODING_UTF_8); 63 | } catch (IOException e) { 64 | LOG.error("Parse description xml failed", e); 65 | throw new SkeletonException("Parse description xml failed", e); 66 | } catch (DocumentException e) { 67 | LOG.error("Parse description xml failed", e); 68 | throw new SkeletonException("Parse description xml failed", e); 69 | } 70 | } 71 | 72 | public SkeletonProperties getContextProperties() { 73 | return skeletonContextProperties; 74 | } 75 | 76 | public SkeletonProperties getDataProperties() { 77 | return skeletonDataProperties; 78 | } 79 | 80 | public SkeletonXmlParser getXmlParser() { 81 | return skeletonXmlParser; 82 | } 83 | 84 | public SkeletonProperties getProperties(String config) { 85 | if (StringUtils.isEmpty(config)) { 86 | throw new SkeletonException("Config content is null or empty"); 87 | } 88 | 89 | try { 90 | return new SkeletonProperties(config, SkeletonConstant.ENCODING_UTF_8); 91 | } catch (Exception e) { 92 | throw new SkeletonException(e.getMessage(), e); 93 | } 94 | } 95 | 96 | public String getCanonicalFileName(String fileName, SkeletonProperties skeletonProperties) { 97 | if (StringUtils.isEmpty(fileName)) { 98 | throw new SkeletonException("File name is null or empty"); 99 | } 100 | 101 | try { 102 | String canonicalFileName = SkeletonUtil.getCanonicalFileName(fileName, skeletonProperties); 103 | 104 | return URLEncoder.encode(canonicalFileName + ".zip", SkeletonConstant.ENCODING_UTF_8); 105 | } catch (UnsupportedEncodingException e) { 106 | throw new SkeletonException(e.getMessage(), e); 107 | } 108 | } 109 | 110 | public List getMetaData() { 111 | List skeletonGroups = skeletonXmlParser.getSkeletonGroups(); 112 | 113 | LOG.info("Get skeleton meta data for {} groups is executed...", skeletonGroups.size()); 114 | 115 | return skeletonGroups; 116 | } 117 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/transport/SkeletonDataTransport.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.transport; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.File; 13 | import java.util.UUID; 14 | 15 | import org.apache.commons.lang3.StringUtils; 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | 19 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 20 | import com.nepxion.skeleton.engine.exception.SkeletonException; 21 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 22 | import com.nepxion.skeleton.engine.util.FileUtil; 23 | import com.nepxion.skeleton.engine.util.SkeletonUtil; 24 | import com.nepxion.skeleton.engine.util.ZipUtil; 25 | 26 | public abstract class SkeletonDataTransport { 27 | private static final Logger LOG = LoggerFactory.getLogger(SkeletonDataTransport.class); 28 | 29 | public byte[] download(String generatePath, String fileName, SkeletonProperties skeletonProperties) { 30 | if (StringUtils.isEmpty(generatePath)) { 31 | generatePath = SkeletonUtil.getTempGeneratePath(); 32 | } 33 | 34 | if (StringUtils.isEmpty(fileName)) { 35 | throw new SkeletonException("File name is null or empty"); 36 | } 37 | 38 | String canonicalPath = SkeletonUtil.getCanonicalPath(generatePath, fileName, skeletonProperties); 39 | String canonicalFileName = SkeletonUtil.getCanonicalFileName(fileName, skeletonProperties); 40 | 41 | String deletedDirectoryPath = canonicalPath.endsWith(SkeletonConstant.FILE_SEPARATOR) ? canonicalPath + UUID.randomUUID() : canonicalPath + SkeletonConstant.FILE_SEPARATOR + UUID.randomUUID(); 42 | canonicalPath = deletedDirectoryPath + SkeletonConstant.FILE_SEPARATOR + canonicalFileName; 43 | try { 44 | generate(canonicalPath, skeletonProperties); 45 | 46 | String zipFilePath = ZipUtil.zip(canonicalPath, null); 47 | File zipFile = new File(zipFilePath); 48 | 49 | LOG.info("Download skeleton file for " + zipFile.getName() + " is executed"); 50 | 51 | return FileUtil.getBytes(zipFile); 52 | } catch (Exception e) { 53 | throw new SkeletonException(e.getMessage(), e); 54 | } finally { 55 | File directory = new File(deletedDirectoryPath); 56 | 57 | FileUtil.forceDeleteDirectory(directory, 5); 58 | } 59 | } 60 | 61 | public abstract void generate(String generatePath, SkeletonProperties skeletonProperties) throws Exception; 62 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/util/FileUtil.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.util; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.BufferedOutputStream; 13 | import java.io.File; 14 | import java.io.FileInputStream; 15 | import java.io.FileNotFoundException; 16 | import java.io.FileOutputStream; 17 | import java.io.IOException; 18 | import java.io.InputStream; 19 | 20 | import org.apache.commons.io.FileUtils; 21 | import org.apache.commons.io.IOUtils; 22 | 23 | public class FileUtil { 24 | public static void toFile(String text, String directoryPath, String fileName, String encoding) throws IOException { 25 | File directory = new File(directoryPath); 26 | if (!directory.exists() || !directory.isDirectory()) { 27 | directory.mkdirs(); 28 | } 29 | 30 | File file = new File(directoryPath + File.separator + fileName); 31 | FileUtils.writeStringToFile(file, text, encoding); 32 | } 33 | 34 | public static void toFile(byte[] bytes, String directoryPath, String fileName) throws IOException { 35 | File directory = new File(directoryPath); 36 | if (!directory.exists() || !directory.isDirectory()) { 37 | directory.mkdirs(); 38 | } 39 | 40 | BufferedOutputStream bos = null; 41 | FileOutputStream fos = null; 42 | try { 43 | File file = new File(directoryPath + File.separator + fileName); 44 | fos = new FileOutputStream(file); 45 | bos = new BufferedOutputStream(fos); 46 | bos.write(bytes); 47 | } finally { 48 | if (bos != null) { 49 | IOUtils.closeQuietly(bos); 50 | } 51 | if (fos != null) { 52 | IOUtils.closeQuietly(fos); 53 | } 54 | } 55 | } 56 | 57 | public static byte[] fromFile(String directoryPath, String fileName) throws IOException { 58 | File file = new File(directoryPath + File.separator + fileName); 59 | 60 | return FileUtils.readFileToByteArray(file); 61 | } 62 | 63 | public static void forceDeleteDirectory(File directory, int forceTimes) { 64 | if (directory.isDirectory() && directory.exists()) { 65 | try { 66 | FileUtils.deleteDirectory(directory); 67 | forceTimes--; 68 | if (forceTimes > 0) { 69 | forceDeleteDirectory(directory, forceTimes); 70 | } else { 71 | throw new IOException("Force delete directory=" + directory + " failed"); 72 | } 73 | } catch (IOException e) { 74 | 75 | } 76 | } 77 | } 78 | 79 | public static void forceDeleteFile(File file, int forceTimes) { 80 | if (file.isFile() && file.exists()) { 81 | try { 82 | FileUtils.deleteQuietly(file); 83 | forceTimes--; 84 | if (forceTimes > 0) { 85 | forceDeleteFile(file, forceTimes); 86 | } else { 87 | throw new IOException("Force delete file=" + file + " failed"); 88 | } 89 | } catch (IOException e) { 90 | 91 | } 92 | } 93 | } 94 | 95 | public static byte[] getBytes(File file) throws FileNotFoundException, IOException { 96 | InputStream inputStream = null; 97 | try { 98 | inputStream = new FileInputStream(file); 99 | 100 | return IOUtils.toByteArray(inputStream); 101 | } catch (FileNotFoundException e) { 102 | throw e; 103 | } catch (IOException e) { 104 | throw e; 105 | } finally { 106 | if (inputStream != null) { 107 | IOUtils.closeQuietly(inputStream); 108 | } 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/util/IOUtil.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.util; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.FileInputStream; 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | 16 | public class IOUtil { 17 | public static InputStream getInputStream(String path) throws IOException { 18 | // 从Resource路径获取 19 | InputStream inputStream = IOUtil.class.getClassLoader().getResourceAsStream(path); 20 | if (inputStream == null) { 21 | // 从文件路径获取 22 | inputStream = new FileInputStream(path); 23 | } 24 | 25 | return inputStream; 26 | } 27 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/util/MathsUtil.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.util; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import org.apache.commons.lang3.StringUtils; 13 | 14 | public class MathsUtil { 15 | private static final char ASTERISK = '*'; 16 | 17 | public static Long calculate(String value) { 18 | if (StringUtils.isEmpty(value)) { 19 | return null; 20 | } 21 | 22 | long result = 1; 23 | try { 24 | String[] array = StringUtils.split(value, ASTERISK); 25 | for (String data : array) { 26 | result *= Long.parseLong(data.trim()); 27 | } 28 | } catch (Exception e) { 29 | return null; 30 | } 31 | 32 | return result; 33 | } 34 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/util/SkeletonUtil.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.util; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import org.apache.commons.lang3.StringUtils; 13 | 14 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 15 | import com.nepxion.skeleton.engine.exception.SkeletonException; 16 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 17 | 18 | public class SkeletonUtil { 19 | public static String getOutputPath(String generatePath, SkeletonProperties skeletonProperties) { 20 | return getOutputPath(generatePath, null, skeletonProperties); 21 | } 22 | 23 | public static String getOutputPath(String generatePath, String projectType, SkeletonProperties skeletonProperties) { 24 | return formatGeneratePath(generatePath) + (StringUtils.isNotEmpty(projectType) ? getBaseDirectoryName(projectType, skeletonProperties) + "/" : ""); 25 | } 26 | 27 | public static String getBaseDirectoryName(SkeletonProperties skeletonProperties) { 28 | return getBaseDirectoryName(null, skeletonProperties); 29 | } 30 | 31 | public static String getBaseDirectoryName(String projectType, SkeletonProperties skeletonProperties) { 32 | return skeletonProperties.getString(SkeletonConstant.POM_ARTIFACT_ID) + (StringUtils.isNotEmpty(projectType) ? "-" + projectType : ""); 33 | } 34 | 35 | public static String getBasePackagePath(SkeletonProperties skeletonProperties) { 36 | return getBasePackagePath(null, skeletonProperties); 37 | } 38 | 39 | public static String getBasePackagePath(String projectType, SkeletonProperties skeletonProperties) { 40 | return skeletonProperties.getString(SkeletonConstant.BASE_PACKAGE) + "." + formatProjectName(skeletonProperties.getString(SkeletonConstant.POM_ARTIFACT_ID)) + (StringUtils.isNotEmpty(projectType) ? "." + projectType : ""); 41 | } 42 | 43 | public static String getCanonicalFileName(String fileName, SkeletonProperties skeletonProperties) { 44 | return fileName + "-" + getBaseDirectoryName(skeletonProperties); 45 | } 46 | 47 | public static String getCanonicalPath(String generatePath, String fileName, SkeletonProperties skeletonProperties) { 48 | return formatGeneratePath(generatePath) + getCanonicalFileName(fileName, skeletonProperties); 49 | } 50 | 51 | public static String formatGeneratePath(Class generatorClass, String reducedPath) { 52 | StringBuilder sb = new StringBuilder(); 53 | sb.append(generatorClass.getCanonicalName()); 54 | 55 | String path = sb.toString(); 56 | path = path.substring(0, path.lastIndexOf(".")); 57 | path = path.replace(".", SkeletonConstant.FILE_SEPARATOR); 58 | path += SkeletonConstant.FILE_SEPARATOR; 59 | 60 | if (StringUtils.isNotEmpty(reducedPath)) { 61 | try { 62 | int reducedPathLength = reducedPath.length(); 63 | int pathLength = path.length(); 64 | if (reducedPathLength < pathLength) { 65 | return path.substring(reducedPathLength, pathLength - 1); 66 | } else { 67 | return ""; 68 | } 69 | } catch (Exception e) { 70 | throw new SkeletonException("Path=[" + path + "] doesn't contain reducedPath=[" + reducedPath + "]"); 71 | } 72 | } 73 | 74 | return path; 75 | } 76 | 77 | public static String formatGeneratePath(String generatePath) { 78 | StringBuilder sb = new StringBuilder(); 79 | sb.append(generatePath); 80 | 81 | String path = sb.toString(); 82 | path = path.replace("\\", SkeletonConstant.FILE_SEPARATOR); 83 | if (!path.endsWith(SkeletonConstant.FILE_SEPARATOR)) { 84 | path += SkeletonConstant.FILE_SEPARATOR; 85 | } 86 | 87 | return path; 88 | } 89 | 90 | public static String formatProjectName(String projectName) { 91 | StringBuilder sb = new StringBuilder(); 92 | 93 | String[] array = projectName.split("-"); 94 | for (String text : array) { 95 | sb.append(text.trim()).append("."); 96 | } 97 | 98 | String name = sb.toString(); 99 | 100 | return name.substring(0, name.lastIndexOf(".")); 101 | } 102 | 103 | public static String getTempGeneratePath() { 104 | String tempGeneratePath = formatGeneratePath(System.getProperty("java.io.tmpdir")) + SkeletonConstant.SKELETON; 105 | 106 | return tempGeneratePath; 107 | } 108 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/util/StringUtil.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.util; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.util.List; 15 | 16 | import org.apache.commons.io.IOUtils; 17 | 18 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 19 | 20 | public class StringUtil { 21 | public static String firstLetterToUpper(String value) { 22 | Character character = Character.toUpperCase(value.charAt(0)); 23 | 24 | return character.toString().concat(value.substring(1)); 25 | } 26 | 27 | public static String firstLetterToLower(String value) { 28 | Character character = Character.toLowerCase(value.charAt(0)); 29 | 30 | return character.toString().concat(value.substring(1)); 31 | } 32 | 33 | public static List readLines(String value) throws IOException { 34 | InputStream inputStream = null; 35 | try { 36 | inputStream = IOUtils.toInputStream(value, SkeletonConstant.ENCODING_UTF_8); 37 | return IOUtils.readLines(inputStream, SkeletonConstant.ENCODING_UTF_8); 38 | } finally { 39 | if (inputStream != null) { 40 | IOUtils.closeQuietly(inputStream); 41 | } 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/xml/Dom4JParser.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.xml; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.File; 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | import java.io.Reader; 16 | import java.io.UnsupportedEncodingException; 17 | import java.net.URL; 18 | 19 | import org.apache.commons.io.IOUtils; 20 | import org.dom4j.Document; 21 | import org.dom4j.DocumentException; 22 | import org.dom4j.Element; 23 | import org.xml.sax.InputSource; 24 | 25 | import com.nepxion.skeleton.engine.util.IOUtil; 26 | 27 | public abstract class Dom4JParser { 28 | public void parsePath(String path, String encoding) throws IOException, DocumentException { 29 | InputStream inputStream = null; 30 | try { 31 | inputStream = IOUtil.getInputStream(path); 32 | parse(inputStream, encoding); 33 | } finally { 34 | if (inputStream != null) { 35 | IOUtils.closeQuietly(inputStream); 36 | } 37 | } 38 | } 39 | 40 | public void parse(String text) throws DocumentException { 41 | Document document = Dom4JReader.getDocument(text); 42 | 43 | parse(document); 44 | } 45 | 46 | public void parse(File file, String encoding) throws DocumentException, IOException, UnsupportedEncodingException { 47 | Document document = Dom4JReader.getDocument(file, encoding); 48 | 49 | parse(document); 50 | } 51 | 52 | public void parse(InputStream inputStream, String encoding) throws DocumentException, IOException { 53 | Document document = Dom4JReader.getDocument(inputStream, encoding); 54 | 55 | parse(document); 56 | } 57 | 58 | public void parse(InputSource inputSource, String encoding) throws DocumentException, IOException { 59 | Document document = Dom4JReader.getDocument(inputSource, encoding); 60 | 61 | parse(document); 62 | } 63 | 64 | public void parse(Reader reader, String encoding) throws DocumentException, IOException { 65 | Document document = Dom4JReader.getDocument(reader, encoding); 66 | 67 | parse(document); 68 | } 69 | 70 | public void parse(URL url, String encoding) throws DocumentException, IOException { 71 | Document document = Dom4JReader.getDocument(url, encoding); 72 | 73 | parse(document); 74 | } 75 | 76 | public void parse(Document document) { 77 | Element rootElement = document.getRootElement(); 78 | 79 | parseRoot(rootElement); 80 | } 81 | 82 | protected abstract void parseRoot(Element element); 83 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/xml/Dom4JReader.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.xml; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.File; 13 | import java.io.FileInputStream; 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | import java.io.Reader; 17 | import java.io.UnsupportedEncodingException; 18 | import java.net.URL; 19 | 20 | import org.apache.commons.lang3.StringUtils; 21 | import org.dom4j.Document; 22 | import org.dom4j.DocumentException; 23 | import org.dom4j.DocumentHelper; 24 | import org.dom4j.io.SAXReader; 25 | import org.xml.sax.InputSource; 26 | 27 | public class Dom4JReader { 28 | public static Document getDocument(String text) throws DocumentException { 29 | return DocumentHelper.parseText(text); 30 | } 31 | 32 | public static Document getDocument(File file, String encoding) throws DocumentException, IOException, UnsupportedEncodingException { 33 | InputStream inputStream = new FileInputStream(file); 34 | 35 | return getDocument(inputStream, encoding); 36 | } 37 | 38 | public static Document getDocument(InputStream inputStream, String encoding) throws DocumentException, IOException { 39 | SAXReader saxReader = new SAXReader(); 40 | if (StringUtils.isNotEmpty(encoding)) { 41 | saxReader.setEncoding(encoding); 42 | } 43 | 44 | Document document = null; 45 | try { 46 | document = saxReader.read(inputStream); 47 | } catch (DocumentException e) { 48 | throw e; 49 | } finally { 50 | if (inputStream != null) { 51 | inputStream.close(); 52 | } 53 | } 54 | 55 | return document; 56 | } 57 | 58 | public static Document getDocument(InputSource inputSource, String encoding) throws DocumentException { 59 | inputSource.setEncoding(encoding); 60 | 61 | SAXReader saxReader = new SAXReader(); 62 | if (StringUtils.isNotEmpty(encoding)) { 63 | saxReader.setEncoding(encoding); 64 | } 65 | 66 | return saxReader.read(inputSource); 67 | } 68 | 69 | public static Document getDocument(Reader reader, String encoding) throws DocumentException, IOException { 70 | SAXReader saxReader = new SAXReader(); 71 | if (StringUtils.isNotEmpty(encoding)) { 72 | saxReader.setEncoding(encoding); 73 | } 74 | 75 | Document document = null; 76 | try { 77 | document = saxReader.read(reader); 78 | } catch (DocumentException e) { 79 | throw e; 80 | } finally { 81 | if (reader != null) { 82 | reader.close(); 83 | } 84 | } 85 | 86 | return document; 87 | } 88 | 89 | public static Document getDocument(URL url, String encoding) throws DocumentException { 90 | SAXReader saxReader = new SAXReader(); 91 | if (StringUtils.isNotEmpty(encoding)) { 92 | saxReader.setEncoding(encoding); 93 | } 94 | 95 | return saxReader.read(url); 96 | } 97 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/java/com/nepxion/skeleton/engine/xml/Dom4JWriter.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.engine.xml; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.ByteArrayOutputStream; 13 | import java.io.IOException; 14 | import java.io.UnsupportedEncodingException; 15 | 16 | import org.dom4j.Document; 17 | import org.dom4j.DocumentHelper; 18 | import org.dom4j.io.OutputFormat; 19 | import org.dom4j.io.XMLWriter; 20 | 21 | public class Dom4JWriter { 22 | public static Document createDocument() { 23 | return DocumentHelper.createDocument(); 24 | } 25 | 26 | public static String getText(Document document, String encoding) throws IOException, UnsupportedEncodingException { 27 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 28 | OutputFormat outputFormat = new OutputFormat(" ", true, encoding); 29 | 30 | try { 31 | XMLWriter writer = new XMLWriter(baos, outputFormat); 32 | writer.write(document); 33 | 34 | baos.flush(); 35 | } catch (UnsupportedEncodingException e) { 36 | throw e; 37 | } catch (IOException e) { 38 | throw e; 39 | } finally { 40 | if (baos != null) { 41 | baos.close(); 42 | } 43 | } 44 | 45 | return baos.toString(encoding); 46 | } 47 | } -------------------------------------------------------------------------------- /skeleton-engine/src/main/resources/com/nepxion/skeleton/resource/logo.txt: -------------------------------------------------------------------------------- 1 | ,---. 2 | ' .-' 3 | `. `-. 4 | .-' | 5 | `-----' 6 | ,--. ,--. 7 | | .' / 8 | | . ' 9 | | |\ \ 10 | `--' '--' 11 | ,------. 12 | | .---' 13 | | `--, 14 | | `---. 15 | `------' 16 | ,--. 17 | | | 18 | | | 19 | | '--. 20 | `-----' 21 | ,------. 22 | | .---' 23 | | `--, 24 | | `---. 25 | `------' 26 | ,--------. 27 | '--. .--' 28 | | | 29 | | | 30 | `--' 31 | ,-----. 32 | ' .-. ' 33 | | | | | 34 | ' '-' ' 35 | `-----' 36 | ,--. ,--. 37 | | ,'.| | 38 | | |' ' | 39 | | | ` | 40 | `--' `--' -------------------------------------------------------------------------------- /skeleton-framework/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | skeleton-framework 5 | Nepxion Skeleton Framework 6 | jar 7 | 4.0.0 8 | Nepxion Skeleton is a generic codes and files generator based on freemaker for any text formats 9 | http://www.nepxion.com 10 | 11 | 12 | com.nepxion 13 | skeleton 14 | 2.2.2 15 | 16 | 17 | 18 | 19 | ${project.groupId} 20 | skeleton-engine 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | 29 | io.springfox 30 | springfox-swagger2 31 | 32 | 33 | 34 | io.springfox 35 | springfox-swagger-ui 36 | 37 | 38 | -------------------------------------------------------------------------------- /skeleton-framework/src/main/java/com/nepxion/skeleton/framework/annotation/SkeletonPlugin.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.framework.annotation; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.lang.annotation.Documented; 13 | import java.lang.annotation.ElementType; 14 | import java.lang.annotation.Inherited; 15 | import java.lang.annotation.Retention; 16 | import java.lang.annotation.RetentionPolicy; 17 | import java.lang.annotation.Target; 18 | 19 | @Target({ ElementType.METHOD, ElementType.TYPE }) 20 | @Retention(RetentionPolicy.RUNTIME) 21 | @Inherited 22 | @Documented 23 | public @interface SkeletonPlugin { 24 | String name() default ""; 25 | } -------------------------------------------------------------------------------- /skeleton-framework/src/main/java/com/nepxion/skeleton/framework/aop/SkeletonBeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.framework.aop; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import org.springframework.beans.BeansException; 16 | import org.springframework.beans.factory.config.BeanPostProcessor; 17 | 18 | import com.nepxion.skeleton.engine.exception.SkeletonException; 19 | import com.nepxion.skeleton.framework.annotation.SkeletonPlugin; 20 | 21 | public class SkeletonBeanPostProcessor implements BeanPostProcessor { 22 | private Map skeletonPluginMap = new HashMap(); 23 | 24 | @Override 25 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 26 | return bean; 27 | } 28 | 29 | @Override 30 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 31 | if (bean.getClass().isAnnotationPresent(SkeletonPlugin.class)) { 32 | SkeletonPlugin skeletonPluginAnnotation = bean.getClass().getAnnotation(SkeletonPlugin.class); 33 | String pluginName = skeletonPluginAnnotation.name().trim(); 34 | if (skeletonPluginMap.containsValue(pluginName)) { 35 | throw new SkeletonException("More than one plugin for name=" + pluginName); 36 | } 37 | skeletonPluginMap.put(bean, pluginName); 38 | } 39 | 40 | return bean; 41 | } 42 | 43 | public Map getSkeletonPluginMap() { 44 | return skeletonPluginMap; 45 | } 46 | } -------------------------------------------------------------------------------- /skeleton-framework/src/main/java/com/nepxion/skeleton/framework/configuration/CorsRegistryConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.framework.configuration; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 13 | import org.springframework.context.annotation.Configuration; 14 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 15 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 16 | 17 | @Configuration 18 | @ConditionalOnProperty(value = "cors.registry.enabled", matchIfMissing = false) 19 | public class CorsRegistryConfiguration implements WebMvcConfigurer { 20 | // 解决跨域问题 21 | @Override 22 | public void addCorsMappings(CorsRegistry registry) { 23 | registry.addMapping("/**") 24 | .allowedHeaders("*") 25 | .allowedMethods("*") 26 | .allowedOrigins("*"); 27 | } 28 | } -------------------------------------------------------------------------------- /skeleton-framework/src/main/java/com/nepxion/skeleton/framework/configuration/SkeletonConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.framework.configuration; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.Configuration; 14 | import org.springframework.context.annotation.Import; 15 | 16 | import com.nepxion.skeleton.framework.aop.SkeletonBeanPostProcessor; 17 | import com.nepxion.skeleton.framework.controller.SkeletonController; 18 | 19 | @Configuration 20 | // @ComponentScan(basePackages = { "com.nepxion.skeleton.framework.controller" }) 21 | @Import({ SwaggerConfiguration.class, CorsRegistryConfiguration.class }) 22 | public class SkeletonConfiguration { 23 | @Bean 24 | public SkeletonController skeletonController() { 25 | return new SkeletonController(); 26 | } 27 | 28 | @Bean 29 | public SkeletonBeanPostProcessor skeletonBeanPostProcessor() { 30 | return new SkeletonBeanPostProcessor(); 31 | } 32 | } -------------------------------------------------------------------------------- /skeleton-framework/src/main/java/com/nepxion/skeleton/framework/configuration/SwaggerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.framework.configuration; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import springfox.documentation.builders.ApiInfoBuilder; 13 | import springfox.documentation.builders.PathSelectors; 14 | import springfox.documentation.builders.RequestHandlerSelectors; 15 | import springfox.documentation.service.ApiInfo; 16 | import springfox.documentation.service.Contact; 17 | import springfox.documentation.spi.DocumentationType; 18 | import springfox.documentation.spring.web.plugins.Docket; 19 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 20 | 21 | import org.springframework.beans.factory.annotation.Value; 22 | import org.springframework.context.annotation.Bean; 23 | import org.springframework.context.annotation.Configuration; 24 | 25 | @Configuration 26 | @EnableSwagger2 27 | public class SwaggerConfiguration { 28 | public static final String BASE_PACKAGE = "com.nepxion.skeleton.framework.controller"; 29 | 30 | @Value("${spring.application.name}") 31 | private String serviceName; 32 | 33 | @Value("${swagger.service.description:Skeleton Spring Cloud Restful APIs}") 34 | private String description; 35 | 36 | @Value("${swagger.service.version:1.0.0}") 37 | private String version; 38 | 39 | @Value("${swagger.service.license.name:Apache License 2.0}") 40 | private String license; 41 | 42 | @Value("${swagger.service.license.url:http://www.apache.org/licenses/LICENSE-2.0}") 43 | private String licenseUrl; 44 | 45 | @Value("${swagger.service.contact.name:Haojun Ren}") 46 | private String contactName; 47 | 48 | @Value("${swagger.service.contact.url:https://github.com/Nepxion/Skeleton}") 49 | private String contactUrl; 50 | 51 | @Value("${swagger.service.contact.email:1394997@qq.com}") 52 | private String contactEmail; 53 | 54 | @Value("${swagger.service.termsOfServiceUrl:http://www.nepxion.com}") 55 | private String termsOfServiceUrl; 56 | 57 | @Bean("skeletonDocket") 58 | public Docket createRestApi() { 59 | return new Docket(DocumentationType.SWAGGER_2) 60 | .groupName("skeleton") 61 | .apiInfo(apiInfo()) 62 | .select() 63 | .apis(RequestHandlerSelectors.basePackage(BASE_PACKAGE)) // 扫描该包下的所有需要在Swagger中展示的API,@ApiIgnore注解标注的除外 64 | .paths(PathSelectors.any()) 65 | .build(); 66 | } 67 | 68 | private ApiInfo apiInfo() { 69 | return new ApiInfoBuilder() 70 | .title(serviceName) 71 | .description(description) 72 | .version(version) 73 | .license(license) 74 | .licenseUrl(licenseUrl) 75 | .contact(new Contact(contactName, contactUrl, contactEmail)) 76 | .termsOfServiceUrl(termsOfServiceUrl) 77 | .build(); 78 | } 79 | 80 | } -------------------------------------------------------------------------------- /skeleton-framework/src/main/java/com/nepxion/skeleton/framework/service/SkeletonService.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.framework.service; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.IOException; 13 | 14 | import com.nepxion.skeleton.engine.context.SkeletonContext; 15 | import com.nepxion.skeleton.engine.exception.SkeletonException; 16 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 17 | 18 | import freemarker.template.TemplateException; 19 | 20 | public interface SkeletonService { 21 | void generate(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) throws SkeletonException, TemplateException, IOException; 22 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | skeleton-plugin-springcloud 5 | Nepxion Skeleton Plugin Spring Cloud 6 | jar 7 | 4.0.0 8 | Nepxion Skeleton is a generic codes and files generator based on freemaker for any text formats 9 | http://www.nepxion.com 10 | 11 | 12 | com.nepxion 13 | skeleton 14 | 2.2.2 15 | 16 | 17 | 18 | 19 | ${project.groupId} 20 | skeleton-framework 21 | ${project.version} 22 | 23 | 24 | -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/configuration/SpringCloudPluginConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.configuration; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.Configuration; 14 | 15 | import com.nepxion.skeleton.framework.service.SkeletonService; 16 | import com.nepxion.skeleton.plugin.springcloud.impl.SpringcloudServiceImpl; 17 | 18 | @Configuration 19 | public class SpringCloudPluginConfiguration { 20 | @Bean 21 | public SkeletonService springCloudService() { 22 | return new SpringcloudServiceImpl(); 23 | } 24 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/InstallDockerShellGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import org.apache.commons.lang3.StringUtils; 16 | 17 | import com.nepxion.skeleton.engine.context.SkeletonContext; 18 | import com.nepxion.skeleton.engine.generator.SkeletonFileGenerator; 19 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 20 | import com.nepxion.skeleton.engine.util.SkeletonUtil; 21 | 22 | public class InstallDockerShellGenerator extends SkeletonFileGenerator { 23 | private String subProjectType; 24 | private String shellType; 25 | private String linkDocker; 26 | 27 | public InstallDockerShellGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties, String subProjectType, String shellType, String linkDocker) { 28 | super(skeletonContext.clone(null, InstallDockerShellGenerator.class), skeletonProperties); 29 | 30 | this.subProjectType = subProjectType; 31 | this.shellType = shellType; 32 | this.linkDocker = linkDocker; 33 | } 34 | 35 | @Override 36 | protected String getFileName() { 37 | return "install-" + subProjectType + "-docker." + shellType; 38 | } 39 | 40 | @Override 41 | protected String getTemplateName() { 42 | return "install-docker." + shellType + ".template"; 43 | } 44 | 45 | @Override 46 | protected Object getDataModel() { 47 | Map dataModel = new HashMap(); 48 | dataModel.put("projectName", SkeletonUtil.getBaseDirectoryName(subProjectType, skeletonProperties)); 49 | dataModel.put("dockerHost", skeletonProperties.getString("dockerHost")); 50 | dataModel.put("dockerCertPath", skeletonProperties.getString("dockerCertPath")); 51 | dataModel.put("dockerCertEnabled", skeletonProperties.getString("dockerCertEnabled")); 52 | dataModel.put("dockerType", skeletonProperties.getString("dockerType")); 53 | dataModel.put("imageName", skeletonProperties.getString("serviceName") + "-" + subProjectType); 54 | dataModel.put("port", skeletonProperties.getString(subProjectType + "Port")); 55 | dataModel.put("linkDocker", StringUtils.isNotEmpty(linkDocker) ? linkDocker : ""); 56 | 57 | return dataModel; 58 | } 59 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/PomXmlGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.context.SkeletonContext; 16 | import com.nepxion.skeleton.engine.generator.SkeletonFileGenerator; 17 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 18 | 19 | public class PomXmlGenerator extends SkeletonFileGenerator { 20 | public PomXmlGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 21 | super(skeletonContext.clone(null, PomXmlGenerator.class), skeletonProperties); 22 | } 23 | 24 | @Override 25 | protected String getFileName() { 26 | return "pom.xml"; 27 | } 28 | 29 | @Override 30 | protected String getTemplateName() { 31 | return "pom.xml.template"; 32 | } 33 | 34 | @Override 35 | protected Object getDataModel() { 36 | Map dataModel = new HashMap(); 37 | dataModel.put("pomGroupId", skeletonProperties.getString("pomGroupId")); 38 | dataModel.put("pomArtifactId", skeletonProperties.getString("pomArtifactId")); 39 | dataModel.put("pomName", skeletonProperties.getString("pomName")); 40 | dataModel.put("pomVersion", skeletonProperties.getString("pomVersion")); 41 | dataModel.put("springCloudVersion", skeletonProperties.getString("springCloudVersion")); 42 | dataModel.put("springBootVersion", skeletonProperties.getString("springBootVersion")); 43 | dataModel.put("javaVersion", skeletonProperties.getString("javaVersion")); 44 | dataModel.put("moduleName", skeletonProperties.getString("pomArtifactId")); 45 | 46 | return dataModel; 47 | } 48 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/client/PomXmlGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.client; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.context.SkeletonContext; 16 | import com.nepxion.skeleton.engine.generator.SkeletonFileGenerator; 17 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 18 | import com.nepxion.skeleton.engine.util.SkeletonUtil; 19 | import com.nepxion.skeleton.engine.util.StringUtil; 20 | 21 | public class PomXmlGenerator extends SkeletonFileGenerator { 22 | public PomXmlGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 23 | super(skeletonContext.clone("client", PomXmlGenerator.class), skeletonProperties); 24 | } 25 | 26 | @Override 27 | protected String getFileName() { 28 | return "pom.xml"; 29 | } 30 | 31 | @Override 32 | protected String getTemplateName() { 33 | return "pom.xml.template"; 34 | } 35 | 36 | @Override 37 | protected Object getDataModel() { 38 | Map dataModel = new HashMap(); 39 | dataModel.put("parentPomArtifactId", skeletonProperties.getString("pomArtifactId")); 40 | dataModel.put("pomGroupId", skeletonProperties.getString("pomGroupId")); 41 | dataModel.put("pomArtifactId", skeletonProperties.getString("pomArtifactId") + "-" + getSkeletonContext().getProjectType()); 42 | dataModel.put("pomName", skeletonProperties.getString("pomName") + " " + StringUtil.firstLetterToUpper(getSkeletonContext().getProjectType())); 43 | dataModel.put("pomVersion", skeletonProperties.getString("pomVersion")); 44 | dataModel.put("javaImageVersion", skeletonProperties.getString("javaImageVersion")); 45 | dataModel.put("mainClass", SkeletonUtil.getBasePackagePath(getSkeletonContext().getProjectType(), skeletonProperties) + "." + StringUtil.firstLetterToUpper(getSkeletonContext().getProjectType()) + "Application"); 46 | dataModel.put("clientHystrixEnabled", skeletonProperties.getString("clientHystrixEnabled")); 47 | 48 | return dataModel; 49 | } 50 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/client/java/AbstractClientTestClassGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.client.java; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 16 | import com.nepxion.skeleton.engine.context.SkeletonContext; 17 | import com.nepxion.skeleton.engine.generator.SkeletonJavaGenerator; 18 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 19 | 20 | public class AbstractClientTestClassGenerator extends SkeletonJavaGenerator { 21 | public AbstractClientTestClassGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 22 | super(skeletonContext.clone("client", AbstractClientTestClassGenerator.class), skeletonProperties); 23 | } 24 | 25 | @Override 26 | protected String getPackage() { 27 | return super.getPackage() + ".test"; 28 | } 29 | 30 | @Override 31 | protected String getClassName() { 32 | return "AbstractClientTest"; 33 | } 34 | 35 | @Override 36 | protected String getTemplateName() { 37 | return "AbstractClientTest.java.template"; 38 | } 39 | 40 | @Override 41 | protected boolean isMainCode() { 42 | return true; 43 | } 44 | 45 | @Override 46 | protected Object getDataModel() { 47 | Map dataModel = new HashMap(); 48 | dataModel.put(SkeletonConstant.PACKAGE, getPackage()); 49 | 50 | return dataModel; 51 | } 52 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/client/java/ClientApplicationClassGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.client.java; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 16 | import com.nepxion.skeleton.engine.context.SkeletonContext; 17 | import com.nepxion.skeleton.engine.generator.SkeletonJavaGenerator; 18 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 19 | 20 | public class ClientApplicationClassGenerator extends SkeletonJavaGenerator { 21 | public ClientApplicationClassGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 22 | super(skeletonContext.clone("client", ClientApplicationClassGenerator.class), skeletonProperties); 23 | } 24 | 25 | @Override 26 | protected String getClassName() { 27 | return "ClientApplication"; 28 | } 29 | 30 | @Override 31 | protected String getTemplateName() { 32 | return "ClientApplication.java.template"; 33 | } 34 | 35 | @Override 36 | protected boolean isMainCode() { 37 | return true; 38 | } 39 | 40 | @Override 41 | protected Object getDataModel() { 42 | Map dataModel = new HashMap(); 43 | dataModel.put(SkeletonConstant.PACKAGE, getPackage()); 44 | dataModel.put("clientHystrixEnabled", skeletonProperties.getString("clientHystrixEnabled")); 45 | 46 | return dataModel; 47 | } 48 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/client/java/ClientContextAwareClassGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.client.java; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 16 | import com.nepxion.skeleton.engine.context.SkeletonContext; 17 | import com.nepxion.skeleton.engine.generator.SkeletonJavaGenerator; 18 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 19 | 20 | public class ClientContextAwareClassGenerator extends SkeletonJavaGenerator { 21 | public ClientContextAwareClassGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 22 | super(skeletonContext.clone("client", ClientContextAwareClassGenerator.class), skeletonProperties); 23 | } 24 | 25 | @Override 26 | protected String getPackage() { 27 | return super.getPackage() + ".context"; 28 | } 29 | 30 | @Override 31 | protected String getClassName() { 32 | return "ClientContextAware"; 33 | } 34 | 35 | @Override 36 | protected String getTemplateName() { 37 | return "ClientContextAware.java.template"; 38 | } 39 | 40 | @Override 41 | protected boolean isMainCode() { 42 | return true; 43 | } 44 | 45 | @Override 46 | protected Object getDataModel() { 47 | Map dataModel = new HashMap(); 48 | dataModel.put(SkeletonConstant.PACKAGE, getPackage()); 49 | 50 | return dataModel; 51 | } 52 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/client/java/ClientControllerClassGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.client.java; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 16 | import com.nepxion.skeleton.engine.context.SkeletonContext; 17 | import com.nepxion.skeleton.engine.generator.SkeletonJavaGenerator; 18 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 19 | 20 | public class ClientControllerClassGenerator extends SkeletonJavaGenerator { 21 | public ClientControllerClassGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 22 | super(skeletonContext.clone("client", ClientControllerClassGenerator.class), skeletonProperties); 23 | } 24 | 25 | @Override 26 | protected String getPackage() { 27 | return super.getPackage() + ".controller"; 28 | } 29 | 30 | @Override 31 | protected String getClassName() { 32 | return "ClientController"; 33 | } 34 | 35 | @Override 36 | protected String getTemplateName() { 37 | return "ClientController.java.template"; 38 | } 39 | 40 | @Override 41 | protected boolean isMainCode() { 42 | return true; 43 | } 44 | 45 | @Override 46 | protected Object getDataModel() { 47 | Map dataModel = new HashMap(); 48 | dataModel.put(SkeletonConstant.PACKAGE, getPackage()); 49 | dataModel.put(SkeletonConstant.BASE_PACKAGE, super.getPackage()); 50 | dataModel.put("clientHystrixEnabled", skeletonProperties.getString("clientHystrixEnabled")); 51 | 52 | return dataModel; 53 | } 54 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/client/java/ClientRestTestClassGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.client.java; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 16 | import com.nepxion.skeleton.engine.context.SkeletonContext; 17 | import com.nepxion.skeleton.engine.generator.SkeletonJavaGenerator; 18 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 19 | 20 | public class ClientRestTestClassGenerator extends SkeletonJavaGenerator { 21 | public ClientRestTestClassGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 22 | super(skeletonContext.clone("client", ClientRestTestClassGenerator.class), skeletonProperties); 23 | } 24 | 25 | @Override 26 | protected String getPackage() { 27 | return super.getPackage() + ".test"; 28 | } 29 | 30 | @Override 31 | protected String getClassName() { 32 | return "ClientRestTest"; 33 | } 34 | 35 | @Override 36 | protected String getTemplateName() { 37 | return "ClientRestTest.java.template"; 38 | } 39 | 40 | @Override 41 | protected boolean isMainCode() { 42 | return true; 43 | } 44 | 45 | @Override 46 | protected Object getDataModel() { 47 | Map dataModel = new HashMap(); 48 | dataModel.put(SkeletonConstant.PACKAGE, getPackage()); 49 | dataModel.put(SkeletonConstant.BASE_PACKAGE, super.getPackage()); 50 | dataModel.put("port", skeletonProperties.getString("clientPort")); 51 | 52 | return dataModel; 53 | } 54 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/client/java/ClientRpcTestClassGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.client.java; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 16 | import com.nepxion.skeleton.engine.context.SkeletonContext; 17 | import com.nepxion.skeleton.engine.generator.SkeletonJavaGenerator; 18 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 19 | 20 | public class ClientRpcTestClassGenerator extends SkeletonJavaGenerator { 21 | public ClientRpcTestClassGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 22 | super(skeletonContext.clone("client", ClientRpcTestClassGenerator.class), skeletonProperties); 23 | } 24 | 25 | @Override 26 | protected String getPackage() { 27 | return super.getPackage() + ".test"; 28 | } 29 | 30 | @Override 31 | protected String getClassName() { 32 | return "ClientRpcTest"; 33 | } 34 | 35 | @Override 36 | protected String getTemplateName() { 37 | return "ClientRpcTest.java.template"; 38 | } 39 | 40 | @Override 41 | protected boolean isMainCode() { 42 | return true; 43 | } 44 | 45 | @Override 46 | protected Object getDataModel() { 47 | Map dataModel = new HashMap(); 48 | dataModel.put(SkeletonConstant.PACKAGE, getPackage()); 49 | dataModel.put(SkeletonConstant.BASE_PACKAGE, super.getPackage()); 50 | 51 | return dataModel; 52 | } 53 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/client/java/ClientServiceClassGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.client.java; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 16 | import com.nepxion.skeleton.engine.context.SkeletonContext; 17 | import com.nepxion.skeleton.engine.generator.SkeletonJavaGenerator; 18 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 19 | 20 | public class ClientServiceClassGenerator extends SkeletonJavaGenerator { 21 | public ClientServiceClassGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 22 | super(skeletonContext.clone("client", ClientServiceClassGenerator.class), skeletonProperties); 23 | } 24 | 25 | @Override 26 | protected String getPackage() { 27 | return super.getPackage() + ".service"; 28 | } 29 | 30 | @Override 31 | protected String getClassName() { 32 | return "ClientService"; 33 | } 34 | 35 | @Override 36 | protected String getTemplateName() { 37 | return "ClientService.java.template"; 38 | } 39 | 40 | @Override 41 | protected boolean isMainCode() { 42 | return true; 43 | } 44 | 45 | @Override 46 | protected Object getDataModel() { 47 | Map dataModel = new HashMap(); 48 | dataModel.put(SkeletonConstant.PACKAGE, getPackage()); 49 | 50 | return dataModel; 51 | } 52 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/client/resources/ApplicationPropertiesGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.client.resources; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 16 | import com.nepxion.skeleton.engine.context.SkeletonContext; 17 | import com.nepxion.skeleton.engine.generator.SkeletonFileGenerator; 18 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 19 | 20 | public class ApplicationPropertiesGenerator extends SkeletonFileGenerator { 21 | public ApplicationPropertiesGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 22 | super(skeletonContext.clone("client", ApplicationPropertiesGenerator.class), skeletonProperties); 23 | } 24 | 25 | @Override 26 | protected String getFileName() { 27 | return "application.properties"; 28 | } 29 | 30 | @Override 31 | protected String getTemplateName() { 32 | return "application.properties.template"; 33 | } 34 | 35 | @Override 36 | protected String getOutputPath() { 37 | return super.getOutputPath() + SkeletonConstant.MAIN_RESOURCES_FILE_PATH; 38 | } 39 | 40 | @Override 41 | protected Object getDataModel() { 42 | Map dataModel = new HashMap(); 43 | dataModel.put("serviceName", skeletonProperties.getString("serviceName") + "-" + getSkeletonContext().getProjectType()); 44 | dataModel.put("clusterName", skeletonProperties.getString("serviceName") + "-server"); 45 | dataModel.put("port", skeletonProperties.getString("clientPort")); 46 | dataModel.put("registryUrl", skeletonProperties.getString("registryUrl")); 47 | 48 | return dataModel; 49 | } 50 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/eureka/PomXmlGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.eureka; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.context.SkeletonContext; 16 | import com.nepxion.skeleton.engine.generator.SkeletonFileGenerator; 17 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 18 | import com.nepxion.skeleton.engine.util.SkeletonUtil; 19 | import com.nepxion.skeleton.engine.util.StringUtil; 20 | 21 | public class PomXmlGenerator extends SkeletonFileGenerator { 22 | public PomXmlGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 23 | super(skeletonContext.clone("eureka", PomXmlGenerator.class), skeletonProperties); 24 | } 25 | 26 | @Override 27 | protected String getFileName() { 28 | return "pom.xml"; 29 | } 30 | 31 | @Override 32 | protected String getTemplateName() { 33 | return "pom.xml.template"; 34 | } 35 | 36 | @Override 37 | protected Object getDataModel() { 38 | Map dataModel = new HashMap(); 39 | dataModel.put("parentPomArtifactId", skeletonProperties.getString("pomArtifactId")); 40 | dataModel.put("pomGroupId", skeletonProperties.getString("pomGroupId")); 41 | dataModel.put("pomArtifactId", skeletonProperties.getString("pomArtifactId") + "-" + getSkeletonContext().getProjectType()); 42 | dataModel.put("pomName", skeletonProperties.getString("pomName") + " " + StringUtil.firstLetterToUpper(getSkeletonContext().getProjectType())); 43 | dataModel.put("pomVersion", skeletonProperties.getString("pomVersion")); 44 | dataModel.put("javaImageVersion", skeletonProperties.getString("javaImageVersion")); 45 | dataModel.put("mainClass", SkeletonUtil.getBasePackagePath(getSkeletonContext().getProjectType(), skeletonProperties) + "." + StringUtil.firstLetterToUpper(getSkeletonContext().getProjectType()) + "Application"); 46 | 47 | return dataModel; 48 | } 49 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/eureka/java/EurekaApplicationClassGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.eureka.java; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 16 | import com.nepxion.skeleton.engine.context.SkeletonContext; 17 | import com.nepxion.skeleton.engine.generator.SkeletonJavaGenerator; 18 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 19 | 20 | public class EurekaApplicationClassGenerator extends SkeletonJavaGenerator { 21 | public EurekaApplicationClassGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 22 | super(skeletonContext.clone("eureka", EurekaApplicationClassGenerator.class), skeletonProperties); 23 | } 24 | 25 | @Override 26 | protected String getClassName() { 27 | return "EurekaApplication"; 28 | } 29 | 30 | @Override 31 | protected String getTemplateName() { 32 | return "EurekaApplication.java.template"; 33 | } 34 | 35 | @Override 36 | protected boolean isMainCode() { 37 | return true; 38 | } 39 | 40 | @Override 41 | protected Object getDataModel() { 42 | Map dataModel = new HashMap(); 43 | dataModel.put(SkeletonConstant.PACKAGE, getPackage()); 44 | 45 | return dataModel; 46 | } 47 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/eureka/resources/ApplicationPropertiesGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.eureka.resources; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 16 | import com.nepxion.skeleton.engine.context.SkeletonContext; 17 | import com.nepxion.skeleton.engine.generator.SkeletonFileGenerator; 18 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 19 | 20 | public class ApplicationPropertiesGenerator extends SkeletonFileGenerator { 21 | public ApplicationPropertiesGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 22 | super(skeletonContext.clone("eureka", ApplicationPropertiesGenerator.class), skeletonProperties); 23 | } 24 | 25 | @Override 26 | protected String getFileName() { 27 | return "application.properties"; 28 | } 29 | 30 | @Override 31 | protected String getTemplateName() { 32 | return "application.properties.template"; 33 | } 34 | 35 | @Override 36 | protected String getOutputPath() { 37 | return super.getOutputPath() + SkeletonConstant.MAIN_RESOURCES_FILE_PATH; 38 | } 39 | 40 | @Override 41 | protected Object getDataModel() { 42 | Map dataModel = new HashMap(); 43 | dataModel.put("serviceName", skeletonProperties.getString("serviceName") + "-" + getSkeletonContext().getProjectType()); 44 | dataModel.put("port", skeletonProperties.getString("eurekaPort")); 45 | dataModel.put("registryUrl", skeletonProperties.getString("registryUrl")); 46 | 47 | return dataModel; 48 | } 49 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/server/PomXmlGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.server; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.context.SkeletonContext; 16 | import com.nepxion.skeleton.engine.generator.SkeletonFileGenerator; 17 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 18 | import com.nepxion.skeleton.engine.util.SkeletonUtil; 19 | import com.nepxion.skeleton.engine.util.StringUtil; 20 | 21 | public class PomXmlGenerator extends SkeletonFileGenerator { 22 | public PomXmlGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 23 | super(skeletonContext.clone("server", PomXmlGenerator.class), skeletonProperties); 24 | } 25 | 26 | @Override 27 | protected String getFileName() { 28 | return "pom.xml"; 29 | } 30 | 31 | @Override 32 | protected String getTemplateName() { 33 | return "pom.xml.template"; 34 | } 35 | 36 | @Override 37 | protected Object getDataModel() { 38 | Map dataModel = new HashMap(); 39 | dataModel.put("parentPomArtifactId", skeletonProperties.getString("pomArtifactId")); 40 | dataModel.put("pomGroupId", skeletonProperties.getString("pomGroupId")); 41 | dataModel.put("pomArtifactId", skeletonProperties.getString("pomArtifactId") + "-" + getSkeletonContext().getProjectType()); 42 | dataModel.put("pomName", skeletonProperties.getString("pomName") + " " + StringUtil.firstLetterToUpper(getSkeletonContext().getProjectType())); 43 | dataModel.put("pomVersion", skeletonProperties.getString("pomVersion")); 44 | dataModel.put("javaImageVersion", skeletonProperties.getString("javaImageVersion")); 45 | dataModel.put("mainClass", SkeletonUtil.getBasePackagePath(getSkeletonContext().getProjectType(), skeletonProperties) + "." + StringUtil.firstLetterToUpper(getSkeletonContext().getProjectType()) + "Application"); 46 | 47 | return dataModel; 48 | } 49 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/server/java/ServerApplicationClassGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.server.java; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 16 | import com.nepxion.skeleton.engine.context.SkeletonContext; 17 | import com.nepxion.skeleton.engine.generator.SkeletonJavaGenerator; 18 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 19 | 20 | public class ServerApplicationClassGenerator extends SkeletonJavaGenerator { 21 | /** 22 | * 构造方法 23 | * @param skeletonContext 封装了参数的上下文对象 24 | * @param skeletonProperties 全局配置文件对象 25 | */ 26 | public ServerApplicationClassGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 27 | super(skeletonContext.clone("server", ServerApplicationClassGenerator.class), skeletonProperties); 28 | } 29 | 30 | /** 31 | * 构造方法 32 | * @param generatePath 创建文件的顶级路径 33 | * @param projectType 工程类型 34 | * @param prefixTemplatePath 前置模板路径,例如template 35 | * @param reducedTemplatePath 模板路径缩减,考虑到模板路径和类路径必须一致,会导致路径太长,可以缩减掉一部分 36 | * @param skeletonProperties 全局配置文件对象 37 | */ 38 | /*public ServerApplicationClassGenerator(String generatePath, String projectType, String prefixTemplatePath, String reducedTemplatePath, SkeletonProperties skeletonProperties) { 39 | super(generatePath, projectType, prefixTemplatePath, reducedTemplatePath, ServerApplicationClassGenerator.class, skeletonProperties); 40 | }*/ 41 | 42 | /** 43 | * 构造方法 44 | * @param generatePath 创建文件的顶级路径 45 | * @param projectType 工程类型 46 | * @param baseTemplatePath 模板文件的顶级路径 47 | * @param skeletonProperties 全局配置文件对象 48 | */ 49 | /*public ServerApplicationClassGenerator(String generatePath, String projectType, String baseTemplatePath, SkeletonProperties skeletonProperties) { 50 | super(generatePath, projectType, baseTemplatePath, skeletonProperties); 51 | }*/ 52 | 53 | /** 54 | * 设置Java类的包路径,如果没特殊处理,则按照默认顶级包路径来处理,不需要Override该方法 55 | */ 56 | /*@Override 57 | protected String getPackage() { 58 | return super.getPackage() + "." + "abc"; 59 | }*/ 60 | 61 | /** 62 | * 设置Java类名 63 | */ 64 | @Override 65 | protected String getClassName() { 66 | return "ServerApplication"; 67 | } 68 | 69 | /** 70 | * 设置模板名 71 | */ 72 | @Override 73 | protected String getTemplateName() { 74 | return "ServerApplication.java.template"; 75 | } 76 | 77 | /** 78 | * 设置Java类的输出路径,如果没特殊处理,则按照默认输出路径来处理,不需要Override该方法 79 | */ 80 | /*@Override 81 | protected String getOutputPath() { 82 | return super.getOutputPath() + "/" + "xyz"; 83 | }*/ 84 | 85 | /** 86 | * 设置Java类到main目录下,还是在test目录下 87 | */ 88 | @Override 89 | protected boolean isMainCode() { 90 | return true; 91 | } 92 | 93 | /** 94 | * 设置Java类创建的所依赖数据模型,主要做动态变量到原型模板的替换(任何文本的替换都支持) 95 | */ 96 | @Override 97 | protected Object getDataModel() { 98 | Map dataModel = new HashMap(); 99 | // 注意:根据freemarker的规范,dataModel中的key似乎只能支持字母和数字,不支持符号,例如eureka.Enabled,eureka-Enabled都会抛错 100 | dataModel.put(SkeletonConstant.PACKAGE, getPackage()); 101 | 102 | return dataModel; 103 | } 104 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/server/java/ServerConfigClassGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.server.java; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 16 | import com.nepxion.skeleton.engine.context.SkeletonContext; 17 | import com.nepxion.skeleton.engine.generator.SkeletonJavaGenerator; 18 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 19 | 20 | public class ServerConfigClassGenerator extends SkeletonJavaGenerator { 21 | public ServerConfigClassGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 22 | super(skeletonContext.clone("server", ServerConfigClassGenerator.class), skeletonProperties); 23 | } 24 | 25 | @Override 26 | protected String getPackage() { 27 | return super.getPackage() + ".config"; 28 | } 29 | 30 | @Override 31 | protected String getClassName() { 32 | return "ServerConfig"; 33 | } 34 | 35 | @Override 36 | protected String getTemplateName() { 37 | return "ServerConfig.java.template"; 38 | } 39 | 40 | @Override 41 | protected boolean isMainCode() { 42 | return true; 43 | } 44 | 45 | @Override 46 | protected Object getDataModel() { 47 | Map dataModel = new HashMap(); 48 | dataModel.put(SkeletonConstant.PACKAGE, getPackage()); 49 | 50 | return dataModel; 51 | } 52 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/server/java/ServerControllerClassGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.server.java; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 16 | import com.nepxion.skeleton.engine.context.SkeletonContext; 17 | import com.nepxion.skeleton.engine.generator.SkeletonJavaGenerator; 18 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 19 | 20 | public class ServerControllerClassGenerator extends SkeletonJavaGenerator { 21 | public ServerControllerClassGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 22 | super(skeletonContext.clone("server", ServerControllerClassGenerator.class), skeletonProperties); 23 | } 24 | 25 | @Override 26 | protected String getPackage() { 27 | return super.getPackage() + ".controller"; 28 | } 29 | 30 | @Override 31 | protected String getClassName() { 32 | return "ServerController"; 33 | } 34 | 35 | @Override 36 | protected String getTemplateName() { 37 | return "ServerController.java.template"; 38 | } 39 | 40 | @Override 41 | protected boolean isMainCode() { 42 | return true; 43 | } 44 | 45 | @Override 46 | protected Object getDataModel() { 47 | Map dataModel = new HashMap(); 48 | dataModel.put(SkeletonConstant.PACKAGE, getPackage()); 49 | 50 | return dataModel; 51 | } 52 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/server/java/TestServerApplicationClassGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.server.java; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 16 | import com.nepxion.skeleton.engine.context.SkeletonContext; 17 | import com.nepxion.skeleton.engine.generator.SkeletonJavaGenerator; 18 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 19 | 20 | public class TestServerApplicationClassGenerator extends SkeletonJavaGenerator { 21 | public TestServerApplicationClassGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 22 | super(skeletonContext.clone("server", TestServerApplicationClassGenerator.class), skeletonProperties); 23 | } 24 | 25 | @Override 26 | protected String getClassName() { 27 | return "TestServerApplication"; 28 | } 29 | 30 | @Override 31 | protected String getTemplateName() { 32 | return "TestServerApplication.java.template"; 33 | } 34 | 35 | @Override 36 | protected boolean isMainCode() { 37 | return false; 38 | } 39 | 40 | @Override 41 | protected Object getDataModel() { 42 | Map dataModel = new HashMap(); 43 | dataModel.put(SkeletonConstant.PACKAGE, getPackage()); 44 | 45 | return dataModel; 46 | } 47 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/server/resources/ApplicationPropertiesGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.server.resources; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 16 | import com.nepxion.skeleton.engine.context.SkeletonContext; 17 | import com.nepxion.skeleton.engine.generator.SkeletonFileGenerator; 18 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 19 | import com.nepxion.skeleton.engine.util.SkeletonUtil; 20 | 21 | public class ApplicationPropertiesGenerator extends SkeletonFileGenerator { 22 | /** 23 | * 构造方法 24 | * @param skeletonContext 封装了参数的上下文对象 25 | * @param skeletonProperties 全局配置文件对象 26 | */ 27 | public ApplicationPropertiesGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) { 28 | super(skeletonContext.clone("server", ApplicationPropertiesGenerator.class), skeletonProperties); 29 | } 30 | 31 | /** 32 | * 构造方法 33 | * @param generatePath 创建文件的顶级路径 34 | * @param projectType 工程类型 35 | * @param prefixTemplatePath 前置模板路径,例如template 36 | * @param reducedTemplatePath 模板路径缩减,考虑到模板路径和类路径必须一致,会导致路径太长,可以缩减掉一部分 37 | * @param skeletonProperties 全局配置文件对象 38 | */ 39 | /*public ApplicationPropertiesGenerator(String generatePath, String projectType, String prefixTemplatePath, String reducedTemplatePath, SkeletonProperties skeletonProperties) { 40 | super(generatePath, projectType, prefixTemplatePath, reducedTemplatePath, ApplicationPropertiesGenerator.class, skeletonProperties); 41 | }*/ 42 | 43 | /** 44 | * 构造方法 45 | * @param generatePath 创建文件的顶级路径 46 | * @param projectType 工程类型 47 | * @param baseTemplatePath 模板文件的顶级路径 48 | * @param fileType 创建的文件类型 49 | * @param skeletonProperties 全局配置文件对象 50 | */ 51 | /*public ApplicationPropertiesGenerator(String generatePath, String projectType, String baseTemplatePath, SkeletonFileType fileType, SkeletonProperties skeletonProperties) { 52 | super(generatePath, projectType, baseTemplatePath, fileType, skeletonProperties); 53 | }*/ 54 | 55 | /** 56 | * 设置文件名 57 | */ 58 | @Override 59 | protected String getFileName() { 60 | return "application.properties"; 61 | } 62 | 63 | /** 64 | * 设置模板名 65 | */ 66 | @Override 67 | protected String getTemplateName() { 68 | return "application.properties.template"; 69 | } 70 | 71 | /** 72 | * 设置文件的输出路径 73 | */ 74 | @Override 75 | protected String getOutputPath() { 76 | return super.getOutputPath() + SkeletonConstant.MAIN_RESOURCES_FILE_PATH; 77 | } 78 | 79 | /** 80 | * 设置文件创建的所依赖数据模型,主要做动态变量到原型模板的替换(任何文本的替换都支持) 81 | */ 82 | @Override 83 | protected Object getDataModel() { 84 | Map dataModel = new HashMap(); 85 | // 注意:根据freemarker的规范,dataModel中的key似乎只能支持字母和数字,不支持符号,例如service.Name,service-Name都会抛错 86 | dataModel.put("serviceName", skeletonProperties.getString("serviceName") + "-" + getSkeletonContext().getProjectType()); 87 | dataModel.put("port", skeletonProperties.getString("serverPort")); 88 | dataModel.put("registryUrl", skeletonProperties.getString("registryUrl")); 89 | dataModel.put("basePackage", SkeletonUtil.getBasePackagePath(getSkeletonContext().getProjectType(), skeletonProperties)); 90 | 91 | return dataModel; 92 | } 93 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/shared/GitAttributesGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.shared; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import com.nepxion.skeleton.engine.context.SkeletonContext; 13 | import com.nepxion.skeleton.engine.generator.SkeletonFileGenerator; 14 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 15 | 16 | public class GitAttributesGenerator extends SkeletonFileGenerator { 17 | public GitAttributesGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties, String projectType) { 18 | super(skeletonContext.clone(projectType, GitAttributesGenerator.class), skeletonProperties); 19 | } 20 | 21 | @Override 22 | protected String getFileName() { 23 | return ".gitattributes"; 24 | } 25 | 26 | @Override 27 | protected String getTemplateName() { 28 | return "file.gitattributes.template"; 29 | } 30 | 31 | @Override 32 | protected Object getDataModel() { 33 | return null; 34 | } 35 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/shared/GitIgnoreGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.shared; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import com.nepxion.skeleton.engine.context.SkeletonContext; 13 | import com.nepxion.skeleton.engine.generator.SkeletonFileGenerator; 14 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 15 | 16 | public class GitIgnoreGenerator extends SkeletonFileGenerator { 17 | public GitIgnoreGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties, String projectType) { 18 | super(skeletonContext.clone(projectType, GitIgnoreGenerator.class), skeletonProperties); 19 | } 20 | 21 | @Override 22 | protected String getFileName() { 23 | return ".gitignore"; 24 | } 25 | 26 | @Override 27 | protected String getTemplateName() { 28 | return "file.gitignore.template"; 29 | } 30 | 31 | @Override 32 | protected Object getDataModel() { 33 | return null; 34 | } 35 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/generator/shared/resources/LogbackXmlGenerator.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.generator.shared.resources; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 16 | import com.nepxion.skeleton.engine.context.SkeletonContext; 17 | import com.nepxion.skeleton.engine.generator.SkeletonFileGenerator; 18 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 19 | 20 | public class LogbackXmlGenerator extends SkeletonFileGenerator { 21 | public LogbackXmlGenerator(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties, String projectType) { 22 | super(skeletonContext.clone(projectType, LogbackXmlGenerator.class), skeletonProperties); 23 | } 24 | 25 | @Override 26 | protected String getFileName() { 27 | return "logback.xml"; 28 | } 29 | 30 | @Override 31 | protected String getTemplateName() { 32 | return "logback.xml.template"; 33 | } 34 | 35 | @Override 36 | protected String getOutputPath() { 37 | return super.getOutputPath() + SkeletonConstant.MAIN_RESOURCES_FILE_PATH; 38 | } 39 | 40 | @Override 41 | protected Object getDataModel() { 42 | Map dataModel = new HashMap(); 43 | dataModel.put("serviceName", skeletonProperties.getString("serviceName") + "-" + getSkeletonContext().getProjectType()); 44 | 45 | return dataModel; 46 | } 47 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/impl/ClientProjectServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.impl; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.IOException; 13 | 14 | import com.nepxion.skeleton.engine.context.SkeletonContext; 15 | import com.nepxion.skeleton.engine.exception.SkeletonException; 16 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 17 | import com.nepxion.skeleton.framework.service.SkeletonService; 18 | import com.nepxion.skeleton.plugin.springcloud.generator.client.PomXmlGenerator; 19 | import com.nepxion.skeleton.plugin.springcloud.generator.client.java.AbstractClientTestClassGenerator; 20 | import com.nepxion.skeleton.plugin.springcloud.generator.client.java.ClientApplicationClassGenerator; 21 | import com.nepxion.skeleton.plugin.springcloud.generator.client.java.ClientContextAwareClassGenerator; 22 | import com.nepxion.skeleton.plugin.springcloud.generator.client.java.ClientControllerClassGenerator; 23 | import com.nepxion.skeleton.plugin.springcloud.generator.client.java.ClientRestTestClassGenerator; 24 | import com.nepxion.skeleton.plugin.springcloud.generator.client.java.ClientRpcTestClassGenerator; 25 | import com.nepxion.skeleton.plugin.springcloud.generator.client.java.ClientServiceClassGenerator; 26 | import com.nepxion.skeleton.plugin.springcloud.generator.client.resources.ApplicationPropertiesGenerator; 27 | import com.nepxion.skeleton.plugin.springcloud.generator.shared.resources.LogbackXmlGenerator; 28 | 29 | import freemarker.template.TemplateException; 30 | 31 | public class ClientProjectServiceImpl implements SkeletonService { 32 | @Override 33 | public void generate(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) throws SkeletonException, TemplateException, IOException { 34 | // 创建Java类文件到main/java目录下 35 | new ClientApplicationClassGenerator(skeletonContext, skeletonProperties).generate(); 36 | new ClientContextAwareClassGenerator(skeletonContext, skeletonProperties).generate(); 37 | new ClientControllerClassGenerator(skeletonContext, skeletonProperties).generate(); 38 | new ClientServiceClassGenerator(skeletonContext, skeletonProperties).generate(); 39 | new AbstractClientTestClassGenerator(skeletonContext, skeletonProperties).generate(); 40 | new ClientRpcTestClassGenerator(skeletonContext, skeletonProperties).generate(); 41 | new ClientRestTestClassGenerator(skeletonContext, skeletonProperties).generate(); 42 | 43 | // 创建文件到main/resources目录下 44 | new ApplicationPropertiesGenerator(skeletonContext, skeletonProperties).generate(); 45 | new LogbackXmlGenerator(skeletonContext, skeletonProperties, "client").generate(); 46 | 47 | // 创建文件到根目录下 48 | new PomXmlGenerator(skeletonContext, skeletonProperties).generate(); 49 | } 50 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/impl/EurekaProjectServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.impl; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.IOException; 13 | 14 | import com.nepxion.skeleton.engine.context.SkeletonContext; 15 | import com.nepxion.skeleton.engine.exception.SkeletonException; 16 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 17 | import com.nepxion.skeleton.framework.service.SkeletonService; 18 | import com.nepxion.skeleton.plugin.springcloud.generator.eureka.PomXmlGenerator; 19 | import com.nepxion.skeleton.plugin.springcloud.generator.eureka.java.EurekaApplicationClassGenerator; 20 | import com.nepxion.skeleton.plugin.springcloud.generator.eureka.resources.ApplicationPropertiesGenerator; 21 | import com.nepxion.skeleton.plugin.springcloud.generator.shared.resources.LogbackXmlGenerator; 22 | 23 | import freemarker.template.TemplateException; 24 | 25 | public class EurekaProjectServiceImpl implements SkeletonService { 26 | @Override 27 | public void generate(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) throws SkeletonException, TemplateException, IOException { 28 | // 创建Java类文件到main/java目录下 29 | new EurekaApplicationClassGenerator(skeletonContext, skeletonProperties).generate(); 30 | new ApplicationPropertiesGenerator(skeletonContext, skeletonProperties).generate(); 31 | 32 | // 创建文件到main/resources目录下 33 | new LogbackXmlGenerator(skeletonContext, skeletonProperties, "eureka").generate(); 34 | 35 | // 创建文件到根目录下 36 | new PomXmlGenerator(skeletonContext, skeletonProperties).generate(); 37 | } 38 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/impl/ParentProjectServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.impl; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.IOException; 13 | 14 | import com.nepxion.skeleton.engine.context.SkeletonContext; 15 | import com.nepxion.skeleton.engine.exception.SkeletonException; 16 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 17 | import com.nepxion.skeleton.framework.service.SkeletonService; 18 | import com.nepxion.skeleton.plugin.springcloud.generator.InstallDockerShellGenerator; 19 | import com.nepxion.skeleton.plugin.springcloud.generator.PomXmlGenerator; 20 | import com.nepxion.skeleton.plugin.springcloud.generator.shared.GitAttributesGenerator; 21 | import com.nepxion.skeleton.plugin.springcloud.generator.shared.GitIgnoreGenerator; 22 | 23 | import freemarker.template.TemplateException; 24 | 25 | public class ParentProjectServiceImpl implements SkeletonService { 26 | @Override 27 | public void generate(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) throws SkeletonException, TemplateException, IOException { 28 | // 创建文件到顶级目录下 29 | new PomXmlGenerator(skeletonContext, skeletonProperties).generate(); 30 | new InstallDockerShellGenerator(skeletonContext, skeletonProperties, "eureka", "bat", null).generate(); 31 | new InstallDockerShellGenerator(skeletonContext, skeletonProperties, "eureka", "sh", null).generate(); 32 | new InstallDockerShellGenerator(skeletonContext, skeletonProperties, "server", "bat", null).generate(); 33 | new InstallDockerShellGenerator(skeletonContext, skeletonProperties, "server", "sh", null).generate(); 34 | new InstallDockerShellGenerator(skeletonContext, skeletonProperties, "client", "bat", skeletonProperties.getString("serviceName") + "-server").generate(); 35 | new InstallDockerShellGenerator(skeletonContext, skeletonProperties, "client", "sh", skeletonProperties.getString("serviceName") + "-server").generate(); 36 | new GitAttributesGenerator(skeletonContext, skeletonProperties, null).generate(); 37 | new GitIgnoreGenerator(skeletonContext, skeletonProperties, null).generate(); 38 | } 39 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/impl/ServerProjectServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.impl; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.IOException; 13 | 14 | import com.nepxion.skeleton.engine.context.SkeletonContext; 15 | import com.nepxion.skeleton.engine.exception.SkeletonException; 16 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 17 | import com.nepxion.skeleton.framework.service.SkeletonService; 18 | import com.nepxion.skeleton.plugin.springcloud.generator.server.PomXmlGenerator; 19 | import com.nepxion.skeleton.plugin.springcloud.generator.server.java.ServerApplicationClassGenerator; 20 | import com.nepxion.skeleton.plugin.springcloud.generator.server.java.ServerConfigClassGenerator; 21 | import com.nepxion.skeleton.plugin.springcloud.generator.server.java.ServerControllerClassGenerator; 22 | import com.nepxion.skeleton.plugin.springcloud.generator.server.java.TestServerApplicationClassGenerator; 23 | import com.nepxion.skeleton.plugin.springcloud.generator.server.resources.ApplicationPropertiesGenerator; 24 | import com.nepxion.skeleton.plugin.springcloud.generator.shared.resources.LogbackXmlGenerator; 25 | 26 | import freemarker.template.TemplateException; 27 | 28 | public class ServerProjectServiceImpl implements SkeletonService { 29 | @Override 30 | public void generate(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) throws SkeletonException, TemplateException, IOException { 31 | // 创建Java类文件到main/java目录下 32 | new ServerApplicationClassGenerator(skeletonContext, skeletonProperties).generate(); 33 | new ServerControllerClassGenerator(skeletonContext, skeletonProperties).generate(); 34 | new ServerConfigClassGenerator(skeletonContext, skeletonProperties).generate(); 35 | 36 | // 创建Java类文件到test/java目录下 37 | new TestServerApplicationClassGenerator(skeletonContext, skeletonProperties).generate(); 38 | 39 | // 创建文件到main/resources目录下 40 | new ApplicationPropertiesGenerator(skeletonContext, skeletonProperties).generate(); 41 | new LogbackXmlGenerator(skeletonContext, skeletonProperties, "server").generate(); 42 | 43 | // 创建文件到根目录下 44 | new PomXmlGenerator(skeletonContext, skeletonProperties).generate(); 45 | } 46 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/java/com/nepxion/skeleton/plugin/springcloud/impl/SpringcloudServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud.impl; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.io.IOException; 13 | 14 | import com.nepxion.skeleton.engine.context.SkeletonContext; 15 | import com.nepxion.skeleton.engine.exception.SkeletonException; 16 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 17 | import com.nepxion.skeleton.framework.annotation.SkeletonPlugin; 18 | import com.nepxion.skeleton.framework.service.SkeletonService; 19 | 20 | import freemarker.template.TemplateException; 21 | 22 | @SkeletonPlugin(name="springcloud") 23 | public class SpringcloudServiceImpl implements SkeletonService { 24 | private SkeletonService parentProjectService = new ParentProjectServiceImpl(); 25 | private SkeletonService eurekaProjectService = new EurekaProjectServiceImpl(); 26 | private SkeletonService serverProjectService = new ServerProjectServiceImpl(); 27 | private SkeletonService clientProjectService = new ClientProjectServiceImpl(); 28 | 29 | @Override 30 | public void generate(SkeletonContext skeletonContext, SkeletonProperties skeletonProperties) throws SkeletonException, TemplateException, IOException { 31 | parentProjectService.generate(skeletonContext, skeletonProperties); 32 | eurekaProjectService.generate(skeletonContext, skeletonProperties); 33 | serverProjectService.generate(skeletonContext, skeletonProperties); 34 | clientProjectService.generate(skeletonContext, skeletonProperties); 35 | } 36 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/config/skeleton-context.properties: -------------------------------------------------------------------------------- 1 | # 模板文件所在的前置路径 2 | skeleton.prefix.template.path=springcloud/template 3 | # 模板文件所在的路径根据传入的Key动态切换,不设置则表示不切换 4 | skeleton.dynamic.template.path.key= 5 | # 模板路径缩减,考虑到模板路径和类路径必须一致,会导致路径太长,可以缩减掉一部分 6 | skeleton.reduced.template.path=com/nepxion/skeleton/plugin/springcloud/generator/ 7 | # 在前端下载zip包名 8 | skeleton.generate.file.name=spring-cloud-skeleton 9 | # 在后端生成zip包的放置路径,不设置则放在操作系统的临时目录下 10 | skeleton.generate.path= -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/config/skeleton-data.properties: -------------------------------------------------------------------------------- 1 | # ---------- 工程配置 ---------- 2 | basePackage=cn.springcloud 3 | pomGroupId=cn.springcloud 4 | pomArtifactId=payment-ccb 5 | pomName=Spring Cloud Payment CCB 6 | pomVersion=1.0.0 7 | springCloudVersion=Edgware.SR5 8 | springBootVersion=1.5.18.RELEASE 9 | javaVersion=1.8 10 | 11 | # ---------- Spring Cloud配置 ---------- 12 | serviceName=spring-cloud-payment-ccb 13 | # registryUrl=http://localhost:9528/eureka/ 14 | registryUrl=http://10.0.75.1:9528/eureka/ 15 | eurekaPort=9528 16 | serverPort=9628 17 | clientPort=9728 18 | clientHystrixEnabled=true 19 | 20 | # ---------- 容器配置 ---------- 21 | dockerHost=tcp://localhost:2375 22 | dockerType=Interaction Container 23 | dockerCertEnabled=false 24 | dockerCertPath=C:/Users/Neptune/.docker/machine/certs 25 | # dockerCertPath=/User/Neptune/.docker/machine/certs 26 | javaImageVersion=openjdk:8-jre-alpine -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/client/java/AbstractClientTest.java.template: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | public abstract class AbstractClientTest { 4 | public void test() { 5 | testGet(); 6 | testPost(); 7 | testPut(); 8 | testDelete(); 9 | } 10 | 11 | public abstract void testGet(); 12 | 13 | public abstract void testPost(); 14 | 15 | public abstract void testPut(); 16 | 17 | public abstract void testDelete(); 18 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/client/java/ClientApplication.java.template: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import java.util.Timer; 4 | import java.util.TimerTask; 5 | 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.boot.builder.SpringApplicationBuilder; 8 | <#if clientHystrixEnabled == "true"> 9 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 10 | 11 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 12 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 13 | 14 | import ${package}.test.ClientRestTest; 15 | import ${package}.test.ClientRpcTest; 16 | 17 | @SpringBootApplication 18 | @EnableDiscoveryClient 19 | @EnableFeignClients 20 | <#if clientHystrixEnabled == "true"> 21 | @EnableCircuitBreaker 22 | 23 | public class ClientApplication { 24 | public static void main(String[] args) { 25 | new SpringApplicationBuilder(ClientApplication.class).web(true).run(args); 26 | 27 | ClientRpcTest clientRpcTest = new ClientRpcTest(); 28 | ClientRestTest clientRestTest = new ClientRestTest(); 29 | 30 | Timer timer = new Timer(); 31 | timer.scheduleAtFixedRate(new TimerTask() { 32 | public void run() { 33 | new Thread(new Runnable() { 34 | @Override 35 | public void run() { 36 | clientRpcTest.test(); 37 | clientRestTest.test(); 38 | } 39 | }).start(); 40 | } 41 | }, 0L, 5000L); 42 | } 43 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/client/java/ClientContextAware.java.template: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.beans.factory.NoSuchBeanDefinitionException; 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.context.ApplicationContextAware; 7 | import org.springframework.core.ResolvableType; 8 | import org.springframework.core.env.Environment; 9 | import org.springframework.stereotype.Component; 10 | 11 | @Component 12 | public class ClientContextAware implements ApplicationContextAware { 13 | private static ApplicationContext applicationContext; 14 | 15 | private ClientContextAware() { 16 | } 17 | 18 | private static void setContext(ApplicationContext applicationContext) { 19 | ClientContextAware.applicationContext = applicationContext; 20 | } 21 | 22 | @Override 23 | public void setApplicationContext(ApplicationContext applicationContext) { 24 | ClientContextAware.setContext(applicationContext); 25 | } 26 | 27 | public static Object getBean(String name) throws BeansException { 28 | return applicationContext.getBean(name); 29 | } 30 | 31 | public static T getBean(String name, Class requiredType) throws BeansException { 32 | return applicationContext.getBean(name, requiredType); 33 | } 34 | 35 | public static Object getBean(String name, Object... args) throws BeansException { 36 | return applicationContext.getBean(name, args); 37 | } 38 | 39 | public static T getBean(Class requiredType) throws BeansException { 40 | return applicationContext.getBean(requiredType); 41 | } 42 | 43 | public static T getBean(Class requiredType, Object... args) throws BeansException { 44 | return applicationContext.getBean(requiredType, args); 45 | } 46 | 47 | public static boolean containsBean(String name) { 48 | return applicationContext.containsBean(name); 49 | } 50 | 51 | public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException { 52 | return applicationContext.isSingleton(name); 53 | } 54 | 55 | public static boolean isPrototype(String name) throws NoSuchBeanDefinitionException { 56 | return applicationContext.isPrototype(name); 57 | } 58 | 59 | public static boolean isTypeMatch(String name, ResolvableType typeToMatch) throws NoSuchBeanDefinitionException { 60 | return applicationContext.isTypeMatch(name, typeToMatch); 61 | } 62 | 63 | public static boolean isTypeMatch(String name, Class typeToMatch) throws NoSuchBeanDefinitionException { 64 | return applicationContext.isTypeMatch(name, typeToMatch); 65 | } 66 | 67 | public static Class getType(String name) throws NoSuchBeanDefinitionException { 68 | return applicationContext.getType(name); 69 | } 70 | 71 | public static String[] getAliases(String name) { 72 | return applicationContext.getAliases(name); 73 | } 74 | 75 | public static Environment getEnvironment() { 76 | return applicationContext.getEnvironment(); 77 | } 78 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/client/java/ClientController.java.template: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.PathVariable; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestMethod; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import ${basePackage}.service.ClientService; 11 | <#if clientHystrixEnabled == "true"> 12 | 13 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 14 | 15 | 16 | @RestController 17 | public class ClientController { 18 | @Autowired 19 | private ClientService clientService; 20 | 21 | @RequestMapping(value = "/invokeGet/{id}", method = RequestMethod.GET) 22 | <#if clientHystrixEnabled == "true"> 23 | @HystrixCommand(fallbackMethod = "invokeGetFallback") 24 | 25 | public String invokeGet(@PathVariable(value = "id") Integer id) { 26 | return clientService.invokeGet(id); 27 | } 28 | 29 | @RequestMapping(value = "/invokePost", method = RequestMethod.POST) 30 | <#if clientHystrixEnabled == "true"> 31 | @HystrixCommand(fallbackMethod = "invokePostFallback") 32 | 33 | public String invokePost(@RequestParam(value = "data") String data) { 34 | return clientService.invokePost(data); 35 | } 36 | 37 | @RequestMapping(value = "/invokePut", method = RequestMethod.PUT) 38 | <#if clientHystrixEnabled == "true"> 39 | @HystrixCommand(fallbackMethod = "invokePutFallback") 40 | 41 | public String invokePut(@RequestParam(value = "data") String data) { 42 | return clientService.invokePut(data); 43 | } 44 | 45 | @RequestMapping(value = "/invokeDelete/{id}", method = RequestMethod.DELETE) 46 | <#if clientHystrixEnabled == "true"> 47 | @HystrixCommand(fallbackMethod = "invokeDeleteFallback") 48 | 49 | public String invokeDelete(@PathVariable(value = "id") Integer id) { 50 | return clientService.invokeDelete(id); 51 | } 52 | <#if clientHystrixEnabled == "true"> 53 | 54 | public String invokeGetFallback(Integer id) { 55 | String value = "Invoke GET is fallback, parameter=" + id; 56 | 57 | return value; 58 | } 59 | 60 | public String invokePostFallback(String data) { 61 | String value = "Invoke POST is fallback, parameter=" + data; 62 | 63 | return value; 64 | } 65 | 66 | public String invokePutFallback(String data) { 67 | String value = "Invoke PUT is fallback, parameter=" + data; 68 | 69 | return value; 70 | } 71 | 72 | public String invokeDeleteFallback(Integer id) { 73 | String value = "Invoke DELETE is fallback, parameter=" + id; 74 | 75 | return value; 76 | } 77 | 78 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/client/java/ClientRestTest.java.template: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.http.HttpEntity; 6 | import org.springframework.http.HttpHeaders; 7 | import org.springframework.util.LinkedMultiValueMap; 8 | import org.springframework.util.MultiValueMap; 9 | import org.springframework.web.client.RestTemplate; 10 | 11 | public class ClientRestTest extends AbstractClientTest { 12 | private static final Logger LOG = LoggerFactory.getLogger(ClientRestTest.class); 13 | 14 | private static final String URL = "http://localhost:${port}"; 15 | 16 | private RestTemplate restTemplate; 17 | 18 | public ClientRestTest() { 19 | restTemplate = new RestTemplate(); 20 | } 21 | 22 | @Override 23 | public void testGet() { 24 | String value = restTemplate.getForObject(URL + "/invokeGet/123", String.class); 25 | 26 | LOG.info("Client - Rest :: {}", value); 27 | } 28 | 29 | @Override 30 | public void testPost() { 31 | MultiValueMap parameters = new LinkedMultiValueMap<>(); 32 | parameters.add("data", "abc"); 33 | 34 | HttpHeaders headers = new HttpHeaders(); 35 | HttpEntity> entity = new HttpEntity<>(parameters, headers); 36 | 37 | String value = restTemplate.postForObject(URL + "/invokePost", entity, String.class); 38 | 39 | LOG.info("Client - Rest :: {}", value); 40 | } 41 | 42 | @Override 43 | public void testPut() { 44 | MultiValueMap parameters = new LinkedMultiValueMap<>(); 45 | parameters.add("data", "abc"); 46 | 47 | HttpHeaders headers = new HttpHeaders(); 48 | HttpEntity> entity = new HttpEntity<>(parameters, headers); 49 | 50 | restTemplate.put(URL + "/invokePut", entity); 51 | } 52 | 53 | @Override 54 | public void testDelete() { 55 | restTemplate.delete(URL + "/invokeDelete/456"); 56 | } 57 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/client/java/ClientRpcTest.java.template: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import ${basePackage}.context.ClientContextAware; 7 | import ${basePackage}.controller.ClientController; 8 | 9 | public class ClientRpcTest extends AbstractClientTest { 10 | private static final Logger LOG = LoggerFactory.getLogger(ClientRpcTest.class); 11 | 12 | private ClientController clientController; 13 | 14 | public ClientRpcTest() { 15 | clientController = ClientContextAware.getBean(ClientController.class); 16 | } 17 | 18 | @Override 19 | public void testGet() { 20 | String value = clientController.invokeGet(123); 21 | 22 | LOG.info("Client - Rpc :: {}", value); 23 | } 24 | 25 | @Override 26 | public void testPost() { 27 | String value = clientController.invokePost("abc"); 28 | 29 | LOG.info("Client - Rpc :: {}", value); 30 | } 31 | 32 | @Override 33 | public void testPut() { 34 | String value = clientController.invokePut("xzy"); 35 | 36 | LOG.info("Client - Rpc :: {}", value); 37 | } 38 | 39 | @Override 40 | public void testDelete() { 41 | String value = clientController.invokeDelete(456); 42 | 43 | LOG.info("Client - Rpc :: {}", value); 44 | } 45 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/client/java/ClientService.java.template: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import org.springframework.cloud.netflix.feign.FeignClient; 4 | import org.springframework.web.bind.annotation.PathVariable; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestMethod; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | 9 | @FeignClient(value = "${r"$"}{service.cluster.name}") 10 | public interface ClientService { 11 | @RequestMapping(value = "/invokeGet/{id}", method = RequestMethod.GET) 12 | String invokeGet(@PathVariable(value = "id") Integer id); 13 | 14 | @RequestMapping(value = "/invokePost", method = RequestMethod.POST) 15 | String invokePost(@RequestParam(value = "data") String data); 16 | 17 | @RequestMapping(value = "/invokePut", method = RequestMethod.PUT) 18 | String invokePut(@RequestParam(value = "data") String data); 19 | 20 | @RequestMapping(value = "/invokeDelete/{id}", method = RequestMethod.DELETE) 21 | String invokeDelete(@PathVariable(value = "id") Integer id); 22 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/client/pom.xml.template: -------------------------------------------------------------------------------- 1 | 2 | 4 | ${pomArtifactId} 5 | ${pomName} 6 | jar 7 | 4.0.0 8 | 9 | ${pomGroupId} 10 | ${parentPomArtifactId} 11 | ${pomVersion} 12 | 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-eureka 18 | 19 | 20 | 21 | org.springframework.cloud 22 | spring-cloud-starter-ribbon 23 | 24 | 25 | 26 | org.springframework.cloud 27 | spring-cloud-starter-feign 28 | 29 | <#if clientHystrixEnabled == "true"> 30 | 31 | 32 | org.springframework.cloud 33 | spring-cloud-starter-hystrix 34 | 35 | 36 | 37 | 38 | 39 | ${r"$"}{project.artifactId}-${r"$"}{project.version} 40 | 41 | 42 | org.apache.maven.plugins 43 | maven-compiler-plugin 44 | 45 | 46 | -parameters 47 | 48 | ${r"$"}{project.build.sourceEncoding} 49 | ${r"$"}{java.version} 50 | ${r"$"}{java.version} 51 | 52 | 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-maven-plugin 57 | 58 | true 59 | ${mainClass} 60 | JAR 61 | 62 | 63 | 64 | 65 | repackage 66 | 67 | 68 | false 69 | 70 | 71 | 72 | 73 | 74 | 75 | com.spotify 76 | docker-maven-plugin 77 | 78 | ${r"$"}{ImageName} 79 | ${javaImageVersion} 80 | ["java", "-jar", "/${r"$"}{project.build.finalName}.jar"] 81 | 82 | ${r"$"}{ExposePort} 83 | 84 | 85 | 86 | / 87 | ${r"$"}{project.build.directory} 88 | ${r"$"}{project.build.finalName}.jar 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | src/main/java 97 | 98 | **/*.xml 99 | **/*.properties 100 | 101 | 102 | 103 | src/main/resources 104 | 105 | **/*.xml 106 | **/*.properties 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/client/resources/application.properties.template: -------------------------------------------------------------------------------- 1 | spring.application.name=${serviceName} 2 | server.port=${port} 3 | 4 | service.cluster.name=${clusterName} 5 | 6 | eureka.client.serviceUrl.defaultZone=${registryUrl} -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/eureka/java/EurekaApplication.java.template: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class EurekaApplication { 10 | public static void main(String[] args) { 11 | new SpringApplicationBuilder(EurekaApplication.class).web(true).run(args); 12 | } 13 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/eureka/pom.xml.template: -------------------------------------------------------------------------------- 1 | 2 | 4 | ${pomArtifactId} 5 | ${pomName} 6 | jar 7 | 4.0.0 8 | 9 | ${pomGroupId} 10 | ${parentPomArtifactId} 11 | ${pomVersion} 12 | 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-eureka-server 18 | 19 | 20 | 21 | 22 | ${r"$"}{project.artifactId}-${r"$"}{project.version} 23 | 24 | 25 | org.apache.maven.plugins 26 | maven-compiler-plugin 27 | 28 | 29 | -parameters 30 | 31 | ${r"$"}{project.build.sourceEncoding} 32 | ${r"$"}{java.version} 33 | ${r"$"}{java.version} 34 | 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-maven-plugin 40 | 41 | true 42 | ${mainClass} 43 | JAR 44 | 45 | 46 | 47 | 48 | repackage 49 | 50 | 51 | false 52 | 53 | 54 | 55 | 56 | 57 | 58 | com.spotify 59 | docker-maven-plugin 60 | 61 | ${r"$"}{ImageName} 62 | ${javaImageVersion} 63 | ["java", "-jar", "/${r"$"}{project.build.finalName}.jar"] 64 | 65 | ${r"$"}{ExposePort} 66 | 67 | 68 | 69 | / 70 | ${r"$"}{project.build.directory} 71 | ${r"$"}{project.build.finalName}.jar 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | src/main/java 80 | 81 | **/*.xml 82 | **/*.properties 83 | 84 | 85 | 86 | src/main/resources 87 | 88 | **/*.xml 89 | **/*.properties 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/eureka/resources/application.properties.template: -------------------------------------------------------------------------------- 1 | spring.application.name=${serviceName} 2 | server.port=${port} 3 | 4 | eureka.client.serviceUrl.defaultZone=${registryUrl} -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/install-docker.bat.template: -------------------------------------------------------------------------------- 1 | @echo on 2 | @echo ============================================================= 3 | @echo $ $ 4 | @echo $ Nepxion Skeleton $ 5 | @echo $ $ 6 | @echo $ $ 7 | @echo $ $ 8 | @echo $ Nepxion Studio All Right Reserved $ 9 | @echo $ Copyright (C) 2017-2050 $ 10 | @echo $ $ 11 | @echo ============================================================= 12 | @echo. 13 | @echo off 14 | 15 | @title Nepxion Skeleton [${imageName}] 16 | @color 0a 17 | 18 | @set PROJECT_NAME=${projectName} 19 | 20 | @set DOCKER_HOST=${dockerHost} 21 | <#if dockerCertEnabled != "true">@rem @set DOCKER_CERT_PATH=${dockerCertPath} 22 | @set IMAGE_NAME=${imageName} 23 | @set MACHINE_PORT=${port} 24 | @set CONTAINER_PORT=${port} 25 | <#if dockerType != "Interaction Container">@rem @set RUN_MODE=-i -t 26 | <#if dockerType != "Daemon Container">@rem @set RUN_MODE=-d 27 | <#if linkDocker != ""> 28 | @set LINK_CONTAINER=${linkDocker} 29 | 30 | 31 | if exist %PROJECT_NAME%\target rmdir /s/q %PROJECT_NAME%\target 32 | 33 | @rem 执行相关模块的Maven Install 34 | call mvn clean install -DskipTests -pl %PROJECT_NAME% -am 35 | 36 | @rem 停止和删除Docker容器 37 | call docker stop %IMAGE_NAME% 38 | @rem call docker kill %IMAGE_NAME% 39 | call docker rm %IMAGE_NAME% 40 | 41 | @rem 删除Docker镜像 42 | call docker rmi %IMAGE_NAME% 43 | 44 | cd %PROJECT_NAME% 45 | 46 | @rem 安装Docker镜像 47 | call mvn package docker:build -DskipTests -DImageName=%IMAGE_NAME% -DExposePort=%CONTAINER_PORT% 48 | 49 | @rem 安装和启动Docker容器,并自动执行端口映射 50 | call docker run %RUN_MODE% -p %MACHINE_PORT%:%CONTAINER_PORT% -h %IMAGE_NAME%<#if linkDocker != ""> --link %LINK_CONTAINER%:%LINK_CONTAINER% --name %IMAGE_NAME% %IMAGE_NAME%:latest 51 | 52 | pause -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/install-docker.sh.template: -------------------------------------------------------------------------------- 1 | echo 'on' 2 | echo '=============================================================' 3 | echo '$ $' 4 | echo '$ Nepxion Skeleton $' 5 | echo '$ $' 6 | echo '$ $' 7 | echo '$ $' 8 | echo '$ Nepxion Studio All Right Reserved $' 9 | echo '$ Copyright (C) 2017-2050 $' 10 | echo '$ $' 11 | echo '=============================================================' 12 | echo '.' 13 | echo 'off' 14 | 15 | title=Nepxion Skeleton [${imageName}] 16 | color=0a 17 | 18 | PROJECT_NAME=${projectName} 19 | 20 | DOCKER_HOST=${dockerHost} 21 | <#if dockerCertEnabled != "true"># DOCKER_CERT_PATH=${dockerCertPath} 22 | IMAGE_NAME=${imageName} 23 | MACHINE_PORT=${port} 24 | CONTAINER_PORT=${port} 25 | <#if dockerType != "Interaction Container"># RUN_MODE=-i -t 26 | <#if dockerType != "Daemon Container"># RUN_MODE=-d 27 | <#if linkDocker != ""> 28 | LINK_CONTAINER=${linkDocker} 29 | 30 | 31 | if [ ! -d ${r"$"}{PROJECT_NAME}/target];then 32 | rmdir /s/q ${r"$"}{PROJECT_NAME}/target 33 | fi 34 | 35 | # 执行相关模块的Maven Install 36 | mvn clean install -DskipTests -pl ${r"$"}{PROJECT_NAME} -am 37 | 38 | # 停止和删除Docker容器 39 | docker stop ${r"$"}{IMAGE_NAME} 40 | # docker kill ${r"$"}{IMAGE_NAME} 41 | docker rm ${r"$"}{IMAGE_NAME} 42 | 43 | # 删除Docker镜像 44 | docker rmi ${r"$"}{IMAGE_NAME} 45 | 46 | cd ${r"$"}{PROJECT_NAME} 47 | 48 | # 安装Docker镜像 49 | mvn package docker:build -DskipTests -DImageName=${r"$"}{IMAGE_NAME} -DExposePort=${r"$"}{CONTAINER_PORT} 50 | 51 | # 安装和启动Docker容器,并自动执行端口映射 52 | docker run ${r"$"}{RUN_MODE} -p ${r"$"}{MACHINE_PORT}:${r"$"}{CONTAINER_PORT} -h ${r"$"}{IMAGE_NAME}<#if linkDocker != ""> --link ${r"$"}{LINK_CONTAINER}:${r"$"}{LINK_CONTAINER} --name ${r"$"}{IMAGE_NAME} ${r"$"}{IMAGE_NAME}:latest -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/pom.xml.template: -------------------------------------------------------------------------------- 1 | 2 | 4 | ${pomGroupId} 5 | ${pomArtifactId} 6 | ${pomName} 7 | pom 8 | 4.0.0 9 | ${pomVersion} 10 | http://www.nepxion.com 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | ${springBootVersion} 15 | 16 | 17 | 18 | ${moduleName}-eureka 19 | ${moduleName}-server 20 | ${moduleName}-client 21 | 22 | 23 | 24 | ${springCloudVersion} 25 | ${javaVersion} 26 | UTF-8 27 | 28 | 29 | 30 | 31 | 32 | ${r"$"}{project.groupId} 33 | ${moduleName}-eureka 34 | ${r"$"}{project.version} 35 | 36 | 37 | 38 | ${r"$"}{project.groupId} 39 | ${moduleName}-server 40 | ${r"$"}{project.version} 41 | 42 | 43 | 44 | ${r"$"}{project.groupId} 45 | ${moduleName}-client 46 | ${r"$"}{project.version} 47 | 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-dependencies 52 | ${r"$"}{spring.cloud.version} 53 | pom 54 | import 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | org.apache.maven.plugins 63 | maven-compiler-plugin 64 | 65 | ${r"$"}{project.build.sourceEncoding} 66 | ${r"$"}{java.version} 67 | ${r"$"}{java.version} 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/server/java/ServerApplication.java.template: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @SpringBootApplication 8 | @EnableDiscoveryClient 9 | public class ServerApplication { 10 | public static void main(String[] args) { 11 | new SpringApplicationBuilder(ServerApplication.class).web(true).run(args); 12 | } 13 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/server/java/ServerConfig.java.template: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import springfox.documentation.builders.ApiInfoBuilder; 4 | import springfox.documentation.builders.PathSelectors; 5 | import springfox.documentation.builders.RequestHandlerSelectors; 6 | import springfox.documentation.service.ApiInfo; 7 | import springfox.documentation.service.Contact; 8 | import springfox.documentation.spi.DocumentationType; 9 | import springfox.documentation.spring.web.plugins.Docket; 10 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 11 | 12 | import org.springframework.beans.factory.annotation.Value; 13 | import org.springframework.context.annotation.Bean; 14 | import org.springframework.context.annotation.Configuration; 15 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 16 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 17 | 18 | @Configuration 19 | @EnableSwagger2 20 | public class ServerConfig extends WebMvcConfigurerAdapter { 21 | @Value("${r"$"}{spring.application.name}") 22 | private String serviceName; 23 | 24 | @Value("${r"$"}{swagger.service.base.package}") 25 | private String basePackage; 26 | 27 | @Value("${r"$"}{swagger.service.description}") 28 | private String description; 29 | 30 | @Value("${r"$"}{swagger.service.version}") 31 | private String version; 32 | 33 | @Value("${r"$"}{swagger.service.license.name}") 34 | private String license; 35 | 36 | @Value("${r"$"}{swagger.service.license.url}") 37 | private String licenseUrl; 38 | 39 | @Value("${r"$"}{swagger.service.contact.name}") 40 | private String contactName; 41 | 42 | @Value("${r"$"}{swagger.service.contact.url}") 43 | private String contactUrl; 44 | 45 | @Value("${r"$"}{swagger.service.contact.email}") 46 | private String contactEmail; 47 | 48 | @Value("${r"$"}{swagger.cors.registry.enabled:false}") 49 | private Boolean corsRegistryEnabled; 50 | 51 | @Bean 52 | public Docket createRestApi() { 53 | return new Docket(DocumentationType.SWAGGER_2) 54 | .apiInfo(apiInfo()) 55 | .select() 56 | .apis(RequestHandlerSelectors.basePackage(basePackage)) // 扫描该包下的所有需要在Swagger中展示的API,@ApiIgnore注解标注的除外 57 | .paths(PathSelectors.any()) 58 | .build(); 59 | } 60 | 61 | private ApiInfo apiInfo() { 62 | return new ApiInfoBuilder() 63 | .title(serviceName) 64 | .description(description) 65 | .version(version) 66 | .license(license) 67 | .licenseUrl(licenseUrl) 68 | .contact(new Contact(contactName, contactUrl, contactEmail)) 69 | .build(); 70 | } 71 | 72 | // 解决跨域问题 73 | @Override 74 | public void addCorsMappings(CorsRegistry registry) { 75 | if (corsRegistryEnabled) { 76 | registry.addMapping("/**") 77 | .allowedHeaders("*") 78 | .allowedMethods("*") 79 | .allowedOrigins("*"); 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/server/java/ServerController.java.template: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import io.swagger.annotations.Api; 4 | import io.swagger.annotations.ApiOperation; 5 | import io.swagger.annotations.ApiParam; 6 | 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.web.bind.annotation.PathVariable; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestMethod; 12 | import org.springframework.web.bind.annotation.RequestParam; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | @RestController 16 | @Api(tags = { "服务端接口" }) 17 | public class ServerController { 18 | private static final Logger LOG = LoggerFactory.getLogger(ServerController.class); 19 | 20 | @RequestMapping(value = "/invokeGet/{id}", method = RequestMethod.GET) 21 | @ApiOperation(value = "执行GET操作", notes = "执行GET操作", response = String.class, httpMethod = "GET") 22 | public String invokeGet(@PathVariable(value = "id") @ApiParam(value = "参数", required = true) Integer id) { 23 | String value = "Invoke GET is response, parameter=" + id; 24 | 25 | LOG.info("Server - {}", value); 26 | 27 | return value; 28 | } 29 | 30 | @RequestMapping(value = "/invokePost", method = RequestMethod.POST) 31 | @ApiOperation(value = "执行POST操作", notes = "执行POST操作", response = String.class, httpMethod = "POST") 32 | public String invokePost(@RequestParam(value = "data") @ApiParam(value = "参数", required = true) String data) { 33 | String value = "Invoke POST is response, parameter=" + data; 34 | 35 | LOG.info("Server - {}", value); 36 | 37 | return value; 38 | } 39 | 40 | @RequestMapping(value = "/invokePut", method = RequestMethod.PUT) 41 | @ApiOperation(value = "执行PUT操作", notes = "执行PUT操作", response = String.class, httpMethod = "PUT") 42 | public String invokePut(@RequestParam(value = "data") @ApiParam(value = "参数", required = true) String data) { 43 | String value = "Invoke PUT is response, parameter=" + data; 44 | 45 | LOG.info("Server - {}", value); 46 | 47 | return value; 48 | } 49 | 50 | @RequestMapping(value = "/invokeDelete/{id}", method = RequestMethod.DELETE) 51 | @ApiOperation(value = "执行DELETE操作", notes = "执行DELETE操作", response = String.class, httpMethod = "DELETE") 52 | public String invokeDelete(@PathVariable(value = "id") @ApiParam(value = "参数", required = true) Integer id) { 53 | String value = "Invoke DELETE is response, parameter=" + id; 54 | 55 | LOG.info("Server - {}", value); 56 | 57 | return value; 58 | } 59 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/server/java/TestServerApplication.java.template: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @SpringBootApplication 8 | @EnableDiscoveryClient 9 | public class TestServerApplication { 10 | public static void main(String[] args) { 11 | new SpringApplicationBuilder(ServerApplication.class).web(true).run(args); 12 | } 13 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/server/pom.xml.template: -------------------------------------------------------------------------------- 1 | 2 | 4 | ${pomArtifactId} 5 | ${pomName} 6 | jar 7 | 4.0.0 8 | 9 | ${pomGroupId} 10 | ${parentPomArtifactId} 11 | ${pomVersion} 12 | 13 | 14 | 15 | 2.7.0 16 | 17 | 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-eureka 22 | 23 | 24 | 25 | io.springfox 26 | springfox-swagger2 27 | ${r"$"}{swagger.version} 28 | 29 | 30 | 31 | io.springfox 32 | springfox-swagger-ui 33 | ${r"$"}{swagger.version} 34 | 35 | 36 | 37 | 38 | ${r"$"}{project.artifactId}-${r"$"}{project.version} 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-compiler-plugin 43 | 44 | 45 | -parameters 46 | 47 | ${r"$"}{project.build.sourceEncoding} 48 | ${r"$"}{java.version} 49 | ${r"$"}{java.version} 50 | 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-maven-plugin 56 | 57 | true 58 | ${mainClass} 59 | JAR 60 | 61 | 62 | 63 | 64 | repackage 65 | 66 | 67 | false 68 | 69 | 70 | 71 | 72 | 73 | 74 | com.spotify 75 | docker-maven-plugin 76 | 77 | ${r"$"}{ImageName} 78 | ${javaImageVersion} 79 | ["java", "-jar", "/${r"$"}{project.build.finalName}.jar"] 80 | 81 | ${r"$"}{ExposePort} 82 | 83 | 84 | 85 | / 86 | ${r"$"}{project.build.directory} 87 | ${r"$"}{project.build.finalName}.jar 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | src/main/java 96 | 97 | **/*.xml 98 | **/*.properties 99 | 100 | 101 | 102 | src/main/resources 103 | 104 | **/*.xml 105 | **/*.properties 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/server/resources/application.properties.template: -------------------------------------------------------------------------------- 1 | spring.application.name=${serviceName} 2 | server.port=${port} 3 | 4 | eureka.client.serviceUrl.defaultZone=${registryUrl} 5 | 6 | swagger.service.base.package=${basePackage} 7 | swagger.service.description=Skeleton Spring Cloud Restful APIs 8 | swagger.service.version=1.0.0 9 | swagger.service.license.name=Apache License 2.0 10 | swagger.service.license.url=http://www.apache.org/licenses/LICENSE-2.0 11 | swagger.service.contact.name=Haojun Ren 12 | swagger.service.contact.url=https://github.com/Nepxion/Skeleton 13 | swagger.service.contact.email=1394997@qq.com -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/shared/file.gitattributes.template: -------------------------------------------------------------------------------- 1 | # Declare files that will always have UNIX line endings on checkout. 2 | *.sh text eol=lf -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/shared/file.gitignore.template: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | .classpath 4 | .springBeans 5 | # Mobile Tools for Java (J2ME) 6 | .mtj.tmp/ 7 | 8 | *.class 9 | *.classpath 10 | *.project 11 | *.springBeans 12 | log/ 13 | test-output/ 14 | 15 | # Package Files # 16 | *.jar 17 | *.war 18 | *.ear 19 | *.zip 20 | *.tar.gz 21 | *.rar 22 | *.swp 23 | *.log 24 | *.ctxt 25 | # nodejs local modules 26 | .tags* 27 | .idea/ 28 | *.iml 29 | .gradle/ 30 | .settings/ 31 | target/ 32 | hs_err_pid* -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/main/resources/springcloud/template/shared/resources/logback.xml.template: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ${serviceName} %date %level [%thread] %logger{10} [%file:%line] - %msg%n 8 | UTF-8 9 | 10 | 11 | log/${serviceName}-%d{yyyy-MM-dd}.%i.log 12 | 50MB 13 | 14 | 15 | INFO 16 | 17 | 18 | true 19 | 20 | 21 | 22 | 0 23 | 512 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | ${serviceName} %date %level [%thread] %logger{10} [%file:%line] - %msg%n 32 | UTF-8 33 | 34 | 35 | 36 | INFO 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/test/java/com/nepxion/skeleton/plugin/springcloud/SkeletonTest.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.plugin.springcloud; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 13 | import com.nepxion.skeleton.engine.context.SkeletonContext; 14 | import com.nepxion.skeleton.engine.property.SkeletonProperties; 15 | import com.nepxion.skeleton.engine.util.SkeletonUtil; 16 | import com.nepxion.skeleton.framework.service.SkeletonService; 17 | import com.nepxion.skeleton.plugin.springcloud.impl.SpringcloudServiceImpl; 18 | 19 | public class SkeletonTest { 20 | public static void main(String[] args) throws Exception { 21 | // ********** 构建全局上下文对象 ********** 22 | // 创建文件的输出的路径 23 | // 放在操作系统的临时目录下 24 | String generatePath = SkeletonUtil.getTempGeneratePath(); 25 | // String generatePath = "E:/Download/skeleton/"; 26 | 27 | // 如何理解prefixTemplatePath和reducedTemplatePath含义? 28 | // FreeMarker规定,模板文件必须放在classpath下,即以com/...开头的路径为其classpath 29 | // 1. 有需求要求,模板文件移动到resources中,并希望放在template/com/a/b/c...,那么template就是prefixTemplatePath,模板的前置路径 30 | // 2. 有需求要求,模板文件路径如果template/com/a/b/c/...,觉得路径太长,那么a/b/c/就是reducedTemplatePath,模板路径缩减,把这部分裁剪掉 31 | // 3. 如果把模板文件和Generator类放在一起,则prefixTemplatePath和reducedTemplatePath同时为null即可 32 | 33 | // 模板文件所在的前置路径 34 | String prefixTemplatePath = "springcloud/template"; 35 | // String prefixTemplatePath = null; 36 | 37 | // 模板路径缩减 38 | String reducedTemplatePath = "com/nepxion/skeleton/plugin/springcloud/generator/"; 39 | // String reducedTemplatePath = null; 40 | 41 | // 全局上下文对象 42 | SkeletonContext skeletonContext = new SkeletonContext(generatePath, prefixTemplatePath, reducedTemplatePath); 43 | // ************************************** 44 | 45 | // ********** 构建全局配置类对象 ********** 46 | // 描述规则的配置文件所在的路径 47 | // 配置文件含中文,stringEncoding必须为GBK,readerEncoding必须为UTF-8,文本文件编码必须为ANSI 48 | String propertiesPath = "springcloud/config/skeleton-data.properties"; 49 | 50 | // 全局配置类对象 51 | SkeletonProperties skeletonProperties = new SkeletonProperties(propertiesPath, SkeletonConstant.ENCODING_GBK, SkeletonConstant.ENCODING_UTF_8); 52 | // ************************************** 53 | 54 | // 输出脚手架文件 55 | SkeletonService skeletonService = new SpringcloudServiceImpl(); 56 | skeletonService.generate(skeletonContext, skeletonProperties); 57 | } 58 | } -------------------------------------------------------------------------------- /skeleton-plugin-springcloud/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${PID:- } --- [%15.15t] %-40.40logger{39} : %msg%n 8 | 9 | UTF-8 10 | 11 | 12 | log/skeleton-%d{yyyy-MM-dd}.%i.log 13 | 50MB 14 | 15 | 16 | INFO 17 | 18 | 19 | true 20 | 21 | 22 | 23 | 0 24 | 512 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | %d{yyyy-MM-dd HH:mm:ss.SSS} %levelColor(%5p) %magenta(${PID:- }) --- [%15.15t] %cyan(%-40.40logger{39}) : %msg%n 34 | 35 | 36 | 37 | INFO 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /skeleton-service/src/main/java/com/nepxion/skeleton/service/SkeletonApplication.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.service; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import org.springframework.boot.autoconfigure.SpringBootApplication; 13 | import org.springframework.boot.builder.SpringApplicationBuilder; 14 | import org.springframework.context.annotation.Import; 15 | 16 | import com.nepxion.skeleton.annotation.EnableSkeleton; 17 | import com.nepxion.skeleton.plugin.springcloud.configuration.SpringCloudPluginConfiguration; 18 | 19 | @SpringBootApplication 20 | @EnableSkeleton 21 | @Import(SpringCloudPluginConfiguration.class) 22 | public class SkeletonApplication { 23 | public static void main(String[] args) { 24 | new SpringApplicationBuilder(SkeletonApplication.class).run(args); 25 | } 26 | } -------------------------------------------------------------------------------- /skeleton-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Spring cloud config 2 | spring.application.name=skeleton-spring-cloud 3 | server.port=2222 4 | 5 | eureka.instance.lease-renewal-interval-in-seconds=10 6 | eureka.instance.lease-expiration-duration-in-seconds=30 7 | 8 | eureka.client.register-with-eureka=true 9 | eureka.client.fetch-registry=false 10 | 11 | eureka.client.serviceUrl.defaultZone=http://localhost:9528/eureka/ 12 | 13 | # Skeleton config 14 | # skeleton.enabled = true 15 | skeleton.default.plugin=springcloud -------------------------------------------------------------------------------- /skeleton-service/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${PID:- } --- [%15.15t] %-40.40logger{39} : %msg%n 8 | 9 | UTF-8 10 | 11 | 12 | log/skeleton-%d{yyyy-MM-dd}.%i.log 13 | 50MB 14 | 15 | 16 | INFO 17 | 18 | 19 | true 20 | 21 | 22 | 23 | 0 24 | 512 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | %d{yyyy-MM-dd HH:mm:ss.SSS} %levelColor(%5p) %magenta(${PID:- }) --- [%15.15t] %cyan(%-40.40logger{39}) : %msg%n 34 | 35 | 36 | 37 | INFO 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /skeleton-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | skeleton-starter 5 | Nepxion Skeleton Starter 6 | jar 7 | 4.0.0 8 | Nepxion Skeleton is a generic codes and files generator based on freemaker for any text formats 9 | http://www.nepxion.com 10 | 11 | 12 | com.nepxion 13 | skeleton 14 | 2.2.2 15 | 16 | 17 | 18 | 19 | ${project.groupId} 20 | skeleton-framework 21 | 22 | 23 | 24 | ${project.groupId} 25 | matrix-aop-starter 26 | 27 | 28 | -------------------------------------------------------------------------------- /skeleton-starter/src/main/java/com/nepxion/skeleton/annotation/EnableSkeleton.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.annotation; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import java.lang.annotation.Documented; 13 | import java.lang.annotation.ElementType; 14 | import java.lang.annotation.Inherited; 15 | import java.lang.annotation.Retention; 16 | import java.lang.annotation.RetentionPolicy; 17 | import java.lang.annotation.Target; 18 | 19 | import org.springframework.context.annotation.Import; 20 | 21 | import com.nepxion.skeleton.aop.SkeletonImportSelector; 22 | 23 | @Target(ElementType.TYPE) 24 | @Retention(RetentionPolicy.RUNTIME) 25 | @Documented 26 | @Inherited 27 | @Import(SkeletonImportSelector.class) 28 | public @interface EnableSkeleton { 29 | 30 | } -------------------------------------------------------------------------------- /skeleton-starter/src/main/java/com/nepxion/skeleton/aop/SkeletonImportSelector.java: -------------------------------------------------------------------------------- 1 | package com.nepxion.skeleton.aop; 2 | 3 | /** 4 | *

Title: Nepxion Skeleton

5 | *

Description: Nepxion Skeleton For Freemarker

6 | *

Copyright: Copyright (c) 2017-2050

7 | *

Company: Nepxion

8 | * @author Haojun Ren 9 | * @version 1.0 10 | */ 11 | 12 | import org.springframework.core.Ordered; 13 | import org.springframework.core.annotation.Order; 14 | 15 | import com.nepxion.matrix.selector.AbstractImportSelector; 16 | import com.nepxion.matrix.selector.RelaxedPropertyResolver; 17 | import com.nepxion.skeleton.annotation.EnableSkeleton; 18 | import com.nepxion.skeleton.engine.constant.SkeletonConstant; 19 | 20 | @Order(Ordered.LOWEST_PRECEDENCE - 100) 21 | public class SkeletonImportSelector extends AbstractImportSelector { 22 | @Override 23 | protected boolean isEnabled() { 24 | return new RelaxedPropertyResolver(getEnvironment()).getProperty(SkeletonConstant.SKELETON_ENABLED, Boolean.class, Boolean.TRUE); 25 | } 26 | } -------------------------------------------------------------------------------- /skeleton-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | com.nepxion.skeleton.annotation.EnableSkeleton=\ 2 | com.nepxion.skeleton.framework.configuration.SkeletonConfiguration -------------------------------------------------------------------------------- /version.bat: -------------------------------------------------------------------------------- 1 | @echo on 2 | @echo ============================================================= 3 | @echo $ $ 4 | @echo $ Nepxion Skeleton $ 5 | @echo $ $ 6 | @echo $ $ 7 | @echo $ $ 8 | @echo $ Nepxion Studio All Right Reserved $ 9 | @echo $ Copyright (C) 2017-2050 $ 10 | @echo $ $ 11 | @echo ============================================================= 12 | @echo. 13 | @echo off 14 | 15 | @title Nepxion Skeleton 16 | @color 0a 17 | 18 | call mvn versions:set -DgenerateBackupPoms=false -DnewVersion=2.2.2 19 | 20 | pause --------------------------------------------------------------------------------