Skip to content

Commit bb4f295

Browse files
committed
添加插件项目生成脚本工具
1 parent 2e08535 commit bb4f295

2 files changed

Lines changed: 258 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.xwintop.xJavaFxTool.javafx;
2+
3+
import org.apache.commons.io.FileUtils;
4+
import org.apache.commons.io.FilenameUtils;
5+
import org.junit.Test;
6+
7+
import java.io.File;
8+
9+
/**
10+
* @ClassName: PluginProgectBuildTool
11+
* @Description: 插件项目生成工具
12+
* @author: xufeng
13+
* @date: 2020/1/21 13:28
14+
*/
15+
16+
public class PluginProgectBuildTool {
17+
private String projectPath = "E:/ideaWorkspaces/xwintop/xJavaFxTool/src/main/";
18+
// private String projectPath = "";
19+
private String resources = "resources/com/xwintop/xJavaFxTool/";
20+
// private String xmlPath = "assistTools/";
21+
// private String xmlPath = "codeTools/";
22+
// private String xmlPath = "debugTools/";
23+
// private String xmlPath = "developTools/";
24+
// private String xmlPath = "games/";
25+
private String xmlPath = "littleTools/";
26+
// private String xmlPath = "webTools/";
27+
private String srcPath = "java/com/xwintop/xJavaFxTool/";
28+
29+
private String pluginPath = "E:/ideaWorkspaces/xwintop/xJavaFxTool-plugin/";
30+
31+
@Test
32+
public void buildJava() throws Exception {
33+
File[] fxmlFileList = new File(projectPath + resources + "fxmlView/" + xmlPath).listFiles();
34+
for (File file : fxmlFileList) {
35+
if (file.isDirectory()) {
36+
continue;
37+
}
38+
String pluginProgectName = FilenameUtils.getBaseName(file.getName());
39+
String pluginProgectPath = pluginPath + xmlPath + "x-" + pluginProgectName;
40+
File pluginProgectNameFile = new File(pluginProgectPath);
41+
if (pluginProgectNameFile.exists()) {
42+
continue;
43+
}
44+
pluginProgectNameFile.mkdir();
45+
pluginProgectPath = pluginProgectPath + "/src/main/";
46+
FileUtils.writeStringToFile(new File(pluginProgectNameFile, "pom.xml"), PluginProgectPomBuildTool.getPom_xml(pluginProgectName), "utf-8");
47+
FileUtils.writeStringToFile(new File(pluginProgectNameFile, "README.md"), pluginProgectName, "utf-8");
48+
FileUtils.writeStringToFile(new File(pluginProgectNameFile, "README_EN.md"), pluginProgectName, "utf-8");
49+
FileUtils.writeStringToFile(new File(pluginProgectNameFile, ".gitignore"), PluginProgectPomBuildTool.getGitignore(pluginProgectName), "utf-8");
50+
FileUtils.writeStringToFile(new File(pluginProgectPath + srcPath + "Main.java"), PluginProgectPomBuildTool.getMain_java(pluginProgectName, xmlPath.substring(0, xmlPath.length() - 1)), "utf-8");
51+
new File(pluginProgectPath + srcPath + "job").mkdirs();
52+
new File(pluginProgectPath + srcPath + "manager").mkdirs();
53+
new File(pluginProgectPath + srcPath + "model").mkdirs();
54+
new File(pluginProgectPath + srcPath + "utils").mkdirs();
55+
56+
FileUtils.writeStringToFile(new File(pluginProgectPath + "resources/config/toolFxmlLoaderConfiguration.xml"), PluginProgectPomBuildTool.getToolFxmlLoaderConfiguration_xml(pluginProgectName, xmlPath.substring(0, xmlPath.length() - 1)), "utf-8");
57+
FileUtils.writeStringToFile(new File(pluginProgectPath + "resources/locale/" + pluginProgectName + ".properties"), PluginProgectPomBuildTool.getLocal_properties(pluginProgectName), "utf-8");
58+
FileUtils.writeStringToFile(new File(pluginProgectPath + "resources/locale/" + pluginProgectName + "_en_US.properties"), PluginProgectPomBuildTool.getLocal_en_US_properties(pluginProgectName), "utf-8");
59+
60+
copyPluginFile(resources + "fxmlView/" + xmlPath + file.getName(), pluginProgectPath);
61+
copyPluginFile(srcPath + "controller/" + xmlPath + pluginProgectName + "Controller.java", pluginProgectPath);
62+
copyPluginFile(srcPath + "services/" + xmlPath + pluginProgectName + "Service.java", pluginProgectPath);
63+
copyPluginFile(srcPath + "view/" + xmlPath + pluginProgectName + "View.java", pluginProgectPath);
64+
// break;
65+
}
66+
}
67+
68+
private void copyPluginFile(String path, String pluginProgectPath) {
69+
try {
70+
File fromFile = new File(projectPath + path);
71+
if (fromFile.exists()) {
72+
File toFile = new File(pluginProgectPath + path);
73+
toFile.getParentFile().mkdirs();
74+
FileUtils.copyFile(fromFile, toFile);
75+
}
76+
} catch (Exception e) {
77+
e.printStackTrace();
78+
}
79+
}
80+
}
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
package com.xwintop.xJavaFxTool.javafx;
2+
3+
public class PluginProgectPomBuildTool {
4+
public static String getPom_xml(String projectName) {
5+
return "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
6+
"\txsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" +
7+
"\t<modelVersion>4.0.0</modelVersion>\n" +
8+
"\n" +
9+
"\t<groupId>com.xwintop</groupId>\n" +
10+
"\t<artifactId>x-"+projectName+"</artifactId>\n" +
11+
"\t<version>0.0.1</version>\n" +
12+
"\t<packaging>jar</packaging>\n" +
13+
"\t<name>x-" + projectName + "</name>\n" +
14+
"\n" +
15+
"\t<properties>\n" +
16+
"\t\t<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\n" +
17+
"\t</properties>\n" +
18+
"\n" +
19+
"\t<repositories>\n" +
20+
"\t\t<repository>\n" +
21+
"\t\t\t<id>aliyunmaven</id>\n" +
22+
"\t\t\t<url>http://maven.aliyun.com/nexus/content/groups/public/</url>\n" +
23+
"\t\t</repository>\n" +
24+
"\t\t<repository>\n" +
25+
"\t\t\t<id>xwintop-maven</id>\n" +
26+
"\t\t\t<url>https://xwintop.gitee.io/maven/repository</url>\n" +
27+
"\t\t</repository>\n" +
28+
"\t\t<repository>\n" +
29+
"\t\t\t<id>spring-snapshots</id>\n" +
30+
"\t\t\t<url>http://repo.spring.io/snapshot</url>\n" +
31+
"\t\t\t<snapshots>\n" +
32+
"\t\t\t\t<enabled>true</enabled>\n" +
33+
"\t\t\t</snapshots>\n" +
34+
"\t\t</repository>\n" +
35+
"\t\t<repository>\n" +
36+
"\t\t\t<id>spring-milestones</id>\n" +
37+
"\t\t\t<url>http://repo.spring.io/milestone</url>\n" +
38+
"\t\t</repository>\n" +
39+
"\t</repositories>\n" +
40+
"\n" +
41+
"\t<dependencies>\n" +
42+
"\t\t<dependency>\n" +
43+
"\t\t\t<groupId>junit</groupId>\n" +
44+
"\t\t\t<artifactId>junit</artifactId>\n" +
45+
"\t\t\t<version>4.12</version>\n" +
46+
"\t\t\t<scope>test</scope>\n" +
47+
"\t\t</dependency>\n" +
48+
"\t\t<dependency>\n" +
49+
"\t\t\t<groupId>com.xwintop</groupId>\n" +
50+
"\t\t\t<artifactId>xcore</artifactId>\n" +
51+
"\t\t\t<version>0.0.2-SNAPSHOT</version>\n" +
52+
"\t\t\t<scope>provided</scope>\n" +
53+
"\t\t</dependency>\n" +
54+
"\n" +
55+
"\t</dependencies>\n" +
56+
"\t\n" +
57+
"\t<build>\n" +
58+
"\t\t<plugins>\n" +
59+
"\t\t\t<plugin>\n" +
60+
"\t\t\t\t<groupId>org.apache.maven.plugins</groupId>\n" +
61+
"\t\t\t\t<artifactId>maven-assembly-plugin</artifactId>\n" +
62+
"\t\t\t\t<version>2.5.5</version>\n" +
63+
"\t\t\t\t<configuration>\n" +
64+
"\t\t\t\t\t<appendAssemblyId>false</appendAssemblyId>\n" +
65+
"\t\t\t\t\t<encoding>utf-8</encoding>\n" +
66+
"<!--\t\t\t\t\t<archive>-->\n" +
67+
"<!--\t\t\t\t\t\t<manifest>-->\n" +
68+
"<!--\t\t\t\t\t\t\t<mainClass>com.xwintop.xJavaFxTool.Main</mainClass>-->\n" +
69+
"<!--\t\t\t\t\t\t</manifest>-->\n" +
70+
"<!--\t\t\t\t\t</archive>-->\n" +
71+
"\t\t\t\t\t<descriptorRefs>\n" +
72+
"\t\t\t\t\t\t<descriptorRef>jar-with-dependencies</descriptorRef>\n" +
73+
"\t\t\t\t\t</descriptorRefs>\n" +
74+
"\t\t\t\t</configuration>\n" +
75+
"\t\t\t\t<executions>\n" +
76+
"\t\t\t\t\t<execution>\n" +
77+
"\t\t\t\t\t\t<id>make-assembly</id>\n" +
78+
"\t\t\t\t\t\t<phase>package</phase>\n" +
79+
"\t\t\t\t\t\t<goals>\n" +
80+
"\t\t\t\t\t\t\t<goal>single</goal>\n" +
81+
"\t\t\t\t\t\t</goals>\n" +
82+
"\t\t\t\t\t</execution>\n" +
83+
"\t\t\t\t</executions>\n" +
84+
"\t\t\t</plugin>\n" +
85+
"\t\t</plugins>\n" +
86+
"\t</build>\n" +
87+
"</project>\n";
88+
}
89+
90+
public static String getGitignore(String projectName) {
91+
return "# Default ignored files\n" +
92+
"#/.gitignore\n" +
93+
"/x-" + projectName + ".iml\n" +
94+
"/log/\n" +
95+
"/target/";
96+
}
97+
98+
public static String getMain_java(String projectName, String xmlPath) {
99+
return "package com.xwintop.xJavaFxTool;\n" +
100+
"\n" +
101+
"import javafx.application.Application;\n" +
102+
"import javafx.event.EventHandler;\n" +
103+
"import javafx.fxml.FXMLLoader;\n" +
104+
"import javafx.scene.Parent;\n" +
105+
"import javafx.scene.Scene;\n" +
106+
"import javafx.stage.Stage;\n" +
107+
"import javafx.stage.WindowEvent;\n" +
108+
"import lombok.extern.slf4j.Slf4j;\n" +
109+
"\n" +
110+
"import java.net.URL;\n" +
111+
"import java.util.ResourceBundle;\n" +
112+
"\n" +
113+
"@Slf4j\n" +
114+
"public class Main extends Application {\n" +
115+
" public static void main(String[] args) {\n" +
116+
" try {\n" +
117+
" launch(args);\n" +
118+
" } catch (Exception e) {\n" +
119+
" e.printStackTrace();\n" +
120+
" }\n" +
121+
" }\n" +
122+
"\n" +
123+
" @Override\n" +
124+
" public void start(Stage primaryStage) throws Exception {\n" +
125+
" FXMLLoader fXMLLoader = Main.getFXMLLoader();\n" +
126+
" ResourceBundle resourceBundle = fXMLLoader.getResources();\n" +
127+
" Parent root = fXMLLoader.load();\n" +
128+
" primaryStage.setResizable(true);\n" +
129+
" primaryStage.setTitle(resourceBundle.getString(\"Title\"));\n" +
130+
"// primaryStage.getIcons().add(new Image(\"/images/icon.jpg\"));\n" +
131+
" primaryStage.setScene(new Scene(root));\n" +
132+
" primaryStage.show();\n" +
133+
" primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {\n" +
134+
" @Override\n" +
135+
" public void handle(WindowEvent event) {\n" +
136+
" System.exit(0);\n" +
137+
" }\n" +
138+
" });\n" +
139+
" }\n" +
140+
"\n" +
141+
" public static FXMLLoader getFXMLLoader() {\n" +
142+
" ResourceBundle resourceBundle = ResourceBundle.getBundle(\"locale." + projectName + "\");\n" +
143+
" URL url = Object.class.getResource(\"/com/xwintop/xJavaFxTool/fxmlView/" + xmlPath + "/" + projectName + ".fxml\");\n" +
144+
" FXMLLoader fXMLLoader = new FXMLLoader(url, resourceBundle);\n" +
145+
" return fXMLLoader;\n" +
146+
" }\n" +
147+
"}";
148+
}
149+
150+
public static String getToolFxmlLoaderConfiguration_xml(String projectName, String xmlPath) {
151+
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
152+
"<root>\n" +
153+
"\t<ToolFxmlLoaderConfiguration title=\"" + xmlPath + "\" menuId=\"p-" + xmlPath + "\" menuParentId=\"moreToolsMenu\" isMenu=\"true\" />\n" +
154+
"\t<ToolFxmlLoaderConfiguration>\n" +
155+
"\t\t<url>/com/xwintop/xJavaFxTool/fxmlView/" + xmlPath + "/" + projectName + ".fxml</url>\n" +
156+
"\t\t<resourceBundleName>locale." + projectName + "</resourceBundleName>\n" +
157+
"\t\t<className></className>\n" +
158+
"\t\t<title>Title</title>\n" +
159+
"\t\t<isDefaultShow></isDefaultShow>\n" +
160+
"\t\t<menuId></menuId>\n" +
161+
"\t\t<menuParentId>p-" + xmlPath + "</menuParentId>\n" +
162+
"\t\t<controllerType>Node</controllerType>\n" +
163+
"\t</ToolFxmlLoaderConfiguration>\n" +
164+
"</root>";
165+
}
166+
167+
public static String getLocal_properties(String projectName) {
168+
return "# Dorian.properties是默认的\"Dorian\"资源束文件。 \n" +
169+
"# 作为中国人,我用自己的地区作为默认 \n" +
170+
"Title=" + projectName;
171+
}
172+
173+
public static String getLocal_en_US_properties(String projectName) {
174+
return "# 文件Dorian_en_US.properties,是美国地区的资源束 \n" +
175+
"# 它覆盖了默认资源束 \n" +
176+
"Title=" + projectName;
177+
}
178+
}

0 commit comments

Comments
 (0)