parent
ee0367ae68
commit
d9b2ef2e39
|
@ -0,0 +1,13 @@
|
||||||
|
<component name="libraryTable">
|
||||||
|
<library name="Maven: org.yaml:snakeyaml:1.30">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$PROJECT_DIR$/../../../basic/Maven/maven_repository/org/yaml/snakeyaml/1.30/snakeyaml-1.30.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC>
|
||||||
|
<root url="jar://$PROJECT_DIR$/../../../basic/Maven/maven_repository/org/yaml/snakeyaml/1.30/snakeyaml-1.30-javadoc.jar!/" />
|
||||||
|
</JAVADOC>
|
||||||
|
<SOURCES>
|
||||||
|
<root url="jar://$PROJECT_DIR$/../../../basic/Maven/maven_repository/org/yaml/snakeyaml/1.30/snakeyaml-1.30-sources.jar!/" />
|
||||||
|
</SOURCES>
|
||||||
|
</library>
|
||||||
|
</component>
|
|
@ -7,6 +7,7 @@ import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
@ -30,6 +31,16 @@ public abstract class ProcessAppTemplate implements MiniApp, ActionListener {
|
||||||
*/
|
*/
|
||||||
public abstract String getCmdStr();
|
public abstract String getCmdStr();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路径位置
|
||||||
|
*
|
||||||
|
* 默认null
|
||||||
|
* @return 执行命令所在路径
|
||||||
|
*/
|
||||||
|
public String getRunPath() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JPanel getPanel() {
|
public JPanel getPanel() {
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
|
@ -96,7 +107,17 @@ public abstract class ProcessAppTemplate implements MiniApp, ActionListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
process = Runtime.getRuntime().exec(getCmdStr());
|
File file = null;
|
||||||
|
|
||||||
|
if (getRunPath() != null && !getRunPath().equals("")) {
|
||||||
|
file = new File(getRunPath());
|
||||||
|
if (!file.exists()) {
|
||||||
|
failWrite("未找到启动路径:" + getRunPath());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
process = Runtime.getRuntime().exec(getCmdStr(), null, file);
|
||||||
successWrite("启动成功!");
|
successWrite("启动成功!");
|
||||||
heartbeatCheck();
|
heartbeatCheck();
|
||||||
String tmp;
|
String tmp;
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="module" module-name="BKPG_PROTOCAL" />
|
<orderEntry type="module" module-name="BKPG_PROTOCAL" scope="PROVIDED" />
|
||||||
|
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.30" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
|
@ -20,6 +20,13 @@
|
||||||
<groupId>top.dreamcenter.bkpg</groupId>
|
<groupId>top.dreamcenter.bkpg</groupId>
|
||||||
<artifactId>BKPG_PROTOCAL</artifactId>
|
<artifactId>BKPG_PROTOCAL</artifactId>
|
||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
<version>1.30</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -27,10 +34,23 @@
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
<appendAssemblyId>false</appendAssemblyId>
|
||||||
<outputDirectory>${project.parent.basedir}/ext</outputDirectory>
|
<outputDirectory>${project.parent.basedir}/ext</outputDirectory>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>make-assembly</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package top.dreamcenter.bkpg.group;
|
package top.dreamcenter.bkpg.group;
|
||||||
|
|
||||||
|
import top.dreamcenter.bkpg.group.bean.ProcessConfigBean;
|
||||||
|
import top.dreamcenter.bkpg.group.util.YamlUtil;
|
||||||
import top.dreamcenter.bkpg.protocal.MiniApp;
|
import top.dreamcenter.bkpg.protocal.MiniApp;
|
||||||
import top.dreamcenter.bkpg.protocal.MiniAppGroup;
|
import top.dreamcenter.bkpg.protocal.MiniAppGroup;
|
||||||
import top.dreamcenter.bkpg.protocal.template.ProcessAppTemplate;
|
import top.dreamcenter.bkpg.protocal.template.ProcessAppTemplate;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import javax.swing.*;
|
||||||
import java.io.FileInputStream;
|
import java.awt.*;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -14,27 +15,27 @@ public class ProcessGroupApp implements MiniAppGroup {
|
||||||
@Override
|
@Override
|
||||||
public List<MiniApp> getMiniApps() {
|
public List<MiniApp> getMiniApps() {
|
||||||
|
|
||||||
|
ProcessConfigBean processConfig = null;
|
||||||
List<MiniApp> list = new LinkedList<>();
|
List<MiniApp> list = new LinkedList<>();
|
||||||
|
try {
|
||||||
|
processConfig = YamlUtil.getProcessConfig("ext/ProgressGroup.yml");
|
||||||
|
|
||||||
|
// 从配置装载命令
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("ext/ProgressGroup.txt")))) {
|
for (ProcessConfigBean.ProcessBean bean : processConfig.getProcessBeanList()){
|
||||||
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
String[] split = line.split(": ");
|
|
||||||
|
|
||||||
String appName = split[0];
|
|
||||||
String appCmd = split[1];
|
|
||||||
|
|
||||||
MiniApp miniApp = new ProcessAppTemplate() {
|
MiniApp miniApp = new ProcessAppTemplate() {
|
||||||
@Override
|
@Override
|
||||||
public String getCmdStr() {
|
public String getCmdStr() {
|
||||||
return appCmd;
|
return bean.getCmd();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return appName;
|
return bean.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRunPath() {
|
||||||
|
return bean.getPath();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,8 +43,37 @@ public class ProcessGroupApp implements MiniAppGroup {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println(e.getMessage());
|
// 异常则显示异常面板
|
||||||
return list;
|
MiniApp miniApp = new MiniApp() {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "ProcessGroupApp";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JPanel getPanel() {
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
panel.setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
JTextArea textArea = new JTextArea();
|
||||||
|
textArea.setText(e.getMessage());
|
||||||
|
textArea.setForeground(Color.RED);
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
|
||||||
|
JScrollPane scrollPane = new JScrollPane(textArea);
|
||||||
|
textArea.setRows(15);
|
||||||
|
|
||||||
|
panel.add(scrollPane);
|
||||||
|
return panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean protect() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
list.add(miniApp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package top.dreamcenter.bkpg.group.bean;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ProcessConfigBean {
|
||||||
|
|
||||||
|
private List<ProcessBean> processBeanList;
|
||||||
|
|
||||||
|
public List<ProcessBean> getProcessBeanList() {
|
||||||
|
return processBeanList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProcessBeanList(List<ProcessBean> processBeanList) {
|
||||||
|
this.processBeanList = processBeanList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ProcessBean{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 指令
|
||||||
|
*/
|
||||||
|
private String cmd;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路径
|
||||||
|
*/
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCmd() {
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCmd(String cmd) {
|
||||||
|
this.cmd = cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPath(String path) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package top.dreamcenter.bkpg.group.util;
|
||||||
|
|
||||||
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
import org.yaml.snakeyaml.constructor.Constructor;
|
||||||
|
import top.dreamcenter.bkpg.group.bean.ProcessConfigBean;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public class YamlUtil {
|
||||||
|
|
||||||
|
public static ProcessConfigBean getProcessConfig(String path) throws IOException {
|
||||||
|
Yaml yaml = new Yaml(new Constructor(ProcessConfigBean.class));
|
||||||
|
|
||||||
|
try (InputStream in = new FileInputStream(path)) {
|
||||||
|
return yaml.load(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
19
README.md
19
README.md
|
@ -50,6 +50,7 @@ MiniAppGroup
|
||||||
ProcessAppTemplate: MiniApp
|
ProcessAppTemplate: MiniApp
|
||||||
- String getName(); // 获取应用名称
|
- String getName(); // 获取应用名称
|
||||||
- String getCmdStr(); // 需要执行的命令
|
- String getCmdStr(); // 需要执行的命令
|
||||||
|
- String getRunPath(); // 默认实现返回null,表示指令执行目录环境
|
||||||
- 其余基类函数已默认实现
|
- 其余基类函数已默认实现
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,13 +88,25 @@ protect() 是保护函数,如果返回true,则表示在BKPG进行RELOAD时
|
||||||
用于执行命令行指令,需要实现两个接口,一个是getName,作用同上,另外一个是该抽象类
|
用于执行命令行指令,需要实现两个接口,一个是getName,作用同上,另外一个是该抽象类
|
||||||
独有的,getCmdStr,需要设置命令行的完整执行指令。当点击面板的执行按钮时,
|
独有的,getCmdStr,需要设置命令行的完整执行指令。当点击面板的执行按钮时,
|
||||||
会启动一个线程来执行该命令,并且每5s会检测一次命令心跳,如果心跳失去连接,
|
会启动一个线程来执行该命令,并且每5s会检测一次命令心跳,如果心跳失去连接,
|
||||||
则会释放资源。可以作为一些应用或者服务的启动端。
|
则会释放资源。
|
||||||
|
如果说有的指令需要在特定目录下执行,可以覆盖getRunPath,来指定运行环境。
|
||||||
|
可以作为一些应用或者服务的启动端。
|
||||||
|
|
||||||
|
|
||||||
为了更加高效的添加命令(常用),
|
为了更加高效的添加命令(常用),
|
||||||
官方内置了一个命令AppGroup: **PLUGIN_BKPG_GROUP_PROCESS** 。
|
官方内置了一个命令AppGroup: **PLUGIN_BKPG_GROUP_PROCESS** 。
|
||||||
通过配置ext/ProgressGroup.txt来添加指令应用,
|
通过配置ext/ProgressGroup.yml来添加指令应用,
|
||||||
指令名称和指令用英文冒号和一个空格隔开【: 】,会自动创建多组ProcessAppTemplate。
|
会自动创建多组ProcessAppTemplate。格式参考:
|
||||||
|
```yml
|
||||||
|
processBeanList:
|
||||||
|
- name: PING百度
|
||||||
|
cmd: ping www.baidu.com
|
||||||
|
- name: PING主站
|
||||||
|
cmd: ping www.dreamcenter.top
|
||||||
|
- name: nginx
|
||||||
|
cmd: D:\basic\nginx-1.24.0\nginx
|
||||||
|
path: D:\basic\nginx-1.24.0
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
PING百度: ping www.baidu.com
|
|
||||||
PING主站: ping www.dreamcenter.top
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
processBeanList:
|
||||||
|
- name: PING百度
|
||||||
|
cmd: ping www.baidu.com
|
||||||
|
- name: PING主站
|
||||||
|
cmd: ping www.dreamcenter.top
|
||||||
|
- name: nginx
|
||||||
|
cmd: D:\basic\nginx-1.24.0\nginx
|
||||||
|
path: D:\basic\nginx-1.24.0
|
Loading…
Reference in New Issue