Skip to content

Commit 332ef98

Browse files
committed
WIP: [newui]重写插件 jar 解析方式
1 parent 1311d60 commit 332ef98

4 files changed

Lines changed: 215 additions & 124 deletions

File tree

pom.xml

Lines changed: 128 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,135 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
44

5-
<groupId>com.xwintop</groupId>
6-
<artifactId>xJavaFxTool</artifactId>
7-
<version>0.2.1</version>
8-
<packaging>jar</packaging>
9-
<name>xJavaFxTool</name>
10-
<description>基于JavaFx搭建的实用小工具集合</description>
11-
<url>https://gitee.com/xwintop/xJavaFxTool</url>
5+
<groupId>com.xwintop</groupId>
6+
<artifactId>xJavaFxTool</artifactId>
7+
<version>0.2.1</version>
8+
<packaging>jar</packaging>
9+
<name>xJavaFxTool</name>
10+
<description>基于JavaFx搭建的实用小工具集合</description>
11+
<url>https://gitee.com/xwintop/xJavaFxTool</url>
1212

13-
<!-- <parent>-->
14-
<!-- <groupId>org.springframework.boot</groupId>-->
15-
<!-- <artifactId>spring-boot-starter-parent</artifactId>-->
16-
<!-- <version>2.1.3.RELEASE</version>-->
17-
<!-- </parent>-->
13+
<!-- <parent>-->
14+
<!-- <groupId>org.springframework.boot</groupId>-->
15+
<!-- <artifactId>spring-boot-starter-parent</artifactId>-->
16+
<!-- <version>2.1.3.RELEASE</version>-->
17+
<!-- </parent>-->
1818

19-
<properties>
20-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21-
<maven.test.skip>true</maven.test.skip>
22-
<maven.compiler.source>1.8</maven.compiler.source>
23-
<maven.compiler.target>1.8</maven.compiler.target>
24-
</properties>
25-
<repositories>
26-
<repository>
27-
<id>aliyunmaven</id>
28-
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
29-
</repository>
30-
<repository>
31-
<id>xwintop-maven</id>
32-
<url>https://xwintop.gitee.io/maven/repository</url>
33-
</repository>
34-
<repository>
35-
<id>spring-snapshots</id>
36-
<url>http://repo.spring.io/snapshot</url>
37-
<snapshots>
38-
<enabled>true</enabled>
39-
</snapshots>
40-
</repository>
41-
<repository>
42-
<id>spring-milestones</id>
43-
<url>http://repo.spring.io/milestone</url>
44-
</repository>
45-
</repositories>
46-
<dependencies>
47-
<dependency>
48-
<groupId>junit</groupId>
49-
<artifactId>junit</artifactId>
50-
<version>4.12</version>
51-
<scope>test</scope>
52-
</dependency>
53-
<dependency>
54-
<groupId>com.xwintop</groupId>
55-
<artifactId>xcore</artifactId>
56-
<version>0.0.4-SNAPSHOT</version>
57-
</dependency>
19+
<properties>
20+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21+
<maven.test.skip>true</maven.test.skip>
22+
<maven.compiler.source>1.8</maven.compiler.source>
23+
<maven.compiler.target>1.8</maven.compiler.target>
24+
</properties>
25+
<repositories>
26+
<repository>
27+
<id>aliyunmaven</id>
28+
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
29+
</repository>
30+
<repository>
31+
<id>xwintop-maven</id>
32+
<url>https://xwintop.gitee.io/maven/repository</url>
33+
</repository>
34+
<repository>
35+
<id>spring-snapshots</id>
36+
<url>http://repo.spring.io/snapshot</url>
37+
<snapshots>
38+
<enabled>true</enabled>
39+
</snapshots>
40+
</repository>
41+
<repository>
42+
<id>spring-milestones</id>
43+
<url>http://repo.spring.io/milestone</url>
44+
</repository>
45+
</repositories>
46+
<dependencies>
47+
<dependency>
48+
<groupId>junit</groupId>
49+
<artifactId>junit</artifactId>
50+
<version>4.12</version>
51+
<scope>test</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>com.xwintop</groupId>
55+
<artifactId>xcore</artifactId>
56+
<version>0.0.4-SNAPSHOT</version>
57+
</dependency>
58+
<!-- dom4j 需要的依赖 -->
59+
<dependency>
60+
<groupId>jaxen</groupId>
61+
<artifactId>jaxen</artifactId>
62+
<version>1.2.0</version>
63+
</dependency>
5864

