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.ActionListener;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -30,6 +31,16 @@ public abstract class ProcessAppTemplate implements MiniApp, ActionListener {
|
|||
*/
|
||||
public abstract String getCmdStr();
|
||||
|
||||
/**
|
||||
* 路径位置
|
||||
*
|
||||
* 默认null
|
||||
* @return 执行命令所在路径
|
||||
*/
|
||||
public String getRunPath() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JPanel getPanel() {
|
||||
JPanel panel = new JPanel();
|
||||
|
@ -96,7 +107,17 @@ public abstract class ProcessAppTemplate implements MiniApp, ActionListener {
|
|||
return;
|
||||
}
|
||||
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("启动成功!");
|
||||
heartbeatCheck();
|
||||
String tmp;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<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>
|
||||
</module>
|
|
@ -20,6 +20,13 @@
|
|||
<groupId>top.dreamcenter.bkpg</groupId>
|
||||
<artifactId>BKPG_PROTOCAL</artifactId>
|
||||
<version>${revision}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>1.30</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -27,10 +34,23 @@
|
|||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
<outputDirectory>${project.parent.basedir}/ext</outputDirectory>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
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.MiniAppGroup;
|
||||
import top.dreamcenter.bkpg.protocal.template.ProcessAppTemplate;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -14,36 +15,65 @@ public class ProcessGroupApp implements MiniAppGroup {
|
|||
@Override
|
||||
public List<MiniApp> getMiniApps() {
|
||||
|
||||
ProcessConfigBean processConfig = null;
|
||||
List<MiniApp> list = new LinkedList<>();
|
||||
try {
|
||||
processConfig = YamlUtil.getProcessConfig("ext/ProgressGroup.yml");
|
||||
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("ext/ProgressGroup.txt")))) {
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String[] split = line.split(": ");
|
||||
|
||||
String appName = split[0];
|
||||
String appCmd = split[1];
|
||||
|
||||
// 从配置装载命令
|
||||
for (ProcessConfigBean.ProcessBean bean : processConfig.getProcessBeanList()){
|
||||
MiniApp miniApp = new ProcessAppTemplate() {
|
||||
@Override
|
||||
public String getCmdStr() {
|
||||
return appCmd;
|
||||
return bean.getCmd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return appName;
|
||||
return bean.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRunPath() {
|
||||
return bean.getPath();
|
||||
}
|
||||
};
|
||||
|
||||
list.add(miniApp);
|
||||
}
|
||||
|
||||
} catch (Exception e){
|
||||
System.err.println(e.getMessage());
|
||||
return list;
|
||||
} catch (Exception e) {
|
||||
// 异常则显示异常面板
|
||||
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;
|
||||
|
|
|
@ -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
|
||||
- String getName(); // 获取应用名称
|
||||
- String getCmdStr(); // 需要执行的命令
|
||||
- String getRunPath(); // 默认实现返回null,表示指令执行目录环境
|
||||
- 其余基类函数已默认实现
|
||||
|
||||
|
||||
|
@ -87,13 +88,25 @@ protect() 是保护函数,如果返回true,则表示在BKPG进行RELOAD时
|
|||
用于执行命令行指令,需要实现两个接口,一个是getName,作用同上,另外一个是该抽象类
|
||||
独有的,getCmdStr,需要设置命令行的完整执行指令。当点击面板的执行按钮时,
|
||||
会启动一个线程来执行该命令,并且每5s会检测一次命令心跳,如果心跳失去连接,
|
||||
则会释放资源。可以作为一些应用或者服务的启动端。
|
||||
则会释放资源。
|
||||
如果说有的指令需要在特定目录下执行,可以覆盖getRunPath,来指定运行环境。
|
||||
可以作为一些应用或者服务的启动端。
|
||||
|
||||
|
||||
为了更加高效的添加命令(常用),
|
||||
官方内置了一个命令AppGroup: **PLUGIN_BKPG_GROUP_PROCESS** 。
|
||||
通过配置ext/ProgressGroup.txt来添加指令应用,
|
||||
指令名称和指令用英文冒号和一个空格隔开【: 】,会自动创建多组ProcessAppTemplate。
|
||||
通过配置ext/ProgressGroup.yml来添加指令应用,
|
||||
会自动创建多组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