add codegen test

This commit is contained in:
东皇 2017-04-20 16:01:30 +08:00
parent 169ab1b99a
commit 8831529251
19 changed files with 102 additions and 270 deletions

141
pom.xml
View File

@ -201,7 +201,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.5</version>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
@ -213,16 +213,6 @@
<artifactId>bson</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.8.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.9.2.RELEASE</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
@ -268,81 +258,22 @@
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-autoconfigure -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>${spring-boot.version}</version>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- / Spring Boot -->
<dependency>
<artifactId>spring-core</artifactId>
<groupId>org.springframework</groupId>
<version>${spring.version}</version>
</dependency>
<dependency>
<artifactId>spring-beans</artifactId>
<groupId>org.springframework</groupId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<artifactId>spring-context</artifactId>
<groupId>org.springframework</groupId>
<version>${spring.version}</version>
</dependency>
<dependency>
<artifactId>spring-context-support</artifactId>
<groupId>org.springframework</groupId>
<version>${spring.version}</version>
</dependency>
<dependency>
<artifactId>spring-webmvc</artifactId>
<groupId>org.springframework</groupId>
<version>${spring.version}</version>
</dependency>
<dependency>
<artifactId>spring-web</artifactId>
<groupId>org.springframework</groupId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
@ -379,11 +310,6 @@
<version>1.2</version>
</dependency>
<!-- test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@ -581,6 +507,14 @@
<include>config.properties</include>
</includes>
</fileset>
<fileset>
<directory>src/main/resources</directory>
<includes>
<include>application.properties</include>
<include>application.yaml</include>
<include>log4j2.xml</include>
</includes>
</fileset>
</filesets>
</configuration>
</execution>
@ -592,8 +526,8 @@
<version>1.0</version>
<executions>
<execution>
<id>copy-config-file</id>
<phase>validate</phase>
<id>copy-config-props-file</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
@ -602,6 +536,39 @@
<destinationFile>src/main/resources/spring/config.properties</destinationFile>
</configuration>
</execution>
<execution>
<id>copy-application-props-file</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>src/main/resources/application_${project.activeProfiles[0].id}.properties</sourceFile>
<destinationFile>src/main/resources/application.properties</destinationFile>
</configuration>
</execution>
<execution>
<id>copy-application-yaml-file</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>src/main/resources/application_${project.activeProfiles[0].id}.yaml</sourceFile>
<destinationFile>src/main/resources/application.yaml</destinationFile>
</configuration>
</execution>
<execution>
<id>copy-log4j2-xml-file</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>src/main/resources/log4j2_${project.activeProfiles[0].id}.xml</sourceFile>
<destinationFile>src/main/resources/log4j2.xml</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>

@ -0,0 +1 @@
Subproject commit a7c690619e09fae1d48584794d68d1b8ee78c197

@ -0,0 +1 @@
Subproject commit a7c690619e09fae1d48584794d68d1b8ee78c197

View File

@ -1,20 +1,22 @@
package me.chyxion.tigon.codegen.controller;
import java.util.List;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import me.chyxion.tigon.codegen.service.CodeGenBaseTool;
import me.chyxion.tigon.codegen.service.CodeGenService;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import javax.validation.constraints.NotNull;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;
import org.hibernate.validator.constraints.NotBlank;
import me.chyxion.tigon.codegen.service.CodeGenService;
import me.chyxion.tigon.codegen.service.CodeGenBaseTool;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
@ -67,6 +69,8 @@ public class CodeGenController {
return true;
}
@Getter
@Setter
public static class GenForm {
@NotNull
private String columns;
@ -90,146 +94,11 @@ public class CodeGenController {
public JSONArray getJaColumns() {
return JSON.parseArray(columns);
}
public String getColumns() {
return columns;
}
/**
* @param columns the columns to set
*/
public void setColumns(String columns) {
this.columns = columns;
}
/**
* @return the model
*/
public String getModel() {
return model;
}
/**
* @param model the model to set
*/
public void setModel(String model) {
this.model = model;
}
/**
* @return the table
*/
public String getTable() {
return table;
}
/**
* @param table the table to set
*/
public void setTable(String table) {
this.table = table;
}
/**
* @return the module
*/
public String getModule() {
return StringUtils.isNotBlank(module) ? module : "";
}
/**
* @param module the module to set
*/
public void setModule(String module) {
this.module = module;
}
/**
* @return the createTable
*/
public boolean isCreateTable() {
return createTable;
}
/**
* @param createTable the createTable to set
*/
public void setCreateTable(boolean createTable) {
this.createTable = createTable;
}
/**
* @return the pkg
*/
public String getPkg() {
return pkg;
}
/**
* @param pkg the pkg to set
*/
public void setPkg(String pkg) {
this.pkg = pkg;
}
/**
* @return the genTable
*/
public boolean isGenTable() {
return genTable;
}
/**
* @param genTable the genTable to set
*/
public void setGenTable(boolean genTable) {
this.genTable = genTable;
}
/**
* @return the genController
*/
public boolean isGenController() {
return genController;
}
/**
* @param genController the genController to set
*/
public void setGenController(boolean genController) {
this.genController = genController;
}
/**
* @return the genService
*/
public boolean isGenService() {
return genService;
}
/**
* @param genService the genService to set
*/
public void setGenService(boolean genService) {
this.genService = genService;
}
/**
* @return the genMapper
*/
public boolean isGenMapper() {
return genMapper;
}
/**
* @param genMapper the genMapper to set
*/
public void setGenMapper(boolean genMapper) {
this.genMapper = genMapper;
}
/**
* @return the genView
*/
public boolean isGenView() {
return genView;
}
/**
* @param genView the genView to set
*/
public void setGenView(boolean genView) {
this.genView = genView;
}
/**
* @return the genModel
*/
public boolean isGenModel() {
return genModel;
}
/**
* @param genModel the genModel to set
*/
public void setGenModel(boolean genModel) {
this.genModel = genModel;
}
}
}