59-
<!-- oshi获取系统信息工具 -->
60-
<dependency>
61-
<groupId>com.github.oshi</groupId>
62-
<artifactId>oshi-core</artifactId>
63-
<version>3.9.1</version>
64-
</dependency>
65+
<!-- oshi获取系统信息工具 -->
66+
<dependency>
67+
<groupId>com.github.oshi</groupId>
68+
<artifactId>oshi-core</artifactId>
69+
<version>3.9.1</version>
70+
</dependency>
6571

66-
</dependencies>
67-
<build>
68-
<plugins>
69-
<plugin>
70-
<groupId>org.apache.maven.plugins</groupId>
71-
<artifactId>maven-assembly-plugin</artifactId>
72-
<version>2.5.5</version>
73-
<configuration>
74-
<finalName>xJavaFxTool</finalName>
75-
<appendAssemblyId>false</appendAssemblyId>
76-
<encoding>utf-8</encoding>
77-
<archive>
78-
<manifest>
79-
<mainClass>com.xwintop.xJavaFxTool.Main</mainClass>
80-
</manifest>
81-
</archive>
82-
<descriptorRefs>
83-
<descriptorRef>jar-with-dependencies</descriptorRef>
84-
</descriptorRefs>
85-
</configuration>
86-
<executions>
87-
<execution>
88-
<id>make-assembly</id>
89-
<phase>package</phase>
90-
<goals>
91-
<goal>single</goal>
92-
</goals>
93-
</execution>
94-
</executions>
95-
</plugin>
96-
<plugin>
97-
<groupId>com.zenjava</groupId>
98-
<artifactId>javafx-maven-plugin</artifactId>
99-
<version>8.8.3</version>
100-
<configuration>
101-
<mainClass>com.xwintop.xJavaFxTool.Main</mainClass>
102-
<vendor>xwintop</vendor>
103-
<appName>xJavaFxTool</appName>
104-
</configuration>
105-
</plugin>
106-
<!-- 生成javadoc文档包的插件 -->
107-
<plugin>
108-
<groupId>org.apache.maven.plugins</groupId>
109-
<artifactId>maven-javadoc-plugin</artifactId>
110-
<version>3.1.1</version>
111-
<configuration>
112-
<show>private</show>
113-
<nohelp>true</nohelp>
114-
<additionalOptions>
115-
<additionalOption>-Xdoclint:none</additionalOption>
116-
</additionalOptions>
117-
</configuration>
118-
<executions>
119-
<execution>
120-
<id>attach-javadocs</id>
121-
<goals>
122-
<goal>jar</goal>
123-
</goals>
124-
</execution>
125-
</executions>
126-
</plugin>
127-
</plugins>
128-
</build>
72+
</dependencies>
73+
<build>
74+
<plugins>
75+
<plugin>
76+
<groupId>org.apache.maven.plugins</groupId>
77+
<artifactId>maven-assembly-plugin</artifactId>
78+
<version>2.5.5</version>
79+
<configuration>
80+
<finalName>xJavaFxTool</finalName>
81+
<appendAssemblyId>false</appendAssemblyId>
82+
<encoding>utf-8</encoding>
83+
<archive>
84+
<manifest>
85+
<mainClass>com.xwintop.xJavaFxTool.Main</mainClass>
86+
</manifest>
87+
</archive>
88+
<descriptorRefs>
89+
<descriptorRef>jar-with-dependencies</descriptorRef>
90+
</descriptorRefs>
91+
</configuration>
92+
<executions>
93+
<execution>
94+
<id>make-assembly</id>
95+
<phase>package</phase>
96+
<goals>
97+
<goal>single</goal>
98+
</goals>
99+
</execution>
100+
</executions>
101+
</plugin>
102+
<plugin>
103+
<groupId>com.zenjava</groupId>
104+
<artifactId>javafx-maven-plugin</artifactId>
105+
<version>8.8.3</version>
106+
<configuration>
107+
<mainClass>com.xwintop.xJavaFxTool.Main</mainClass>
108+
<vendor>xwintop</vendor>
109+
<appName>xJavaFxTool</appName>
110+
</configuration>
111+
</plugin>
112+
<!-- 生成javadoc文档包的插件 -->
113+
<plugin>
114+
<groupId>org.apache.maven.plugins</groupId>
115+
<artifactId>maven-javadoc-plugin</artifactId>
116+
<version>3.1.1</version>
117+
<configuration>
118+
<show>private</show>
119+
<nohelp>true</nohelp>
120+
<additionalOptions>
121+
<additionalOption>-Xdoclint:none</additionalOption>
122+
</additionalOptions>
123+
</configuration>
124+
<executions>
125+
<execution>
126+
<id>attach-javadocs</id>
127+
<goals>
128+
<goal>jar</goal>
129+
</goals>
130+
</execution>
131+
</executions>
132+
</plugin>
133+
</plugins>
134+
</build>
129135
</project>

