Skip to content

Commit 5d674ec

Browse files
committed
Merge branch 'dev'
2 parents 486f97c + 4cbb533 commit 5d674ec

17 files changed

+305
-192
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ apply plugin: 'idea'
1717
apply plugin: 'org.jetbrains.intellij'
1818

1919
group 'com.sjhy'
20-
version '1.1.1-SNAPSHOT'
20+
version '1.1.2-SNAPSHOT'
2121

2222
sourceCompatibility = JavaVersion.VERSION_1_8
2323
targetCompatibility = JavaVersion.VERSION_1_8
@@ -29,6 +29,7 @@ repositories {
2929

3030
dependencies {
3131
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.6'
32+
// compile group: 'org.apache.velocity', name: 'velocity', version: '1.7'
3233
testCompile group: 'junit', name: 'junit', version: '4.12'
3334
compileOnly "org.projectlombok:lombok:1.18.0"
3435
// compileClasspath fileTree(dir: 'lib', includes: ['*.jar'])
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.sjhy.plugin.constants;
2+
3+
/**
4+
* 消息常量值
5+
*
6+
* @author makejava
7+
* @version 1.0.0
8+
* @since 2018/08/02 11:55
9+
*/
10+
public class MsgValue {
11+
/**
12+
* 提示信息
13+
*/
14+
public static final String TITLE_INFO = "EasyCode Title Info";
15+
}

src/main/java/com/sjhy/plugin/tool/CloneUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.sjhy.plugin.tool;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4-
import com.sjhy.plugin.entity.AbstractGroup;
4+
import com.intellij.util.ExceptionUtil;
55

66
import java.io.IOException;
77
import java.util.*;
@@ -52,7 +52,7 @@ public <E> E clone(E entity) {
5252
//noinspection unchecked
5353
return objectMapper.readValue(objectMapper.writeValueAsString(entity), (Class<E>) entity.getClass());
5454
} catch (IOException e) {
55-
e.printStackTrace();
55+
ExceptionUtil.rethrow(e);
5656
}
5757
return null;
5858
}

src/main/java/com/sjhy/plugin/tool/ConfigInfo.java

Lines changed: 24 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package com.sjhy.plugin.tool;
22

3-
import com.intellij.openapi.components.*;
3+
import com.intellij.openapi.components.PersistentStateComponent;
4+
import com.intellij.openapi.components.ServiceManager;
5+
import com.intellij.openapi.components.State;
6+
import com.intellij.openapi.components.Storage;
47
import com.intellij.util.xmlb.XmlSerializerUtil;
58
import com.intellij.util.xmlb.annotations.Transient;
69
import com.sjhy.plugin.entity.*;
710
import lombok.Data;
8-
import org.apache.commons.lang3.StringUtils;
911
import org.jetbrains.annotations.NotNull;
1012
import org.jetbrains.annotations.Nullable;
1113

12-
import java.io.IOException;
13-
import java.util.*;
14-
import java.util.jar.JarEntry;
15-
import java.util.jar.JarFile;
14+
import java.util.ArrayList;
15+
import java.util.LinkedHashMap;
16+
import java.util.List;
17+
import java.util.Map;
1618

1719
/**
1820
* 全局配置信息
@@ -111,9 +113,8 @@ public void initDefault() {
111113
if (this.templateGroupMap == null) {
112114
this.templateGroupMap = new LinkedHashMap<>();
113115
}
114-
for (String groupName : new String[]{DEFAULT_NAME, "MybatisPlus"}) {
115-
this.templateGroupMap.put(groupName, loadTemplateGroup(groupName));
116-
}
116+
this.templateGroupMap.put(DEFAULT_NAME, loadTemplateGroup(DEFAULT_NAME, "entity", "dao", "service", "serviceImpl", "controller"));
117+
this.templateGroupMap.put("MybatisPlus", loadTemplateGroup(DEFAULT_NAME, "entity", "dao", "service", "serviceImpl", "controller"));
117118

118119
//配置默认类型映射
119120
if (this.typeMapperGroupMap == null) {
@@ -151,9 +152,7 @@ public void initDefault() {
151152
if (this.globalConfigGroupMap == null) {
152153
this.globalConfigGroupMap = new LinkedHashMap<>();
153154
}
154-
for (String groupName : new String[]{DEFAULT_NAME}) {
155-
this.globalConfigGroupMap.put(groupName, loadGlobalConfigGroup(groupName));
156-
}
155+
this.globalConfigGroupMap.put(DEFAULT_NAME, loadGlobalConfigGroup(DEFAULT_NAME, "init", "define", "autoImport"));
157156
}
158157

159158
/**
@@ -169,71 +168,35 @@ private static String loadTemplate(String filePath) {
169168
/**
170169
* 加载模板组
171170
*
172-
* @param groupName 组名
171+
* @param groupName 组名
172+
* @param templateNames 模板名称
173173
* @return 模板组
174174
*/
175-
private static TemplateGroup loadTemplateGroup(String groupName) {
175+
private static TemplateGroup loadTemplateGroup(String groupName, String... templateNames) {
176176
TemplateGroup templateGroup = new TemplateGroup();
177177
templateGroup.setName(groupName);
178178
templateGroup.setElementList(new ArrayList<>());
179-
// 获取jar中的文件名
180-
String path = ConfigInfo.class.getResource("/template").getPath();
181-
String jarFileName = path.substring(6, path.indexOf("!"));
182-
try (JarFile jarFile = new JarFile(jarFileName)) {
183-
// 遍历JAR文件
184-
Enumeration<JarEntry> entries = jarFile.entries();
185-
String prefix = "template/" + groupName;
186-
while (entries.hasMoreElements()) {
187-
JarEntry jarEntry = entries.nextElement();
188-
// 目录跳过
189-
if (jarEntry.isDirectory()) {
190-
continue;
191-
}
192-
String name = jarEntry.getName();
193-
if (name.startsWith(prefix)) {
194-
String templatePath = "/" + name;
195-
name = name.substring(name.lastIndexOf("/") + 1, name.length() - 3);
196-
templateGroup.getElementList().add(new Template(name, loadTemplate(templatePath)));
197-
}
198-
}
199-
} catch (IOException e) {
200-
e.printStackTrace();
179+
for (String templateName : templateNames) {
180+
String path = "/template/" + groupName + "/" + templateName + ".vm";
181+
templateGroup.getElementList().add(new Template(templateName, loadTemplate(path)));
201182
}
202183
return templateGroup;
203184
}
204185

205186
/**
206187
* 加载全局配置组
207188
*
208-
* @param groupName 组名
189+
* @param groupName 组名
190+
* @param templateNames 模板名称
209191
* @return 模板组
210192
*/
211-
private static GlobalConfigGroup loadGlobalConfigGroup(String groupName) {
193+
private static GlobalConfigGroup loadGlobalConfigGroup(String groupName, String... templateNames) {
212194
GlobalConfigGroup globalConfigGroup = new GlobalConfigGroup();
213195
globalConfigGroup.setName(groupName);
214196
globalConfigGroup.setElementList(new ArrayList<>());
215-
// 获取jar中的文件名
216-
String path = ConfigInfo.class.getResource("/globalConfig").getPath();
217-
String jarFileName = path.substring(6, path.indexOf("!"));
218-
try (JarFile jarFile = new JarFile(jarFileName)) {
219-
// 遍历JAR文件
220-
Enumeration<JarEntry> entries = jarFile.entries();
221-
String prefix = "globalConfig/" + groupName;
222-
while (entries.hasMoreElements()) {
223-
JarEntry jarEntry = entries.nextElement();
224-
// 目录跳过
225-
if (jarEntry.isDirectory()) {
226-
continue;
227-
}
228-
String name = jarEntry.getName();
229-
if (name.startsWith(prefix)) {
230-
String templatePath = "/" + name;
231-
name = name.substring(name.lastIndexOf("/") + 1, name.length() - 3);
232-
globalConfigGroup.getElementList().add(new GlobalConfig(name, loadTemplate(templatePath)));
233-
}
234-
}
235-
} catch (IOException e) {
236-
e.printStackTrace();
197+
for (String templateName : templateNames) {
198+
String path = "/globalConfig/" + groupName + "/" + templateName + ".vm";
199+
globalConfigGroup.getElementList().add(new GlobalConfig(templateName, loadTemplate(path)));
237200
}
238201
return globalConfigGroup;
239202
}
@@ -253,7 +216,7 @@ public void loadState(@NotNull ConfigInfo configInfo) {
253216
XmlSerializerUtil.copyBean(configInfo, this);
254217

255218
// 已经合并不再重复合并
256-
if (configInfo.getVersion()!=null && configInfo.getVersion().equals(version)) {
219+
if (configInfo.getVersion() != null && configInfo.getVersion().equals(version)) {
257220
return;
258221
}
259222

src/main/java/com/sjhy/plugin/tool/FileUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.sjhy.plugin.tool;
22

33
import com.intellij.openapi.util.io.FileUtil;
4+
import com.intellij.util.ExceptionUtil;
45

56
import java.io.File;
67
import java.io.IOException;
@@ -43,7 +44,7 @@ public String read(File file) {
4344
try {
4445
builder.append(FileUtil.loadFileText(file, "UTF-8"));
4546
} catch (IOException e) {
46-
e.printStackTrace();
47+
ExceptionUtil.rethrow(e);
4748
}
4849
return builder.toString();
4950
}
@@ -58,13 +59,13 @@ public String read(InputStream in) {
5859
byte[] temp = FileUtil.loadBytes(in);
5960
return new String(temp, "UTF-8");
6061
} catch (IOException e) {
61-
e.printStackTrace();
62+
ExceptionUtil.rethrow(e);
6263
} finally {
6364
if (in != null) {
6465
try {
6566
in.close();
6667
} catch (IOException e) {
67-
e.printStackTrace();
68+
ExceptionUtil.rethrow(e);
6869
}
6970
}
7071
}
@@ -90,7 +91,7 @@ public void write(File file, String content, boolean append) {
9091
try {
9192
FileUtil.writeToFile(file, content, append);
9293
} catch (IOException e) {
93-
e.printStackTrace();
94+
ExceptionUtil.rethrow(e);
9495
}
9596
}
9697
}

src/main/java/com/sjhy/plugin/tool/TableInfoUtils.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
import com.intellij.database.model.DasColumn;
66
import com.intellij.database.psi.DbTable;
77
import com.intellij.database.util.DasUtil;
8+
import com.intellij.openapi.ui.Messages;
89
import com.intellij.openapi.vfs.VirtualFileManager;
10+
import com.intellij.util.ExceptionUtil;
911
import com.intellij.util.containers.JBIterable;
1012
import com.sjhy.plugin.comm.AbstractService;
13+
import com.sjhy.plugin.constants.MsgValue;
1114
import com.sjhy.plugin.entity.ColumnInfo;
1215
import com.sjhy.plugin.entity.TableInfo;
1316
import com.sjhy.plugin.entity.TypeMapper;
@@ -182,7 +185,7 @@ private String getColumnType(String typeName) {
182185
}
183186
}
184187
//弹出消息框
185-
JOptionPane.showMessageDialog(null, "发现未知类型:" + typeName, "温馨提示", JOptionPane.PLAIN_MESSAGE);
188+
Messages.showWarningDialog("发现未知类型:" + typeName, MsgValue.TITLE_INFO);
186189
return "java.lang.Object";
187190
}
188191

@@ -219,18 +222,18 @@ public void save(TableInfo tableInfo) {
219222
try {
220223
content = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(tableInfo);
221224
} catch (JsonProcessingException e) {
222-
e.printStackTrace();
225+
ExceptionUtil.rethrow(e);
223226
}
224227
if (content == null) {
225-
JOptionPane.showMessageDialog(null, "保存失败,JSON序列化错误。", "温馨提示", JOptionPane.PLAIN_MESSAGE);
228+
Messages.showWarningDialog("保存失败,JSON序列化错误。", MsgValue.TITLE_INFO);
226229
return;
227230
}
228231
// 获取或创建保存目录
229232
String path = cacheDataUtils.getProject().getBasePath() + SAVE_PATH;
230233
File dir = new File(path);
231234
if (!dir.exists()) {
232235
if (!dir.mkdir()) {
233-
JOptionPane.showMessageDialog(null, "保存失败,无法创建目录。", "温馨提示", JOptionPane.PLAIN_MESSAGE);
236+
Messages.showWarningDialog("保存失败,无法创建目录。", MsgValue.TITLE_INFO);
234237
return;
235238
}
236239
}
@@ -241,12 +244,12 @@ public void save(TableInfo tableInfo) {
241244
if (!file.exists()) {
242245
try {
243246
if (!file.createNewFile()) {
244-
JOptionPane.showMessageDialog(null, "保存失败,无法创建文件。", "温馨提示", JOptionPane.PLAIN_MESSAGE);
247+
Messages.showWarningDialog("保存失败,无法创建文件。", MsgValue.TITLE_INFO);
245248
return;
246249
}
247250
} catch (IOException e) {
248-
e.printStackTrace();
249-
JOptionPane.showMessageDialog(null, "保存失败,创建文件异常。", "温馨提示", JOptionPane.PLAIN_MESSAGE);
251+
ExceptionUtil.rethrow(e);
252+
Messages.showWarningDialog("保存失败,创建文件异常。", MsgValue.TITLE_INFO);
250253
return;
251254
}
252255
}
@@ -290,8 +293,8 @@ private TableInfo parser(String str) {
290293
try {
291294
return objectMapper.readValue(str, TableInfo.class);
292295
} catch (IOException e) {
293-
e.printStackTrace();
294-
JOptionPane.showMessageDialog(null, "读取配置失败,JSON反序列化异常。", "温馨提示", JOptionPane.PLAIN_MESSAGE);
296+
ExceptionUtil.rethrow(e);
297+
Messages.showWarningDialog("读取配置失败,JSON反序列化异常。", MsgValue.TITLE_INFO);
295298
}
296299
return null;
297300
}

0 commit comments

Comments
 (0)