├── .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