src/main/java/com/xwintop/xJavaFxTool/model/PluginJarInfo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ public class PluginJarInfo {
4343

4444
private String className; // ?
4545

46-
private String menuId; // 菜单id
46+
private String menuId; // (当是菜单时)菜单ID
4747

48-
private String menuParentId; // 菜单父id
48+
private String menuParentId; // 上级菜单ID
49+
50+
private String menuParentTitle; // 上级菜单标题(资源名)
4951

5052
private Boolean isMenu = false; // 是否为菜单
5153

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.xwintop.xJavaFxTool.plugin;
2+
3+
import com.xwintop.xJavaFxTool.model.PluginJarInfo;
4+
import java.io.File;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.util.HashMap;
8+
import java.util.List;
9+
import java.util.Map;
10+
import java.util.jar.JarEntry;
11+
import java.util.jar.JarFile;
12+
import java.util.stream.Collectors;
13+
import org.dom4j.Document;
14+
import org.dom4j.DocumentException;
15+
import org.dom4j.Element;
16+
import org.dom4j.io.SAXReader;
17+
18+
/**
19+
* 用来解析插件文件中的 toolFxmlLoaderConfiguration.xml
20+
*/
21+
public class PluginParser {
22+
23+
public static final String ENTRY_NAME = "config/toolFxmlLoaderConfiguration.xml";
24+
25+
/**
26+
* 解析插件文件,补完 pluginJarInfo 属性
27+
*/
28+
public static void parse(File pluginFile, PluginJarInfo pluginJarInfo) throws IOException, DocumentException {
29+
try (JarFile jarFile = new JarFile(pluginFile)) {
30+
31+
JarEntry entry = jarFile.getJarEntry(ENTRY_NAME);
32+
if (entry == null) {
33+
return;
34+
}
35+
36+
Element root = createRootElement(jarFile, entry);
37+
List<Element> menuElements = selectElements(root, "/root/ToolFxmlLoaderConfiguration[@isMenu='true']");
38+
Element pluginElement = selectSingleElement(root, "/root/ToolFxmlLoaderConfiguration[not(@isMenu)]");
39+
40+
Map<String, String> menuTitles = new HashMap<>();
41+
for (Element menuElement : menuElements) {
42+
menuTitles.put(menuElement.attributeValue("menuId"), menuElement.attributeValue("title"));
43+
}
44+
45+
String menuId = pluginElement.selectSingleNode("child::menuParentId").getText();
46+
String menuTitle = menuTitles.get(menuId);
47+
48+
pluginJarInfo.setMenuParentTitle(menuTitle);
49+
}
50+
51+
}
52+
53+
private static Element createRootElement(JarFile jarFile, JarEntry entry) throws IOException, DocumentException {
54+
InputStream input = jarFile.getInputStream(entry);
55+
SAXReader saxReader = new SAXReader();
56+
Document document = saxReader.read(input);
57+
return document.getRootElement();
58+
}
59+
60+
private static List<Element> selectElements(Element root, String xpath) {
61+
return root.selectNodes(xpath).stream()
62+
.filter(n -> n instanceof Element).map(n -> (Element) n)
63+
.collect(Collectors.toList());
64+
}
65+
66+
private static Element selectSingleElement(Element root, String xpath) {
67+
return root.selectNodes(xpath).stream()
68+
.filter(n -> n instanceof Element).map(n -> (Element) n)
69+
.findFirst().orElse(null);
70+
}
71+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.xwintop.xJavaFxTool.plugin;
2+
3+
import com.xwintop.xJavaFxTool.model.PluginJarInfo;
4+
import java.io.File;
5+
6+
public class PluginParserTest {
7+
8+
public static void main(String[] args) throws Exception {
9+
String pluginJar = "libs/x-ActiveMqTool-0.0.1.jar";
10+
PluginParser.parse(new File(pluginJar), new PluginJarInfo());
11+
}
12+
}

0 commit comments

Comments
 (0)