1
1
package com .sjhy .plugin .tool ;
2
2
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 ;
4
7
import com .intellij .util .xmlb .XmlSerializerUtil ;
5
8
import com .intellij .util .xmlb .annotations .Transient ;
6
9
import com .sjhy .plugin .entity .*;
7
10
import lombok .Data ;
8
- import org .apache .commons .lang3 .StringUtils ;
9
11
import org .jetbrains .annotations .NotNull ;
10
12
import org .jetbrains .annotations .Nullable ;
11
13
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 ;
16
18
17
19
/**
18
20
* 全局配置信息
@@ -111,9 +113,8 @@ public void initDefault() {
111
113
if (this .templateGroupMap == null ) {
112
114
this .templateGroupMap = new LinkedHashMap <>();
113
115
}
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" ));
117
118
118
119
//配置默认类型映射
119
120
if (this .typeMapperGroupMap == null ) {
@@ -151,9 +152,7 @@ public void initDefault() {
151
152
if (this .globalConfigGroupMap == null ) {
152
153
this .globalConfigGroupMap = new LinkedHashMap <>();
153
154
}
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" ));
157
156
}
158
157
159
158
/**
@@ -169,71 +168,35 @@ private static String loadTemplate(String filePath) {
169
168
/**
170
169
* 加载模板组
171
170
*
172
- * @param groupName 组名
171
+ * @param groupName 组名
172
+ * @param templateNames 模板名称
173
173
* @return 模板组
174
174
*/
175
- private static TemplateGroup loadTemplateGroup (String groupName ) {
175
+ private static TemplateGroup loadTemplateGroup (String groupName , String ... templateNames ) {
176
176
TemplateGroup templateGroup = new TemplateGroup ();
177
177
templateGroup .setName (groupName );
178
178
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 )));
201
182
}
202
183
return templateGroup ;
203
184
}
204
185
205
186
/**
206
187
* 加载全局配置组
207
188
*
208
- * @param groupName 组名
189
+ * @param groupName 组名
190
+ * @param templateNames 模板名称
209
191
* @return 模板组
210
192
*/
211
- private static GlobalConfigGroup loadGlobalConfigGroup (String groupName ) {
193
+ private static GlobalConfigGroup loadGlobalConfigGroup (String groupName , String ... templateNames ) {
212
194
GlobalConfigGroup globalConfigGroup = new GlobalConfigGroup ();
213
195
globalConfigGroup .setName (groupName );
214
196
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 )));
237
200
}
238
201
return globalConfigGroup ;
239
202
}
@@ -253,7 +216,7 @@ public void loadState(@NotNull ConfigInfo configInfo) {
253
216
XmlSerializerUtil .copyBean (configInfo , this );
254
217
255
218
// 已经合并不再重复合并
256
- if (configInfo .getVersion ()!= null && configInfo .getVersion ().equals (version )) {
219
+ if (configInfo .getVersion () != null && configInfo .getVersion ().equals (version )) {
257
220
return ;
258
221
}
259
222
0 commit comments