├── .gitignore
├── README.md
├── codegen-common
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── cn
│ │ └── springcloud
│ │ └── codegen
│ │ ├── annotation
│ │ ├── CodeGenCube.java
│ │ └── CodeGenPlugin.java
│ │ └── utils
│ │ ├── ProjectConfig.java
│ │ └── ProjectConfigHelper.java
│ └── test
│ └── java
│ └── cn
│ └── springcloud
│ └── codegen
│ └── AppTest.java
├── codegen-config
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── cn
│ │ └── springcloud
│ │ └── codegen
│ │ └── App.java
│ └── test
│ └── java
│ └── cn
│ └── springcloud
│ └── codegen
│ └── AppTest.java
├── codegen-docs
├── design
│ └── README.md
├── images
│ └── README.md
└── pom.xml
├── codegen-engine
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── cn
│ │ │ └── springcloud
│ │ │ └── codegen
│ │ │ └── engine
│ │ │ ├── component
│ │ │ └── CodeGenComponent.java
│ │ │ ├── config
│ │ │ └── FileConfig.java
│ │ │ ├── constants
│ │ │ └── CodeGenConstants.java
│ │ │ ├── entity
│ │ │ ├── BaseInputParams.java
│ │ │ ├── CodeOutType.java
│ │ │ ├── ConfigParams.java
│ │ │ ├── DependenciesGav.java
│ │ │ ├── InputParams.java
│ │ │ └── InputParamsContext.java
│ │ │ ├── exception
│ │ │ ├── CodeGenException.java
│ │ │ └── CodeGenFileException.java
│ │ │ ├── generator
│ │ │ ├── CodeGenEngineGenerator.java
│ │ │ ├── CodeGenExtendGenerator.java
│ │ │ ├── CodeGenForDataBaseGenerator.java
│ │ │ └── CodeGenForFileGenerator.java
│ │ │ ├── service
│ │ │ ├── ClassService.java
│ │ │ ├── ExtendService.java
│ │ │ ├── OutFileService.java
│ │ │ └── TemplateConfigService.java
│ │ │ ├── thread
│ │ │ └── CodeGenPool.java
│ │ │ └── tools
│ │ │ ├── ClassTools.java
│ │ │ ├── CommonTools.java
│ │ │ ├── FileTools.java
│ │ │ ├── JsonTools.java
│ │ │ ├── MapTools.java
│ │ │ ├── ObjectCopyValueToVoTools.java
│ │ │ ├── ReadXmlFileTools.java
│ │ │ └── TransforParamTools.java
│ └── resources
│ │ └── log4j.properties
│ └── test
│ ├── java
│ └── cn
│ │ └── springcloud
│ │ └── codegen
│ │ └── engine
│ │ ├── ConfigForInputParamsCodeGenConfigTest.java
│ │ ├── EurekaForInputParamsCodeGenConfigTest.java
│ │ ├── EurekaWithFeignTest.java
│ │ ├── FeignCodeGenTest.java
│ │ └── feign
│ │ ├── FeignAssemblyGenerator.java
│ │ ├── FeignDataGenerator.java
│ │ ├── FeignFileGenerator.java
│ │ └── FeignPomDataGenerator.java
│ └── resources
│ └── templates
│ ├── config
│ ├── java
│ │ └── ConfigApplication.java.ftl
│ ├── pom.xml.ftl
│ └── resources
│ │ └── application.properties.ftl
│ ├── eureka
│ ├── java
│ │ └── EurekaApplication.java.ftl
│ ├── pom.xml.ftl
│ └── resources
│ │ └── application.properties.ftl
│ ├── feign
│ └── java
│ │ └── UserServiceFeignClient.java.ftl
│ └── xml_config
│ ├── config_component_xml.xml
│ ├── eureka_component_xml.xml
│ └── feign_component_xml.xml
├── codegen-ui
├── .babelrc
├── .editorconfig
├── .gitignore
├── .postcssrc.js
├── LICENSE
├── README.md
├── build
│ ├── build.js
│ ├── check-versions.js
│ ├── logo.png
│ ├── utils.js
│ ├── vue-loader.conf.js
│ ├── webpack.base.conf.js
│ ├── webpack.dev.conf.js
│ ├── webpack.prod.conf.js
│ ├── webpack.remote.conf.js
│ └── webpack.v2.conf.js
├── config
│ ├── dev.env.js
│ ├── index.js
│ ├── prod.env.js
│ ├── remote.env.js
│ └── version.env.js
├── index.html
├── package-lock.json
├── package.json
├── src
│ ├── App.vue
│ ├── api
│ │ ├── api.js
│ │ └── index.js
│ ├── assets
│ │ ├── bg1.jpg
│ │ ├── logo.png
│ │ ├── logo4.png
│ │ ├── sw-footer-sprite1.png
│ │ ├── theme
│ │ │ ├── theme-darkblue
│ │ │ │ ├── alert.css
│ │ │ │ ├── autocomplete.css
│ │ │ │ ├── badge.css
│ │ │ │ ├── base.css
│ │ │ │ ├── breadcrumb-item.css
│ │ │ │ ├── breadcrumb.css
│ │ │ │ ├── button-group.css
│ │ │ │ ├── button.css
│ │ │ │ ├── card.css
│ │ │ │ ├── carousel-item.css
│ │ │ │ ├── carousel.css
│ │ │ │ ├── cascader.css
│ │ │ │ ├── checkbox-group.css
│ │ │ │ ├── checkbox.css
│ │ │ │ ├── col.css
│ │ │ │ ├── collapse-item.css
│ │ │ │ ├── collapse.css
│ │ │ │ ├── color-picker.css
│ │ │ │ ├── date-picker.css
│ │ │ │ ├── dialog.css
│ │ │ │ ├── dropdown-item.css
│ │ │ │ ├── dropdown-menu.css
│ │ │ │ ├── dropdown.css
│ │ │ │ ├── fonts
│ │ │ │ │ ├── element-icons.ttf
│ │ │ │ │ └── element-icons.woff
│ │ │ │ ├── form-item.css
│ │ │ │ ├── form.css
│ │ │ │ ├── icon.css
│ │ │ │ ├── index.css
│ │ │ │ ├── input-number.css
│ │ │ │ ├── input.css
│ │ │ │ ├── loading.css
│ │ │ │ ├── menu-item-group.css
│ │ │ │ ├── menu-item.css
│ │ │ │ ├── menu.css
│ │ │ │ ├── message-box.css
│ │ │ │ ├── message.css
│ │ │ │ ├── notification.css
│ │ │ │ ├── option-group.css
│ │ │ │ ├── option.css
│ │ │ │ ├── pagination.css
│ │ │ │ ├── popover.css
│ │ │ │ ├── progress.css
│ │ │ │ ├── radio-button.css
│ │ │ │ ├── radio-group.css
│ │ │ │ ├── radio.css
│ │ │ │ ├── rate.css
│ │ │ │ ├── reset.css
│ │ │ │ ├── row.css
│ │ │ │ ├── scrollbar.css
│ │ │ │ ├── select-dropdown.css
│ │ │ │ ├── select.css
│ │ │ │ ├── slider.css
│ │ │ │ ├── spinner.css
│ │ │ │ ├── step.css
│ │ │ │ ├── steps.css
│ │ │ │ ├── submenu.css
│ │ │ │ ├── switch.css
│ │ │ │ ├── tab-pane.css
│ │ │ │ ├── table-column.css
│ │ │ │ ├── table.css
│ │ │ │ ├── tabs.css
│ │ │ │ ├── tag.css
│ │ │ │ ├── time-picker.css
│ │ │ │ ├── time-select.css
│ │ │ │ ├── tooltip.css
│ │ │ │ ├── tree.css
│ │ │ │ └── upload.css
│ │ │ └── theme-green
│ │ │ │ ├── alert.css
│ │ │ │ ├── autocomplete.css
│ │ │ │ ├── badge.css
│ │ │ │ ├── base.css
│ │ │ │ ├── breadcrumb-item.css
│ │ │ │ ├── breadcrumb.css
│ │ │ │ ├── button-group.css
│ │ │ │ ├── button.css
│ │ │ │ ├── card.css
│ │ │ │ ├── carousel-item.css
│ │ │ │ ├── carousel.css
│ │ │ │ ├── cascader.css
│ │ │ │ ├── checkbox-group.css
│ │ │ │ ├── checkbox.css
│ │ │ │ ├── col.css
│ │ │ │ ├── collapse-item.css
│ │ │ │ ├── collapse.css
│ │ │ │ ├── color-picker.css
│ │ │ │ ├── date-picker.css
│ │ │ │ ├── dialog.css
│ │ │ │ ├── dropdown-item.css
│ │ │ │ ├── dropdown-menu.css
│ │ │ │ ├── dropdown.css
│ │ │ │ ├── fonts
│ │ │ │ ├── element-icons.ttf
│ │ │ │ └── element-icons.woff
│ │ │ │ ├── form-item.css
│ │ │ │ ├── form.css
│ │ │ │ ├── icon.css
│ │ │ │ ├── index.css
│ │ │ │ ├── input-number.css
│ │ │ │ ├── input.css
│ │ │ │ ├── loading.css
│ │ │ │ ├── menu-item-group.css
│ │ │ │ ├── menu-item.css
│ │ │ │ ├── menu.css
│ │ │ │ ├── message-box.css
│ │ │ │ ├── message.css
│ │ │ │ ├── notification.css
│ │ │ │ ├── option-group.css
│ │ │ │ ├── option.css
│ │ │ │ ├── pagination.css
│ │ │ │ ├── popover.css
│ │ │ │ ├── progress.css
│ │ │ │ ├── radio-button.css
│ │ │ │ ├── radio-group.css
│ │ │ │ ├── radio.css
│ │ │ │ ├── rate.css
│ │ │ │ ├── reset.css
│ │ │ │ ├── row.css
│ │ │ │ ├── scrollbar.css
│ │ │ │ ├── select-dropdown.css
│ │ │ │ ├── select.css
│ │ │ │ ├── slider.css
│ │ │ │ ├── spinner.css
│ │ │ │ ├── step.css
│ │ │ │ ├── steps.css
│ │ │ │ ├── submenu.css
│ │ │ │ ├── switch.css
│ │ │ │ ├── tab-pane.css
│ │ │ │ ├── table-column.css
│ │ │ │ ├── table.css
│ │ │ │ ├── tabs.css
│ │ │ │ ├── tag.css
│ │ │ │ ├── time-picker.css
│ │ │ │ ├── time-select.css
│ │ │ │ ├── tooltip.css
│ │ │ │ ├── tree.css
│ │ │ │ └── upload.css
│ │ └── user.png
│ ├── common
│ │ └── js
│ │ │ └── util.js
│ ├── components
│ │ └── .gitkeep
│ ├── main.js
│ ├── mock
│ │ ├── data
│ │ │ └── user.js
│ │ ├── index.js
│ │ └── mock.js
│ ├── routes.js
│ ├── styles
│ │ └── vars.scss
│ ├── views
│ │ ├── 404.vue
│ │ ├── Home.vue
│ │ ├── Login.vue
│ │ ├── Main.vue
│ │ ├── charts
│ │ │ └── echarts.vue
│ │ ├── footer.vue
│ │ ├── nav1
│ │ │ ├── Form.vue
│ │ │ ├── FormTest.vue
│ │ │ └── user.vue
│ │ ├── nav2
│ │ │ └── Page5.vue
│ │ └── nav3
│ │ │ └── Page6.vue
│ └── vuex
│ │ ├── actions.js
│ │ ├── getters.js
│ │ └── store.js
└── static
│ ├── .gitkeep
│ ├── css
│ ├── animate.min.css
│ ├── bootstrap.min.css
│ ├── default.css
│ ├── font-awesome.min.css
│ └── style.min.css
│ └── js
│ ├── bootstrap.min.js
│ ├── jquery.js
│ └── jquery.min.js
├── codegen-web
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── cn
│ │ └── springcloud
│ │ └── codegen
│ │ ├── SmartCodeGenApplication.java
│ │ └── config
│ │ └── EnableSwaggerConfig.java
│ └── resources
│ ├── application.properties
│ └── logback.xml
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | # Output Directory
2 | bin/
3 | target/
4 | tmp/
5 |
6 | # C pre-compile
7 | *.gch
8 | *.pch
9 |
10 | # C compile
11 | *.a
12 | *.o
13 | *.ko
14 | *.la
15 | *.lo
16 | *.obj
17 | *.elf
18 | *.so
19 | *.so.*
20 | *.dylib
21 | *.exe
22 | *.lib
23 | *.dll
24 | *.out
25 | *.app
26 | *.hex
27 |
28 | # Debug files
29 | *.dSYM/
30 |
31 | # Java
32 | *.class
33 |
34 | # Java Package Files
35 | *.jar
36 | *.war
37 | *.ear
38 |
39 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
40 | hs_err_pid*
41 |
42 | # Zip Files
43 | *.rar
44 | *.zip
45 | *.7z
46 | *.tar
47 | *.gz
48 |
49 | # Ant
50 | #build/
51 |
52 | # Compiled Python
53 | __pycache__/
54 | *.py[cod]
55 | *py.class
56 |
57 | # Eclipse
58 | .settings/
59 | .classpath
60 | .project
61 |
62 |
63 | # IntelliJ, based on http://devnet.jetbrains.net/docs/DOC-1186
64 | .idea/
65 | *.iml
66 |
67 | # logs and trace
68 | *.log
69 | *.trace
70 | *.dat
71 |
72 | # vi swap
73 | *.swp
74 |
75 | # Backup Files
76 | *.bak
77 | *.old
78 |
79 | # SVN metadata
80 | .svn/
81 |
82 |
83 |
--------------------------------------------------------------------------------
/codegen-common/pom.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 | codegen
5 | cn.springcloud.codegen
6 | 1.0.0
7 |
8 | 4.0.0
9 |
10 | codegen-common
11 | jar
12 |
13 | codegen-common
14 | http://maven.apache.org
15 |
16 |
17 | UTF-8
18 |
19 |
20 |
21 |
22 | junit
23 | junit
24 | 3.8.1
25 | test
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/codegen-common/src/main/java/cn/springcloud/codegen/annotation/CodeGenCube.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.annotation;
2 |
3 | /**
4 | * 代码生成器CodeGenCube注解,代码生成器由一个个Cube(立方体组成)
5 | * @author xujin
6 | */
7 | public @interface CodeGenCube {
8 | }
9 |
--------------------------------------------------------------------------------
/codegen-common/src/main/java/cn/springcloud/codegen/annotation/CodeGenPlugin.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.annotation;
2 |
3 | /**
4 | * 代码生成器插件
5 | * @author xujin
6 | */
7 | public @interface CodeGenPlugin {
8 | }
9 |
--------------------------------------------------------------------------------
/codegen-common/src/main/java/cn/springcloud/codegen/utils/ProjectConfig.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.utils;
2 |
3 | import java.io.*;
4 |
5 |
6 | /**
7 | * @author xujin
8 | */
9 | public class ProjectConfig implements Serializable {
10 |
11 |
12 | /**
13 | * 使用序列化方式深度克隆项目配置模型
14 | * @return
15 | * @throws IOException
16 | * @throws ClassNotFoundException
17 | */
18 | public ProjectConfig deepClone() throws IOException, ClassNotFoundException {
19 | ProjectConfig dc = null;
20 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
21 | ObjectOutputStream oos = new ObjectOutputStream(baos);
22 | oos.writeObject(this);
23 | oos.close();
24 |
25 | ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
26 | ObjectInputStream bis = new ObjectInputStream(bais);
27 | dc = (ProjectConfig)bis.readObject();
28 | return dc;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/codegen-common/src/main/java/cn/springcloud/codegen/utils/ProjectConfigHelper.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.utils;
2 |
3 | /**
4 | * @author xujin
5 | */
6 | public class ProjectConfigHelper {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/codegen-common/src/test/java/cn/springcloud/codegen/AppTest.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestCase;
5 | import junit.framework.TestSuite;
6 |
7 | /**
8 | * Unit test for simple App.
9 | */
10 | public class AppTest
11 | extends TestCase
12 | {
13 | /**
14 | * Create the test case
15 | *
16 | * @param testName name of the test case
17 | */
18 | public AppTest( String testName )
19 | {
20 | super( testName );
21 | }
22 |
23 | /**
24 | * @return the suite of tests being tested
25 | */
26 | public static Test suite()
27 | {
28 | return new TestSuite( AppTest.class );
29 | }
30 |
31 | /**
32 | * Rigourous Test :-)
33 | */
34 | public void testApp()
35 | {
36 | assertTrue( true );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/codegen-config/pom.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 | codegen
5 | cn.springcloud.codegen
6 | 1.0.0
7 |
8 | 4.0.0
9 |
10 | codegen-config
11 | jar
12 |
13 | codegen-config
14 | http://maven.apache.org
15 |
16 |
17 | UTF-8
18 |
19 |
20 |
21 |
22 | junit
23 | junit
24 | 3.8.1
25 | test
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/codegen-config/src/main/java/cn/springcloud/codegen/App.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen;
2 |
3 | /**
4 | * Hello world!
5 | *
6 | */
7 | public class App
8 | {
9 | public static void main( String[] args )
10 | {
11 | System.out.println( "Hello World!" );
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/codegen-config/src/test/java/cn/springcloud/codegen/AppTest.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestCase;
5 | import junit.framework.TestSuite;
6 |
7 | /**
8 | * Unit test for simple App.
9 | */
10 | public class AppTest
11 | extends TestCase
12 | {
13 | /**
14 | * Create the test case
15 | *
16 | * @param testName name of the test case
17 | */
18 | public AppTest( String testName )
19 | {
20 | super( testName );
21 | }
22 |
23 | /**
24 | * @return the suite of tests being tested
25 | */
26 | public static Test suite()
27 | {
28 | return new TestSuite( AppTest.class );
29 | }
30 |
31 | /**
32 | * Rigourous Test :-)
33 | */
34 | public void testApp()
35 | {
36 | assertTrue( true );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/codegen-docs/pom.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 | codegen
5 | cn.springcloud.codegen
6 | 1.0.0
7 |
8 | 4.0.0
9 |
10 | codegen-docs
11 |
12 | Maven
13 | http://maven.apache.org/
14 | 2001
15 |
16 |
17 |
18 | website
19 | scp://webhost.company.com/www/website
20 |
21 |
22 |
23 |
24 | UTF-8
25 |
26 |
27 |
28 |
29 |
30 | maven-site-plugin
31 |
32 | en,fr
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/codegen-engine/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | codegen
7 | cn.springcloud.codegen
8 | 1.0.0
9 | ..
10 |
11 | 4.0.0
12 | codegen-engine
13 |
14 |
15 |
16 | org.freemarker
17 | freemarker
18 |
19 |
20 |
21 | dom4j
22 | dom4j
23 |
24 |
25 |
26 | com.alibaba
27 | fastjson
28 |
29 |
30 |
31 | org.apache.commons
32 | commons-lang3
33 |
34 |
35 | commons-beanutils
36 | commons-beanutils
37 |
38 |
39 |
40 | org.slf4j
41 | slf4j-log4j12
42 |
43 |
44 |
45 |
46 |
47 |
48 | org.apache.maven.plugins
49 | maven-compiler-plugin
50 |
51 | 1.6
52 | 1.6
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/component/CodeGenComponent.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.component;
2 |
3 | import cn.springcloud.codegen.engine.constants.CodeGenConstants;
4 | import cn.springcloud.codegen.engine.entity.CodeOutType;
5 | import cn.springcloud.codegen.engine.entity.InputParams;
6 | import cn.springcloud.codegen.engine.entity.InputParamsContext;
7 | import cn.springcloud.codegen.engine.generator.CodeGenExtendGenerator;
8 | import cn.springcloud.codegen.engine.generator.CodeGenForFileGenerator;
9 | import cn.springcloud.codegen.engine.tools.FileTools;
10 |
11 | import java.util.List;
12 | import java.util.Map;
13 |
14 | /**
15 | * Created with IntelliJ IDEA.
16 | *
17 | * @author: zzf
18 | * @date: 2018/1/30
19 | * @time: 16:48
20 | * @description : 组件的统一创建对象
21 | */
22 | public final class CodeGenComponent extends CodeGenForFileGenerator {
23 |
24 | private Map otherData;
25 |
26 | public CodeGenComponent(InputParamsContext context, Map templateData, Map otherData) {
27 | super(context, templateData, otherData);
28 | this.otherData = otherData;
29 | }
30 |
31 | public CodeGenComponent(InputParams inputParams, Map templateData, Map otherData) {
32 | super(inputParams, templateData, otherData);
33 | this.otherData = otherData;
34 | transforParam(inputParams);
35 | }
36 |
37 | public CodeGenComponent(InputParams inputParams, Map templateData, List extendGenerators, Map otherData) {
38 | super(inputParams, templateData, extendGenerators);
39 | this.otherData = otherData;
40 | transforParam(inputParams);
41 | }
42 |
43 | /**
44 | * 如果在templateData 中的参数为空的时候才会使用这个重写的参数
45 | * @return
46 | */
47 | @Override
48 | public Map getTemplateData() {
49 | return null;
50 | }
51 |
52 | @Override
53 | public CodeOutType isJavaOrResourcesOrOtherCode() {
54 | CodeOutType codeOutType = CodeOutType.getType(FileTools.getTypeValue(String.valueOf(otherData.get("isJavaOrResourcesOrOtherCode"))));
55 | return codeOutType != null ? codeOutType : CodeOutType.NONE;
56 | }
57 |
58 | /**
59 | * 转化参数信息
60 | * @param inputParams
61 | * @return
62 | */
63 | private void transforParam(InputParams inputParams){
64 |
65 | Object constValue = CodeGenConstants.getConstValue(FileTools.getTypeValue(inputParams.getTemplateConfigEncode()));
66 | inputParams.setTemplateConfigEncode(constValue == null ? "" : constValue.toString());
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/config/FileConfig.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.config;
2 |
3 | import cn.springcloud.codegen.engine.exception.CodeGenException;
4 | import cn.springcloud.codegen.engine.exception.CodeGenFileException;
5 |
6 | import java.io.*;
7 | import java.net.URL;
8 | import java.util.Properties;
9 |
10 | /**
11 | * Created with IntelliJ IDEA.
12 | *
13 | * @author: zzf
14 | * @date: 2018/1/18
15 | * @time: 16:04
16 | * @description : 配置文件的解析, 多种文件解析都写在这里
17 | * 例如: properties , xml, json 等文件格式的解析要支持
18 | */
19 | public class FileConfig {
20 |
21 | /**
22 | * 加载properties 资源文件
23 | * @param in 输入流
24 | * @return
25 | */
26 | public static Properties getProperties(InputStream in) {
27 | Properties properties = new Properties();
28 | try {
29 | properties.load(in);
30 | } catch (IOException e) {
31 | throw new CodeGenException("couldn't load properties file '" + in +"'", e);
32 | }
33 | return properties;
34 | }
35 |
36 | /**
37 | * 配置文件路径
38 | * @param configPath
39 | * @return
40 | */
41 | public static Properties getProperties(String configPath){
42 |
43 | try {
44 | File file = new File(configPath);
45 | InputStream in = new FileInputStream(file);
46 | return getProperties(in);
47 | } catch (FileNotFoundException e) {
48 | throw new CodeGenException("couldn't find config file in " + configPath + " " + e);
49 | }
50 | }
51 |
52 | /**
53 | *@paramurl
54 | *@return
55 | *@throwsIOException
56 | */
57 | public static InputStream getStream(URL url) throws IOException{
58 | if(url!=null){
59 | return url.openStream();
60 | }else{
61 | return null;
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/constants/CodeGenConstants.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.constants;
2 |
3 |
4 | /**
5 | * Created with IntelliJ IDEA.
6 | *
7 | * @author: zzf
8 | * @date: 2018/1/17
9 | * @time: 15:57
10 | * @description : 全局常量
11 | */
12 | public class CodeGenConstants {
13 |
14 | /**
15 | * 默认编码的格式
16 | */
17 | public static final String DEFAULT_ENCODE = "UTF-8";
18 |
19 | /**
20 | * 默认的模板名称
21 | */
22 | public static final String DEFAULT_TEMPLATE_POSTFIX = "ftl";
23 |
24 | /**
25 | * 文件分隔符
26 | */
27 | public static final String POINT_STR = ".";
28 |
29 | /**
30 | * 文件切个类型
31 | */
32 | public static final String FILE_SEPARATOR = "/";
33 |
34 | public static final String CLASS_ANNOTATION_KEY = "classAnnotationKey";
35 |
36 | public static final String CLASS_IMPORT_KEY = "classImportKey";
37 |
38 | public static final String POM_DEPENDENCY_KEY = "pomDependencyKey";
39 |
40 | /**
41 | * 生成目录下的片接
42 | */
43 | public static final String MAIN_JAVA_PATH = "src" + FILE_SEPARATOR + "main" + FILE_SEPARATOR + "java" + FILE_SEPARATOR;
44 | public static final String MAIN_RESOURCE_PATH = "src" + FILE_SEPARATOR + "main" + FILE_SEPARATOR + "resources" + FILE_SEPARATOR;
45 | public static final String TEST_JAVA_PATH = "src" + FILE_SEPARATOR + "test" + FILE_SEPARATOR + "java" + FILE_SEPARATOR;
46 | public static final String TEST_RESOURCES_PATH = "src" + FILE_SEPARATOR + "test" + FILE_SEPARATOR + "resources" + FILE_SEPARATOR;
47 |
48 | /**
49 | * 获取静态的常量属性
50 | * @param field
51 | * @return
52 | */
53 | public static Object getConstValue(String field){
54 | try {
55 | // null 表示的是static的
56 | return CodeGenConstants.class.getField(field).get(null);
57 | } catch (Exception e) {
58 |
59 | }
60 | return null;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/entity/BaseInputParams.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.entity;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created with IntelliJ IDEA.
7 | *
8 | * @author: zzf
9 | * @date: 2018/1/18
10 | * @time: 15:38
11 | * @description : 输入参数的基础类型(这里的输出参数不是指模板文件的参数)
12 | */
13 | public class BaseInputParams implements Serializable{
14 |
15 | private static final long serialVersionUID = 2822361127561108856L;
16 | private String templateName;
17 | private String fileName;
18 | private String fileType;
19 | private String dynamicOutPath;
20 | private String moduleName;
21 | private String packageName;
22 |
23 | public BaseInputParams(String templateName, String fileName, String fileType, String dynamicOutPath, String moduleName, String packageName) {
24 | this.templateName = templateName;
25 | this.fileName = fileName;
26 | this.fileType = fileType;
27 | this.dynamicOutPath = dynamicOutPath;
28 | this.moduleName = moduleName;
29 | this.packageName = packageName;
30 | }
31 |
32 | public BaseInputParams() {}
33 |
34 | public String getTemplateName() {
35 | return templateName;
36 | }
37 |
38 | public void setTemplateName(String templateName) {
39 | this.templateName = templateName;
40 | }
41 |
42 | public String getFileName() {
43 | return fileName;
44 | }
45 |
46 | public void setFileName(String fileName) {
47 | this.fileName = fileName;
48 | }
49 |
50 | public String getFileType() {
51 | return fileType;
52 | }
53 |
54 | public void setFileType(String fileType) {
55 | this.fileType = fileType;
56 | }
57 |
58 | public String getDynamicOutPath() {
59 | return dynamicOutPath;
60 | }
61 |
62 | public void setDynamicOutPath(String dynamicOutPath) {
63 | this.dynamicOutPath = dynamicOutPath;
64 | }
65 |
66 | public String getModuleName() {
67 | return moduleName;
68 | }
69 |
70 | public void setModuleName(String moduleName) {
71 | this.moduleName = moduleName;
72 | }
73 |
74 | public String getPackageName() {
75 | return packageName;
76 | }
77 |
78 | public void setPackageName(String packageName) {
79 | this.packageName = packageName;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/entity/CodeOutType.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.entity;
2 |
3 | import cn.springcloud.codegen.engine.constants.CodeGenConstants;
4 |
5 | /**
6 | * Created with IntelliJ IDEA.
7 | *
8 | * @author: zzf
9 | * @date: 2018/1/21
10 | * @time: 18:11
11 | * @description :
12 | * 代码的类型 :
13 | * 1. java : src/main/java
14 | * 2. resources : src/main/resources
15 | * 3. none : 不添加任何目录
16 | * 4. test_java : src/test/java
17 | * 5. test_resources : src/test/resources
18 | */
19 | public enum CodeOutType {
20 |
21 | JAVA(CodeGenConstants.MAIN_JAVA_PATH, "java文件夹下的目录"),
22 | RESOURCES(CodeGenConstants.MAIN_RESOURCE_PATH, "resources文件夹下的目录"),
23 | NONE("", "其他文件类型的生成, 不考虑添加额外的目录"),
24 | TEST_JAVA(CodeGenConstants.TEST_JAVA_PATH, "test文件夹下的 java 目录"),
25 | TEST_RESOURCES(CodeGenConstants.TEST_RESOURCES_PATH, "test文件夹下的 resources目录");
26 |
27 | private final String key;
28 | private final String value;
29 |
30 | private CodeOutType(String key, String value) {
31 | this.value = value;
32 | this.key = key;
33 | }
34 |
35 | public String getKey() {
36 | return key;
37 | }
38 |
39 | public String getValue() {
40 | return value;
41 | }
42 |
43 | /**
44 | * 通过value 反查 key
45 | * @param value
46 | * @return
47 | */
48 | public static String getLabelByValue(String value){
49 | CodeOutType[] types = CodeOutType.values();
50 | for (int i = 0; i < types.length; i++) {
51 | if(types[i].value.equals(value)){
52 | return types[i].getKey();
53 | }
54 | }
55 | return "";
56 | }
57 |
58 | /**
59 | * 获取枚举的属性
60 | * @param type
61 | * @return
62 | */
63 | public static CodeOutType getType(String type){
64 | CodeOutType[] types = CodeOutType.values();
65 | for (int i = 0; i < types.length; i++) {
66 | if(types[i].toString().equals(type)){
67 | return types[i];
68 | }
69 | }
70 | System.out.println("CodeOutType中,未找到对应的枚举属性");
71 | return null;
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/entity/ConfigParams.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.entity;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created with IntelliJ IDEA.
7 | *
8 | * @author: zzf
9 | * @date: 2018/1/24
10 | * @time: 15:20
11 | * @description : 配置文件的参数参数转化, 全部转字符串, 可以通过fastJson 转化在转化成对应的构造bean即可
12 | */
13 | public class ConfigParams implements Serializable {
14 |
15 | private static final long serialVersionUID = 6380397981444700402L;
16 |
17 | /**
18 | * 初始化需要的参数
19 | */
20 | private String initData;
21 |
22 | /**
23 | * 模板需要的参数
24 | */
25 | private String templateData;
26 |
27 | /**
28 | * 其他的补充参数
29 | */
30 | private String otherData;
31 |
32 | public String getInitData() {
33 | return initData;
34 | }
35 |
36 | public void setInitData(String initData) {
37 | this.initData = initData;
38 | }
39 |
40 | public String getTemplateData() {
41 | return templateData;
42 | }
43 |
44 | public void setTemplateData(String templateData) {
45 | this.templateData = templateData;
46 | }
47 |
48 | public String getOtherData() {
49 | return otherData;
50 | }
51 |
52 | public void setOtherData(String otherData) {
53 | this.otherData = otherData;
54 | }
55 |
56 | @Override
57 | public String toString() {
58 | return "ConfigParams{" +
59 | "initData='" + initData + '\'' +
60 | ", templateData='" + templateData + '\'' +
61 | ", otherData='" + otherData + '\'' +
62 | '}';
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/entity/DependenciesGav.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.entity;
2 |
3 | /**
4 | * @author Vincent.
5 | * @createdOn 2018/01/27 17:50
6 | */
7 | public class DependenciesGav {
8 |
9 | private String groupId;
10 |
11 | private String artifactId;
12 |
13 | private String version;
14 |
15 | public String getGroupId() {
16 | return groupId;
17 | }
18 |
19 | public void setGroupId(String groupId) {
20 | this.groupId = groupId;
21 | }
22 |
23 | public String getArtifactId() {
24 | return artifactId;
25 | }
26 |
27 | public void setArtifactId(String artifactId) {
28 | this.artifactId = artifactId;
29 | }
30 |
31 | public String getVersion() {
32 | return version;
33 | }
34 |
35 | public void setVersion(String version) {
36 | this.version = version;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/entity/InputParams.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.entity;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created with IntelliJ IDEA.
7 | *
8 | * @author: zzf
9 | * @date: 2018/1/17
10 | * @time: 19:27
11 | * @description : 子类的输出参数, 模板和输出路径等自定义在任何地方
12 | */
13 | public class InputParams extends BaseInputParams implements Serializable{
14 |
15 | private static final long serialVersionUID = -1377887339408890399L;
16 | private String templateConfigEncode;
17 | private String templateDir;
18 |
19 |
20 | public InputParams(String templateConfigEncode, String dynamicOutPath,
21 | String templateDir, String packageName,String templateName,
22 | String fileName, String fileType, String moduleName) {
23 |
24 | // 父类的构造方法
25 | super(templateName, fileName, fileType, dynamicOutPath, moduleName, packageName);
26 | this.templateConfigEncode = templateConfigEncode;
27 | this.templateDir = templateDir;
28 | }
29 |
30 | public InputParams(){}
31 |
32 | public String getTemplateConfigEncode() {
33 | return templateConfigEncode;
34 | }
35 |
36 | public void setTemplateConfigEncode(String templateConfigEncode) {
37 | this.templateConfigEncode = templateConfigEncode;
38 | }
39 |
40 | public String getTemplateDir() {
41 | return templateDir;
42 | }
43 |
44 | public void setTemplateDir(String templateDir) {
45 | this.templateDir = templateDir;
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/entity/InputParamsContext.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.entity;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created with IntelliJ IDEA.
7 | *
8 | * @author: zzf
9 | * @date: 2018/1/18
10 | * @time: 11:54
11 | * @description : 主要是使用于模板文件和操作类所在的路径一致的情况下使用
12 | */
13 | public class InputParamsContext extends BaseInputParams implements Serializable{
14 |
15 | private static final long serialVersionUID = 8790588232535807382L;
16 | private String prefixTemplatePath;
17 | private String reducedTemplatePath;
18 | private Class> currentClasses;
19 |
20 | public InputParamsContext(String templateName,String fileName, String fileType, String dynamicOutPath, String moduleName,
21 | String prefixTemplatePath, String reducedTemplatePath, Class> currentClasses, String packageName) {
22 | super(templateName, fileName, fileType, dynamicOutPath, moduleName, packageName);
23 | this.prefixTemplatePath = prefixTemplatePath;
24 | this.reducedTemplatePath = reducedTemplatePath;
25 | this.currentClasses = currentClasses;
26 | }
27 |
28 | /**
29 | * 这个需要set 方法设置 dynamicOutPath, moduleName,fileType 参数
30 | * templateName, fileName, templateDir 使用当前类的共同属性
31 | *
32 | * @param prefixTemplatePath 模板的前缀
33 | * @param reducedTemplatePath 缩减路径
34 | * @param currentClasses 当前类的class
35 | */
36 | public InputParamsContext(String prefixTemplatePath, String reducedTemplatePath, Class> currentClasses) {
37 | this.prefixTemplatePath = prefixTemplatePath;
38 | this.reducedTemplatePath = reducedTemplatePath;
39 | this.currentClasses = currentClasses;
40 | }
41 |
42 | /**
43 | * 默认的缩减路径为类所在的路径
44 | * 生成的的名字默认为类名
45 | * 模板名称默认为类名称+ftl
46 | *
47 | * @param prefixTemplatePath
48 | * @param currentClasses
49 | */
50 | public InputParamsContext(String prefixTemplatePath, Class> currentClasses) {
51 | this.prefixTemplatePath = prefixTemplatePath;
52 | this.currentClasses = currentClasses;
53 | }
54 |
55 | public InputParamsContext() {}
56 |
57 | public String getPrefixTemplatePath() {
58 | return prefixTemplatePath;
59 | }
60 |
61 | public void setPrefixTemplatePath(String prefixTemplatePath) {
62 | this.prefixTemplatePath = prefixTemplatePath;
63 | }
64 |
65 | public String getReducedTemplatePath() {
66 | return reducedTemplatePath;
67 | }
68 |
69 | public void setReducedTemplatePath(String reducedTemplatePath) {
70 | this.reducedTemplatePath = reducedTemplatePath;
71 | }
72 |
73 | public Class> getCurrentClasses() {
74 | return currentClasses;
75 | }
76 |
77 | public void setCurrentClasses(Class> currentClasses) {
78 | this.currentClasses = currentClasses;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/exception/CodeGenException.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.exception;
2 |
3 | /**
4 | * Created with IntelliJ IDEA.
5 | *
6 | * @author: zzf
7 | * @date: 2018/1/17
8 | * @time: 15:50
9 | * @description : 生成异常类
10 | */
11 | public class CodeGenException extends RuntimeException {
12 |
13 | private static final long serialVersionUID = 1776723636365101508L;
14 | private String code;
15 | private String msg;
16 |
17 | public CodeGenException(String message){
18 | super(message);
19 | }
20 |
21 | public CodeGenException(String message, Throwable cause){
22 | super(message, cause);
23 | }
24 |
25 | public CodeGenException(String code, String msg) {
26 | super(msg);
27 | this.code = code;
28 | this.msg = msg;
29 | }
30 |
31 | public String getCode() {
32 | return code;
33 | }
34 |
35 | public String getMsg() {
36 | return msg;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/exception/CodeGenFileException.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.exception;
2 |
3 | import javax.annotation.processing.FilerException;
4 |
5 | /**
6 | * Created with IntelliJ IDEA.
7 | *
8 | * @author: zzf
9 | * @date: 2018/1/17
10 | * @time: 16:17
11 | * @description : 模板文件和生成文件异常
12 | */
13 | public class CodeGenFileException extends Exception {
14 |
15 | private static final long serialVersionUID = 206605161158992130L;
16 |
17 | public CodeGenFileException(String message){
18 | super(message);
19 | }
20 |
21 | public CodeGenFileException(String message, Throwable cause){
22 | super(message, cause);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/generator/CodeGenExtendGenerator.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.generator;
2 |
3 | import cn.springcloud.codegen.engine.service.ExtendService;
4 |
5 | import java.util.Map;
6 |
7 | /**
8 | * @author Vincent.
9 | * @createdOn 2018/01/27 15:52
10 | */
11 | public abstract class CodeGenExtendGenerator implements ExtendService {
12 |
13 | @Override
14 | public abstract Map getExtendData();
15 |
16 | /**
17 | * 扩展数据作用文件标识,可用作将改数据作用到指定文件上
18 | * @return
19 | */
20 | public abstract String targetIdentifier();
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/generator/CodeGenForDataBaseGenerator.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.generator;
2 |
3 | /**
4 | * Created with IntelliJ IDEA.
5 | *
6 | * @author: zzf
7 | * @date: 2018/1/17
8 | * @time: 18:27
9 | * @description : 数据库的代码生成器
10 | */
11 | public class CodeGenForDataBaseGenerator {
12 |
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/service/ClassService.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.service;
2 |
3 | /**
4 | * Created with IntelliJ IDEA.
5 | *
6 | * @author: zzf
7 | * @date: 2018/1/18
8 | * @time: 11:08
9 | * @description : 类的服务, 主要是完成类的
10 | */
11 | public interface ClassService {
12 |
13 | String getModuleName();
14 |
15 | String getPackageName();
16 | }
17 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/service/ExtendService.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.service;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * @author Vincent.
7 | * @createdOn 2018/01/27 15:24
8 | */
9 | public interface ExtendService {
10 |
11 | Map getExtendData();
12 | }
13 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/service/OutFileService.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.service;
2 |
3 | import java.io.File;
4 |
5 | /**
6 | * Created with IntelliJ IDEA.
7 | *
8 | * @author: zzf
9 | * @date: 2018/1/17
10 | * @time: 16:08
11 | * @description : 输出文件接口
12 | */
13 | public interface OutFileService {
14 |
15 | String getDynamicOutPath();
16 |
17 | String getFileName();
18 |
19 | String getFileType();
20 | }
21 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/service/TemplateConfigService.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.service;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * Created with IntelliJ IDEA.
7 | *
8 | * @author: zzf
9 | * @date: 2018/1/17
10 | * @time: 15:58
11 | * @description : 模板配置的接口
12 | */
13 | public interface TemplateConfigService {
14 |
15 | String getTemplateDir();
16 |
17 | String getTemplateName();
18 |
19 | Map getData();
20 | }
21 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/thread/CodeGenPool.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.thread;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 |
6 | import java.util.concurrent.*;
7 |
8 | /**
9 | * Created with IntelliJ IDEA.
10 | *
11 | * @author: zzf
12 | * @date: 2018/1/18
13 | * @time: 13:27
14 | * @description : 代码生成器的线程池
15 | */
16 | public class CodeGenPool {
17 |
18 | private final Logger logger = LoggerFactory.getLogger(CodeGenPool.class);
19 |
20 | /**
21 | * 线程池的大小默认为, CPU核数 * 2
22 | */
23 | public static int DEFAULT_POOL_SIZE = Runtime.getRuntime().availableProcessors() * 2;
24 | private static CodeGenPool instance = null;
25 | private ExecutorService executors = null;
26 |
27 | private CodeGenPool(){
28 | this.executors = Executors.newFixedThreadPool(DEFAULT_POOL_SIZE);
29 | }
30 |
31 | public static CodeGenPool getInstance(){
32 | if(instance == null){
33 | synchronized (CodeGenPool.class){
34 | if(instance == null){
35 | instance = new CodeGenPool();
36 | }
37 | }
38 | }
39 |
40 | return instance;
41 | }
42 |
43 | /**
44 | * 执行生成任务
45 | * @param callable
46 | * @param
47 | * @return
48 | */
49 | public Future submit(Callable callable){
50 | return this.executors.submit(callable);
51 | }
52 |
53 | /**
54 | * 获取线程池大小
55 | * @return 线程池大小
56 | */
57 | public static int size() {
58 | return DEFAULT_POOL_SIZE;
59 | }
60 |
61 | /**
62 | * 销毁线程池
63 | */
64 | public static void destroy() {
65 | if (instance != null) {
66 | instance.executors.shutdown();
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/tools/ClassTools.java:
--------------------------------------------------------------------------------
1 |
2 | package cn.springcloud.codegen.engine.tools;
3 |
4 | import org.apache.commons.logging.Log;
5 | import org.apache.commons.logging.LogFactory;
6 |
7 | import java.net.URL;
8 |
9 | /**
10 | * Created with IntelliJ IDEA.
11 | *
12 | * @author: zzf
13 | * @date: 2018/1/18
14 | * @time: 19:50
15 | * @description : 公共方法存放类
16 | */
17 | public class ClassTools {
18 |
19 | private static Log log= LogFactory.getLog(ClassTools.class);
20 |
21 | /**
22 | * 加载Java类。 使用全限定类名
23 | *@paramclassName
24 | *@return
25 | */
26 | public static Class loadClass(String className) {
27 | try {
28 | return getClassLoader().loadClass(className);
29 | } catch (ClassNotFoundException e) {
30 | throw new RuntimeException("class not found '"+className+"'", e);
31 | }
32 | }
33 | /**
34 | *得到类加载器
35 | *@return
36 | */
37 | public static ClassLoader getClassLoader() {
38 | return ClassTools.class.getClassLoader();
39 | }
40 |
41 | /**
42 | * 得到本Class所在的ClassLoader的Classpat的绝对路径。
43 | * URL形式的
44 | * @return
45 | */
46 | public static String getAbsolutePathOfClassLoaderClassPath(){
47 | ClassTools.log.info(ClassTools.getClassLoader().getResource("").toString());
48 | return ClassTools.getClassLoader().getResource("").toString();
49 |
50 | }
51 |
52 | /**
53 | * 得到绝对路径的 : 例如 D://test/template/
54 | * @param clazz
55 | * @return
56 | */
57 | public static String getAbsolutePathOfClassLoaderClassPath(Class clazz){
58 | URL resource = clazz.getClassLoader().getResource("");
59 | return resource.getPath();
60 | }
61 |
62 | /**
63 | * 获取纯类名称:例如 Application.java 得到 Application
64 | * @param clazz
65 | * @return
66 | */
67 | public static String getClassSimpleName(Class clazz){
68 | return clazz.getSimpleName();
69 | }
70 |
71 | /**
72 | * 得到包名称 : 例如 cn.springcloud.engine
73 | * @param clazz
74 | * @return
75 | */
76 | public static String getClassPackageName(Class clazz){
77 | return clazz.getPackage().getName();
78 | }
79 |
80 | /**
81 | * 得到类的全路径,是 包.类名称 cn.springcloud.Application
82 | * @param clazz
83 | * @return
84 | */
85 | public static String getClassFullPath(Class clazz){
86 | return clazz.getName();
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/tools/CommonTools.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.tools;
2 |
3 | /**
4 | * Created with IntelliJ IDEA.
5 | *
6 | * @author: zzf
7 | * @date: 2018/1/18
8 | * @time: 11:26
9 | * @description : 公共方法存放类
10 | */
11 | public class CommonTools {
12 |
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/tools/FileTools.java:
--------------------------------------------------------------------------------
1 |
2 | package cn.springcloud.codegen.engine.tools;
3 |
4 | import cn.springcloud.codegen.engine.constants.CodeGenConstants;
5 | import org.apache.commons.lang3.StringUtils;
6 |
7 | import java.io.File;
8 |
9 | /**
10 | * Created with IntelliJ IDEA.
11 | *
12 | * @author: zzf
13 | * @date: 2018/1/17
14 | * @time: 20:20
15 | * @description : 文件工具类
16 | */
17 | public class FileTools {
18 |
19 | /**
20 | * 输出目录
21 | * @param dynamicOutPath
22 | * @param moduleName
23 | * @param classPackageName
24 | * @return
25 | */
26 | public static String getOutPath(String dynamicOutPath,String moduleName, String codeOutTypePath,String classPackageName){
27 |
28 | if(StringUtils.isNotBlank(classPackageName)){
29 | classPackageName = convertPackageToPath(classPackageName);
30 | }else{
31 | classPackageName = "";
32 | }
33 |
34 | StringBuilder sb = new StringBuilder();
35 | sb.append(dynamicOutPath).append(File.separator);
36 | sb.append(moduleName).append(File.separator);
37 | sb.append(codeOutTypePath).append(File.separator);
38 | sb.append(classPackageName).append(File.separator);
39 |
40 | return sb.toString().replace("\\", CodeGenConstants.FILE_SEPARATOR);
41 | }
42 |
43 | /**
44 | * 最终要出书的文件名
45 | * @param fileName
46 | * @param fileType
47 | * @return
48 | */
49 | public static String getFinalFileName(String fileName, String fileType){
50 |
51 | // 不传递文件类型的时候, 使用模板截取调后面的进行使用
52 | return StringUtils.isNotBlank(fileType) ? fileName + "." + fileType : fileName;
53 | }
54 |
55 | /**
56 | * 将包名转换成路径名称(也就是将. 转化成/)
57 | * @param packageName
58 | * @return
59 | */
60 | public static String convertPackageToPath(String packageName){
61 | if(StringUtils.isNotBlank(packageName)){
62 | return packageName.replaceAll("\\.", CodeGenConstants.FILE_SEPARATOR);
63 | }
64 | return packageName;
65 | }
66 |
67 | /**
68 | * 将路径转化成包结构
69 | * @param path
70 | * @return
71 | */
72 | public static String convertPathToPackage(String path){
73 | if(StringUtils.isNotBlank(path)){
74 | return path.replaceAll("//", ".");
75 | }
76 | return path;
77 | }
78 |
79 | /**
80 | * 获取当前系统的临时目录
81 | * @return
82 | */
83 | public static String getSysTemp(){
84 | return System.getProperty("java.io.tmpdir");
85 | }
86 |
87 |
88 | /**
89 | * 获取输出文件的名称
90 | * @param templateName
91 | * @return
92 | */
93 | public static String getOutFileName(String templateName){
94 | return templateName.substring(0, templateName.lastIndexOf("."));
95 | }
96 |
97 | /**
98 | * 截取到想要的部分字符串信息
99 | * @param finalStr
100 | * @return
101 | */
102 | public static String getTypeValue(String finalStr){
103 | return StringUtils.isNotBlank(finalStr) ? finalStr.substring(finalStr.lastIndexOf(".") + 1, finalStr.length()) : "";
104 | }
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/tools/JsonTools.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.tools;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import com.alibaba.fastjson.JSONArray;
5 | import com.alibaba.fastjson.JSONObject;
6 |
7 | import java.io.*;
8 | import java.util.Map;
9 |
10 | /**
11 | * Created with IntelliJ IDEA.
12 | *
13 | * @author: zzf
14 | * @date: 2018/1/23
15 | * @time: 22:25
16 | * @description : json 工具类,解析json 文件和将对象转化成json 对象
17 | */
18 | public class JsonTools {
19 |
20 | /**
21 | * 将对象转化成json 数据
22 | * @param obj
23 | * @return
24 | */
25 | public static Object objectToJson(Object obj){
26 | return JSON.toJSON(obj);
27 | }
28 |
29 | /**
30 | * 将json 字符串信息转化成对象信息, 通过泛型的形式转化
31 | * @param jsonStr
32 | * @param clazz
33 | * @param
34 | * @return
35 | */
36 | public static T parseObjectByGenericity(String jsonStr, Class clazz){
37 | T t = JSON.parseObject(jsonStr, clazz);
38 | return t;
39 | }
40 |
41 | /**
42 | * 将map 转化成json数组
43 | * @param o
44 | * @return
45 | */
46 | public static JSONArray parseObjectToJsonArray(Object o){
47 |
48 | Object obj = objectToJson(o);
49 | if(obj instanceof JSONObject){
50 | System.out.println("json对象");
51 | JSONArray jsonArray = new JSONArray();
52 | jsonArray.add(obj);
53 | return jsonArray;
54 | }
55 | return (JSONArray) JsonTools.objectToJson(obj);
56 | }
57 |
58 | /**
59 | * json 文件的位置
60 | * @param path
61 | * @return
62 | */
63 | public static Object readJsonFile(String path){
64 | return readJsonFile(new File(path));
65 | }
66 |
67 | /**
68 | * 读取json 配置文件
69 | * @param file
70 | * @return
71 | */
72 | public static Object readJsonFile(File file){
73 |
74 | StringBuilder sb = new StringBuilder();
75 | InputStream in = null;
76 | try {
77 | in = new FileInputStream(file);
78 | BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
79 | String tempString = "";
80 | while((tempString = reader.readLine()) != null){
81 | sb.append(tempString);
82 | }
83 | reader.close();
84 | } catch (IOException e) {
85 | e.printStackTrace();
86 | } finally {
87 | if(in != null){
88 | try {
89 | in.close();
90 | } catch (IOException e) {
91 | e.printStackTrace();
92 | }
93 | }
94 | }
95 |
96 | return JSON.parse(sb.toString());
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/codegen-engine/src/main/java/cn/springcloud/codegen/engine/tools/MapTools.java:
--------------------------------------------------------------------------------
1 | package cn.springcloud.codegen.engine.tools;
2 |
3 | import java.util.*;
4 |
5 | /**
6 | * @author Vincent.
7 | * @createdOn 2018/01/27 21:33
8 | */
9 | public class MapTools {
10 |
11 | public static Map addMap(Map originMap, Map addendMap) {
12 | if (originMap == null){
13 | originMap = new HashMap();
14 | }
15 | if (addendMap == null){
16 | return originMap;
17 | }
18 | for (Map.Entry entry : addendMap.entrySet()) {
19 | if (originMap.get(entry.getKey()) == null) {
20 | if (entry.getValue() instanceof List) {
21 | originMap.put(entry.getKey(), entry.getValue());
22 | } else {
23 | List