diff --git a/pom.xml b/pom.xml
index 6137e98..1606b68 100644
--- a/pom.xml
+++ b/pom.xml
@@ -47,7 +47,6 @@
tigon-service-api
tigon-service-support
tigon-extjs
- tigon-freemarker-support
tigon-codegen
@@ -159,7 +158,6 @@
-
@@ -169,8 +167,6 @@
true
ZIP
-
-
diff --git a/tigon-codegen/pom.xml b/tigon-codegen/pom.xml
index 66c31bb..7976295 100644
--- a/tigon-codegen/pom.xml
+++ b/tigon-codegen/pom.xml
@@ -24,9 +24,12 @@
- me.chyxion.tigon
- tigon-freemarker-support
- 0.0.1-SNAPSHOT
+ org.freemarker
+ freemarker
+
+
+ org.springframework
+ spring-context-support
me.chyxion.tigon
@@ -50,6 +53,16 @@
me.chyxion.tigon
tigon-mybatis
+
+ mysql
+ mysql-connector-java
+ 5.1.6
+
+
+ com.alibaba
+ druid
+ 1.1.10
+
org.projectlombok
lombok
@@ -71,6 +84,7 @@
spring-boot-maven-plugin
false
+ true
diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/TigonCodeGen.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/TigonCodeGen.java
index 7996d59..bb23368 100644
--- a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/TigonCodeGen.java
+++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/TigonCodeGen.java
@@ -1,5 +1,6 @@
package me.chyxion.tigon.codegen;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -8,13 +9,15 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* chyxion@163.com
* Jun 24, 2018 20:43:36
*/
+@Slf4j
@SpringBootApplication
public class TigonCodeGen {
/**
* @param args start args
*/
- public static void main(String[] args) {
+ public static void main(final String[] args) {
+ log.info("Startup args [{}].", args);
SpringApplication.run(TigonCodeGen.class, args);
}
}
diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/controller/CodeGenController.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/controller/CodeGenController.java
index aa1eca2..6073db5 100644
--- a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/controller/CodeGenController.java
+++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/controller/CodeGenController.java
@@ -10,6 +10,8 @@ import com.alibaba.fastjson.JSONArray;
import javax.validation.constraints.NotNull;
import org.apache.commons.lang3.StringUtils;
import javax.validation.constraints.NotBlank;
+
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;
import me.chyxion.tigon.codegen.service.CodeGenService;
@@ -35,11 +37,16 @@ public class CodeGenController {
private CodeGenService service;
@Autowired
private CodeGenBaseTool tool;
+ @Value("${codegen.components:}")
+ private String genComponents;
@RequestMapping(method = GET)
public ModelAndView index() {
return new ModelAndView("webapp/views/codegen")
- .addObject("pkg", tool.getPkg());
+ .addObject("pkg", tool.getPkg())
+ .addObject("components",
+ StringUtils.isNotBlank(genComponents) ?
+ JSON.toJSONString(genComponents.split("\\s*[,;]\\s*")) : "[]");
}
@RequestMapping(value = "/tables")
diff --git a/tigon-freemarker-support/src/main/java/me/chyxion/tigon/freemarker/FreeMarkerViewResolverExt.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/freemarker/FreeMarkerViewResolverExt.java
similarity index 73%
rename from tigon-freemarker-support/src/main/java/me/chyxion/tigon/freemarker/FreeMarkerViewResolverExt.java
rename to tigon-codegen/src/main/java/me/chyxion/tigon/codegen/freemarker/FreeMarkerViewResolverExt.java
index 1a38262..8e76d27 100644
--- a/tigon-freemarker-support/src/main/java/me/chyxion/tigon/freemarker/FreeMarkerViewResolverExt.java
+++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/freemarker/FreeMarkerViewResolverExt.java
@@ -1,8 +1,7 @@
-package me.chyxion.tigon.freemarker;
+package me.chyxion.tigon.codegen.freemarker;
import java.util.Locale;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
@@ -13,9 +12,8 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
* chyxion@163.com
* Dec 5, 2014 2:31:39 PM
*/
+@Slf4j
public class FreeMarkerViewResolverExt extends FreeMarkerViewResolver {
- private static final Logger log =
- LoggerFactory.getLogger(FreeMarkerViewResolverExt.class);
/**
* {@inheritDoc}
@@ -24,6 +22,6 @@ public class FreeMarkerViewResolverExt extends FreeMarkerViewResolver {
public View resolveViewName(String viewName, Locale locale)
throws Exception {
log.debug("Try to resolve view name [{}], locale [{}] as freemarker view.", viewName, locale);
- return super.resolveViewName(viewName.replaceAll("(?i)(^\\s*ftl\\:)|(\\.ftl\\s*$)", ""), locale);
+ return super.resolveViewName(viewName.replaceAll("(?i)(^\\s*ftl:)|(\\.ftl\\s*$)", ""), locale);
}
}
diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/CodeGenBaseTool.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/CodeGenBaseTool.java
index 1444803..80576b0 100644
--- a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/CodeGenBaseTool.java
+++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/CodeGenBaseTool.java
@@ -1,41 +1,25 @@
package me.chyxion.tigon.codegen.service;
import java.io.File;
-import java.util.Map;
-import java.util.Set;
-import java.util.Date;
-import java.util.List;
-import java.util.Arrays;
-import org.slf4j.Logger;
-import java.util.TreeSet;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
+import java.util.*;
import java.io.FileWriter;
import java.sql.ResultSet;
-import org.w3c.dom.Element;
import java.io.IOException;
-import java.io.InputStream;
import java.sql.Connection;
-import java.util.Properties;
-import java.util.LinkedList;
-import javax.sql.DataSource;
import java.sql.SQLException;
import java.io.FileInputStream;
-import org.slf4j.LoggerFactory;
+import lombok.extern.slf4j.Slf4j;
import java.sql.DatabaseMetaData;
import com.alibaba.fastjson.JSON;
import java.io.InputStreamReader;
import me.chyxion.tigon.model.M1;
import freemarker.template.Template;
import org.apache.commons.io.IOUtils;
-import javax.annotation.PostConstruct;
import org.apache.commons.io.FileUtils;
import me.chyxion.tigon.util.WordUtils;
+import java.nio.charset.StandardCharsets;
import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.CharEncoding;
-import me.chyxion.tigon.codegen.utils.DbTool;
-import javax.xml.parsers.DocumentBuilderFactory;
+import me.chyxion.tigon.codegen.util.DbTool;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.dao.DataAccessException;
@@ -46,7 +30,6 @@ import com.alibaba.fastjson.serializer.SerializerFeature;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
-import static org.springframework.context.ConfigurableApplicationContext.*;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
/**
@@ -56,92 +39,21 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
* chyxion@163.com
* Dec 3, 2014 11:25:17 AM
*/
+@Slf4j
public class CodeGenBaseTool {
- private static final Logger log =
- LoggerFactory.getLogger(CodeGenBaseTool.class);
@Autowired
private FreeMarkerConfigurer fmCfg;
- @Autowired(required = false)
- private DataSource dataSource;
+ @Autowired
private JdbcTemplate jdbcTpl;
- @Value("#{systemProperties['project.basedir']}")
+ @Value("${project.base-dir}")
private String projDir;
- private String groupId;
+ @Value("${project.base-package}")
private String pkg;
- private Properties config = new Properties();
- private Set baseCols = new HashSet();
+ @Value("${codegen.table-prefix:}")
+ private String tablePrefix;
- /**
- * @param col
- * @return true if col is base col
- */
- public boolean isBaseCol(String col) {
- return baseCols.contains(col);
- }
-
- /**
- * @param key
- * @return
- */
- public String getConfig(String key) {
- return config.getProperty(key);
- }
-
- /**
- * @param key
- * @param defaultValue
- * @return
- */
- public String getConfig(String key, String defaultValue) {
- return config.getProperty(key, defaultValue);
- }
-
- /**
- * get config
- * @param key
- * @param defaultValue
- * @return
- */
- public boolean getConfig(String key, boolean defaultValue) {
- return Boolean.valueOf(getConfig(key, String.valueOf(defaultValue)));
- }
-
- /**
- * @param key
- * @param defaultValue
- * @return
- */
- public int getConfig(String key, int defaultValue) {
- return Integer.valueOf(getConfig(key, String.valueOf(defaultValue)));
- }
-
- /**
- * @param key
- * @param defaultValue
- * @return
- */
- public long getConfig(String key, long defaultValue) {
- return Long.valueOf(getConfig(key, String.valueOf(defaultValue)));
- }
-
- /**
- * @param key
- * @param defaultValue
- * @return
- */
- public double getConfig(String key, double defaultValue) {
- return Double.valueOf(getConfig(key, String.valueOf(defaultValue)));
- }
-
- /**
- * @param key
- * @param defaultValue
- * @return
- */
- public float getConfig(String key, float defaultValue) {
- return Float.valueOf(getConfig(key, String.valueOf(defaultValue)));
- }
+ private Set baseCols = new HashSet<>();
/**
* @return the projDir
@@ -150,13 +62,6 @@ public class CodeGenBaseTool {
return projDir;
}
- /**
- * @return the groupId
- */
- public String getGroupId() {
- return groupId;
- }
-
/**
* @return the groupId
*/
@@ -193,63 +98,6 @@ public class CodeGenBaseTool {
}
}
- /**
- * init config
- */
- @PostConstruct
- void init() {
- // disable cache
- log.info("Disable FreeMarker Cache In Dev Mode.");
- fmCfg.getConfiguration().setTemplateUpdateDelayMilliseconds(0);
- if (dataSource != null) {
- jdbcTpl = new JdbcTemplate(dataSource, true);
- }
-
- try {
- log.info("Parse Group ID From [{}/pom.xml].", projDir);
- Element root = DocumentBuilderFactory.newInstance()
- .newDocumentBuilder()
- .parse(new File(projDir, "pom.xml"))
- .getDocumentElement();
- root.normalize();
- groupId = root.getElementsByTagName("groupId").item(0).getTextContent().trim();
- log.info("Group ID [{}] Found.", groupId);
- }
- catch (Exception e) {
- throw new IllegalStateException(
- "Parse [groupId] From Maven POM File [" + projDir + "/pom.xml] Error Caused", e);
- }
-
- InputStream cfgIns = CodeGenBaseTool.class
- .getResourceAsStream("/codegen/config.properties");
- if (cfgIns != null) {
- try {
- config.load(cfgIns);
- log.info("Code Gen Config [{}] Found.", config);
- }
- catch (IOException e) {
- throw new IllegalStateException(
- "Load Code Gen Config Error Caused", e);
- }
- finally {
- IOUtils.closeQuietly(cfgIns);
- }
- }
-
- baseCols.add("id");
- String baseColsProp = config.getProperty("base.cols");
- if (StringUtils.isNotBlank(baseColsProp)) {
- log.info("Code Gen Base Cols [{}] Found.", baseColsProp);
- baseCols.addAll(Arrays.asList(
- org.springframework.util.StringUtils
- .tokenizeToStringArray(
- baseColsProp, CONFIG_LOCATION_DELIMITERS, true, true)));
- }
- log.info("Code Gen Base Cols [{}] Result.", baseCols);
- pkg = config.getProperty("base.package", groupId);
- log.info("Code Gen Package [{}].", pkg);
- }
-
/**
* list all model generated
* @return
@@ -270,7 +118,7 @@ public class CodeGenBaseTool {
FileInputStream fin = null;
try {
fin = new FileInputStream(file);
- mapData = JSON.parseObject(IOUtils.toString(fin, CharEncoding.UTF_8));
+ mapData = JSON.parseObject(IOUtils.toString(fin, StandardCharsets.UTF_8));
}
catch (IOException e) {
log.info("Parse JSON File [{}] ERROR Caused.", file.getName());
@@ -284,7 +132,7 @@ public class CodeGenBaseTool {
// backup data file
IOUtils.copy(fin,
new FileWriter(new File(projDir, backupFileName)),
- CharEncoding.UTF_8);
+ StandardCharsets.UTF_8);
}
}
catch (IOException e1) {
@@ -296,8 +144,8 @@ public class CodeGenBaseTool {
}
}
if (mapData == null) {
- mapData = new HashMap();
- mapData.put("items", new LinkedList