Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
makejavas committed Aug 2, 2018
2 parents 486f97c + 4cbb533 commit 5d674ec
Show file tree
Hide file tree
Showing 17 changed files with 305 additions and 192 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ apply plugin: 'idea'
apply plugin: 'org.jetbrains.intellij'

group 'com.sjhy'
version '1.1.1-SNAPSHOT'
version '1.1.2-SNAPSHOT'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -29,6 +29,7 @@ repositories {

dependencies {
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.6'
// compile group: 'org.apache.velocity', name: 'velocity', version: '1.7'
testCompile group: 'junit', name: 'junit', version: '4.12'
compileOnly "org.projectlombok:lombok:1.18.0"
// compileClasspath fileTree(dir: 'lib', includes: ['*.jar'])
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/sjhy/plugin/constants/MsgValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.sjhy.plugin.constants;

/**
* 消息常量值
*
* @author makejava
* @version 1.0.0
* @since 2018/08/02 11:55
*/
public class MsgValue {
/**
* 提示信息
*/
public static final String TITLE_INFO = "EasyCode Title Info";
}
4 changes: 2 additions & 2 deletions src/main/java/com/sjhy/plugin/tool/CloneUtils.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.sjhy.plugin.tool;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sjhy.plugin.entity.AbstractGroup;
import com.intellij.util.ExceptionUtil;

import java.io.IOException;
import java.util.*;
Expand Down Expand Up @@ -52,7 +52,7 @@ public <E> E clone(E entity) {
//noinspection unchecked
return objectMapper.readValue(objectMapper.writeValueAsString(entity), (Class<E>) entity.getClass());
} catch (IOException e) {
e.printStackTrace();
ExceptionUtil.rethrow(e);
}
return null;
}
Expand Down
85 changes: 24 additions & 61 deletions src/main/java/com/sjhy/plugin/tool/ConfigInfo.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.sjhy.plugin.tool;

import com.intellij.openapi.components.*;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.intellij.util.xmlb.annotations.Transient;
import com.sjhy.plugin.entity.*;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
* 全局配置信息
Expand Down Expand Up @@ -111,9 +113,8 @@ public void initDefault() {
if (this.templateGroupMap == null) {
this.templateGroupMap = new LinkedHashMap<>();
}
for (String groupName : new String[]{DEFAULT_NAME, "MybatisPlus"}) {
this.templateGroupMap.put(groupName, loadTemplateGroup(groupName));
}
this.templateGroupMap.put(DEFAULT_NAME, loadTemplateGroup(DEFAULT_NAME, "entity", "dao", "service", "serviceImpl", "controller"));
this.templateGroupMap.put("MybatisPlus", loadTemplateGroup(DEFAULT_NAME, "entity", "dao", "service", "serviceImpl", "controller"));

//配置默认类型映射
if (this.typeMapperGroupMap == null) {
Expand Down Expand Up @@ -151,9 +152,7 @@ public void initDefault() {
if (this.globalConfigGroupMap == null) {
this.globalConfigGroupMap = new LinkedHashMap<>();
}
for (String groupName : new String[]{DEFAULT_NAME}) {
this.globalConfigGroupMap.put(groupName, loadGlobalConfigGroup(groupName));
}
this.globalConfigGroupMap.put(DEFAULT_NAME, loadGlobalConfigGroup(DEFAULT_NAME, "init", "define", "autoImport"));
}

/**
Expand All @@ -169,71 +168,35 @@ private static String loadTemplate(String filePath) {
/**
* 加载模板组
*
* @param groupName 组名
* @param groupName 组名
* @param templateNames 模板名称
* @return 模板组
*/
private static TemplateGroup loadTemplateGroup(String groupName) {
private static TemplateGroup loadTemplateGroup(String groupName, String... templateNames) {
TemplateGroup templateGroup = new TemplateGroup();
templateGroup.setName(groupName);
templateGroup.setElementList(new ArrayList<>());
// 获取jar中的文件名
String path = ConfigInfo.class.getResource("/template").getPath();
String jarFileName = path.substring(6, path.indexOf("!"));
try (JarFile jarFile = new JarFile(jarFileName)) {
// 遍历JAR文件
Enumeration<JarEntry> entries = jarFile.entries();
String prefix = "template/" + groupName;
while (entries.hasMoreElements()) {
JarEntry jarEntry = entries.nextElement();
// 目录跳过
if (jarEntry.isDirectory()) {
continue;
}
String name = jarEntry.getName();
if (name.startsWith(prefix)) {
String templatePath = "/" + name;
name = name.substring(name.lastIndexOf("/") + 1, name.length() - 3);
templateGroup.getElementList().add(new Template(name, loadTemplate(templatePath)));
}
}
} catch (IOException e) {
e.printStackTrace();
for (String templateName : templateNames) {
String path = "/template/" + groupName + "/" + templateName + ".vm";
templateGroup.getElementList().add(new Template(templateName, loadTemplate(path)));
}
return templateGroup;
}

/**
* 加载全局配置组
*
* @param groupName 组名
* @param groupName 组名
* @param templateNames 模板名称
* @return 模板组
*/
private static GlobalConfigGroup loadGlobalConfigGroup(String groupName) {
private static GlobalConfigGroup loadGlobalConfigGroup(String groupName, String... templateNames) {
GlobalConfigGroup globalConfigGroup = new GlobalConfigGroup();
globalConfigGroup.setName(groupName);
globalConfigGroup.setElementList(new ArrayList<>());
// 获取jar中的文件名
String path = ConfigInfo.class.getResource("/globalConfig").getPath();
String jarFileName = path.substring(6, path.indexOf("!"));
try (JarFile jarFile = new JarFile(jarFileName)) {
// 遍历JAR文件
Enumeration<JarEntry> entries = jarFile.entries();
String prefix = "globalConfig/" + groupName;
while (entries.hasMoreElements()) {
JarEntry jarEntry = entries.nextElement();
// 目录跳过
if (jarEntry.isDirectory()) {
continue;
}
String name = jarEntry.getName();
if (name.startsWith(prefix)) {
String templatePath = "/" + name;
name = name.substring(name.lastIndexOf("/") + 1, name.length() - 3);
globalConfigGroup.getElementList().add(new GlobalConfig(name, loadTemplate(templatePath)));
}
}
} catch (IOException e) {
e.printStackTrace();
for (String templateName : templateNames) {
String path = "/globalConfig/" + groupName + "/" + templateName + ".vm";
globalConfigGroup.getElementList().add(new GlobalConfig(templateName, loadTemplate(path)));
}
return globalConfigGroup;
}
Expand All @@ -253,7 +216,7 @@ public void loadState(@NotNull ConfigInfo configInfo) {
XmlSerializerUtil.copyBean(configInfo, this);

// 已经合并不再重复合并
if (configInfo.getVersion()!=null && configInfo.getVersion().equals(version)) {
if (configInfo.getVersion() != null && configInfo.getVersion().equals(version)) {
return;
}

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/sjhy/plugin/tool/FileUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sjhy.plugin.tool;

import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.ExceptionUtil;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -43,7 +44,7 @@ public String read(File file) {
try {
builder.append(FileUtil.loadFileText(file, "UTF-8"));
} catch (IOException e) {
e.printStackTrace();
ExceptionUtil.rethrow(e);
}
return builder.toString();
}
Expand All @@ -58,13 +59,13 @@ public String read(InputStream in) {
byte[] temp = FileUtil.loadBytes(in);
return new String(temp, "UTF-8");
} catch (IOException e) {
e.printStackTrace();
ExceptionUtil.rethrow(e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
ExceptionUtil.rethrow(e);
}
}
}
Expand All @@ -90,7 +91,7 @@ public void write(File file, String content, boolean append) {
try {
FileUtil.writeToFile(file, content, append);
} catch (IOException e) {
e.printStackTrace();
ExceptionUtil.rethrow(e);
}
}
}
21 changes: 12 additions & 9 deletions src/main/java/com/sjhy/plugin/tool/TableInfoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import com.intellij.database.model.DasColumn;
import com.intellij.database.psi.DbTable;
import com.intellij.database.util.DasUtil;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.util.ExceptionUtil;
import com.intellij.util.containers.JBIterable;
import com.sjhy.plugin.comm.AbstractService;
import com.sjhy.plugin.constants.MsgValue;
import com.sjhy.plugin.entity.ColumnInfo;
import com.sjhy.plugin.entity.TableInfo;
import com.sjhy.plugin.entity.TypeMapper;
Expand Down Expand Up @@ -182,7 +185,7 @@ private String getColumnType(String typeName) {
}
}
//弹出消息框
JOptionPane.showMessageDialog(null, "发现未知类型:" + typeName, "温馨提示", JOptionPane.PLAIN_MESSAGE);
Messages.showWarningDialog("发现未知类型:" + typeName, MsgValue.TITLE_INFO);
return "java.lang.Object";
}

Expand Down Expand Up @@ -219,18 +222,18 @@ public void save(TableInfo tableInfo) {
try {
content = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(tableInfo);
} catch (JsonProcessingException e) {
e.printStackTrace();
ExceptionUtil.rethrow(e);
}
if (content == null) {
JOptionPane.showMessageDialog(null, "保存失败,JSON序列化错误。", "温馨提示", JOptionPane.PLAIN_MESSAGE);
Messages.showWarningDialog("保存失败,JSON序列化错误。", MsgValue.TITLE_INFO);
return;
}
// 获取或创建保存目录
String path = cacheDataUtils.getProject().getBasePath() + SAVE_PATH;
File dir = new File(path);
if (!dir.exists()) {
if (!dir.mkdir()) {
JOptionPane.showMessageDialog(null, "保存失败,无法创建目录。", "温馨提示", JOptionPane.PLAIN_MESSAGE);
Messages.showWarningDialog("保存失败,无法创建目录。", MsgValue.TITLE_INFO);
return;
}
}
Expand All @@ -241,12 +244,12 @@ public void save(TableInfo tableInfo) {
if (!file.exists()) {
try {
if (!file.createNewFile()) {
JOptionPane.showMessageDialog(null, "保存失败,无法创建文件。", "温馨提示", JOptionPane.PLAIN_MESSAGE);
Messages.showWarningDialog("保存失败,无法创建文件。", MsgValue.TITLE_INFO);
return;
}
} catch (IOException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "保存失败,创建文件异常。", "温馨提示", JOptionPane.PLAIN_MESSAGE);
ExceptionUtil.rethrow(e);
Messages.showWarningDialog("保存失败,创建文件异常。", MsgValue.TITLE_INFO);
return;
}
}
Expand Down Expand Up @@ -290,8 +293,8 @@ private TableInfo parser(String str) {
try {
return objectMapper.readValue(str, TableInfo.class);
} catch (IOException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "读取配置失败,JSON反序列化异常。", "温馨提示", JOptionPane.PLAIN_MESSAGE);
ExceptionUtil.rethrow(e);
Messages.showWarningDialog("读取配置失败,JSON反序列化异常。", MsgValue.TITLE_INFO);
}
return null;
}
Expand Down
Loading

0 comments on commit 5d674ec

Please sign in to comment.