View File

@ -44,10 +44,10 @@ public class CodeGenArgs {
private Map<String, Object> model;
/**
* @param target
* @param ftl
* @param model
* @param file
* @param target target
* @param ftl ftl
* @param model model
* @param file file
*/
public CodeGenArgs(String target, String ftl, Map<String, Object> model, String file) {
this.target = target;

View File

@ -35,7 +35,6 @@ import me.chyxion.tigon.util.WordUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.CharEncoding;
import me.chyxion.tigon.codegen.utils.DbTool;
import org.springframework.stereotype.Service;
import javax.xml.parsers.DocumentBuilderFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.JdbcUtils;
@ -57,7 +56,6 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
* chyxion@163.com <br>
* Dec 3, 2014 11:25:17 AM
*/
@Service
public class CodeGenBaseTool {
private static final Logger log =
LoggerFactory.getLogger(CodeGenBaseTool.class);

View File

@ -36,7 +36,6 @@ import me.chyxion.tigon.webmvc.test.ControllerTestTool;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @version 0.0.1
@ -45,7 +44,6 @@ import org.springframework.stereotype.Service;
* chyxion@163.com <br>
* Oct 6, 2014 1:10:02 PM
*/
@Service
public class CodeGenServiceSupport implements CodeGenService {
private static final Logger log = LoggerFactory.getLogger(CodeGenServiceSupport.class);
private static final Map<String, String> TYPE_PACKAGES = new HashMap<String, String>() {

View File

@ -1,7 +1,6 @@
package me.chyxion.tigon.codegen.service.support;
import java.util.Map;
import org.springframework.stereotype.Service;
import me.chyxion.tigon.codegen.model.CodeGenArgs;
import me.chyxion.tigon.codegen.service.CodeGenerator;
@ -12,7 +11,6 @@ import me.chyxion.tigon.codegen.service.CodeGenerator;
* chyxion@163.com <br>
* Oct 6, 2014 1:17:03 PM
*/
@Service
public class ControllerCodeGen extends CodeGenerator {
/**

View File

@ -1,7 +1,6 @@
package me.chyxion.tigon.codegen.service.support;
import java.util.Map;
import org.springframework.stereotype.Service;
import me.chyxion.tigon.codegen.model.CodeGenArgs;
/**
@ -11,7 +10,6 @@ import me.chyxion.tigon.codegen.model.CodeGenArgs;
* chyxion@163.com <br>
* Oct 7, 2014 7:57:07 PM
*/
@Service
public class ControllerTestCodeGen extends ControllerCodeGen {
/**

View File

@ -1,8 +1,6 @@
package me.chyxion.tigon.codegen.service.support;
import java.util.Map;
import org.springframework.stereotype.Service;
import me.chyxion.tigon.codegen.model.CodeGenArgs;
import me.chyxion.tigon.codegen.service.CodeGenerator;
@ -13,7 +11,6 @@ import me.chyxion.tigon.codegen.service.CodeGenerator;
* chyxion@163.com <br>
* Oct 6, 2014 1:17:13 PM
*/
@Service
public class MapperCodeGen extends CodeGenerator {
/**

View File

@ -1,8 +1,6 @@
package me.chyxion.tigon.codegen.service.support;
import java.util.Map;
import org.springframework.stereotype.Service;
import me.chyxion.tigon.codegen.model.CodeGenArgs;
/**
@ -12,7 +10,6 @@ import me.chyxion.tigon.codegen.model.CodeGenArgs;
* chyxion@163.com <br>
* Oct 7, 2014 7:52:21 PM
*/
@Service
public class MapperTestCodeGen extends MapperCodeGen {
/**

View File

@ -2,7 +2,6 @@ package me.chyxion.tigon.codegen.service.support;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import me.chyxion.tigon.codegen.model.CodeGenArgs;
/**
@ -12,7 +11,6 @@ import me.chyxion.tigon.codegen.model.CodeGenArgs;
* chyxion@163.com <br>
* Oct 6, 2014 5:51:27 PM
*/
@Service
public class MapperXmlCodeGen extends MapperCodeGen {
/**

View File

@ -1,7 +1,6 @@
package me.chyxion.tigon.codegen.service.support;
import java.util.Map;
import org.springframework.stereotype.Service;
import me.chyxion.tigon.codegen.model.CodeGenArgs;
import me.chyxion.tigon.codegen.service.CodeGenerator;
@ -12,7 +11,6 @@ import me.chyxion.tigon.codegen.service.CodeGenerator;
* chyxion@163.com <br>
* Oct 6, 2014 1:17:42 PM
*/
@Service
public class ModelCodeGen extends CodeGenerator {
/**

View File

@ -1,9 +1,6 @@
package me.chyxion.tigon.codegen.service.support;
import java.util.Map;
import org.springframework.stereotype.Service;
import me.chyxion.tigon.codegen.model.CodeGenArgs;
import me.chyxion.tigon.codegen.service.CodeGenerator;
@ -14,7 +11,6 @@ import me.chyxion.tigon.codegen.service.CodeGenerator;
* chyxion@163.com <br>
* Oct 6, 2014 1:17:30 PM
*/
@Service
public class ServiceCodeGen extends CodeGenerator {
/**

View File

@ -6,7 +6,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.Ordered;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.core.annotation.Order;
import me.chyxion.tigon.codegen.model.CodeGenArgs;
import me.chyxion.tigon.codegen.service.CodeGenerator;
@ -18,7 +17,6 @@ import me.chyxion.tigon.codegen.service.CodeGenerator;
* chyxion@163.com <br>
* Oct 7, 2014 12:23:13 PM
*/
@Service
@Order(Ordered.LOWEST_PRECEDENCE)
public class TableCodeGen extends CodeGenerator {
private static final Logger log = LoggerFactory.getLogger(TableCodeGen.class);

View File

@ -2,7 +2,6 @@ package me.chyxion.tigon.codegen.service.support;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import me.chyxion.tigon.codegen.model.CodeGenArgs;
import me.chyxion.tigon.codegen.service.CodeGenerator;
@ -13,7 +12,6 @@ import me.chyxion.tigon.codegen.service.CodeGenerator;
* chyxion@163.com <br>
* Oct 6, 2014 1:17:22 PM
*/
@Service
public class ViewCodeGen extends CodeGenerator {
/**

View File

@ -7,5 +7,5 @@
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- Scan Code Gen -->
<context:component-scan base-package="me.chyxion.tigon.codegen" />
<context:component-scan base-package="me.chyxion.tigon.codegen.controller" />
</beans>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="me.chyxion.tigon.codegen.controller" />
<!-- Tool -->
<bean class="me.chyxion.tigon.codegen.service.CodeGenBaseTool" />
<!--Services -->
<bean class="me.chyxion.tigon.codegen.service.support.CodeGenServiceSupport" />
<bean class="me.chyxion.tigon.codegen.service.support.ControllerCodeGen" />
<bean class="me.chyxion.tigon.codegen.service.support.ControllerTestCodeGen" />
<bean class="me.chyxion.tigon.codegen.service.support.MapperCodeGen" />
<bean class="me.chyxion.tigon.codegen.service.support.MapperTestCodeGen" />
<bean class="me.chyxion.tigon.codegen.service.support.MapperXmlCodeGen" />
<bean class="me.chyxion.tigon.codegen.service.support.ModelCodeGen" />
<bean class="me.chyxion.tigon.codegen.service.support.ServiceCodeGen" />
<bean class="me.chyxion.tigon.codegen.service.support.TableCodeGen" />
<bean class="me.chyxion.tigon.codegen.service.support.ViewCodeGen" />
</beans>

View File

@ -21,12 +21,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>me.chyxion.tigon</groupId>