diff --git a/.gitignore b/.gitignore index 0ed8b51..199b890 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ build/ ### VS Code ### .vscode/ +/out/artifacts/java_tool_jar/java_tool.jar diff --git a/pom.xml b/pom.xml index 391b2b8..3af1621 100644 --- a/pom.xml +++ b/pom.xml @@ -137,6 +137,12 @@ 2.11.0 + + + org.hyperic + sigar + 1.6.5.132 + diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000..7d6d1a6 --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: com.insigma.utils.OsTest + diff --git a/src/main/java/com/insigma/HyToolApplication.java b/src/main/java/com/insigma/HyToolApplication.java index 0aa76e5..63a9b01 100644 --- a/src/main/java/com/insigma/HyToolApplication.java +++ b/src/main/java/com/insigma/HyToolApplication.java @@ -29,14 +29,7 @@ public class HyToolApplication { SwingUtilities.invokeLater(() -> { log.info("正在启动GUI =======================>>> " + guiType ); - if(SWING2.equals(guiType)){ - SwingSet2.main(args); - }else if(SWING9.equals(guiType)){ - // TODO... - }else { - log.error("启动GUI异常 =======================>>> 请检查GUITYPE是否存在 "); - throw new RuntimeException("GUI类型出错:"+guiType); - } + SwingSet2.main(args); }); } catch (Exception e) { log.error("\n\t 启动GUI异常 >>>>>>>>>>>{},{}",e.getMessage(),e); @@ -46,7 +39,4 @@ public class HyToolApplication { //spring SpringApplication.run(HyToolApplication.class, args); } - - private static final String SWING2 = "SwingSet2GUI"; - private static final String SWING9 = "Swing9patchGUI"; } diff --git a/src/main/java/com/insigma/service/Computer.java b/src/main/java/com/insigma/service/Computer.java index eab9b35..75190c5 100644 --- a/src/main/java/com/insigma/service/Computer.java +++ b/src/main/java/com/insigma/service/Computer.java @@ -1,23 +1,17 @@ package com.insigma.service; -import org.springframework.util.Assert; - /** * (Computer 计算机 接口) * * @author zhangxianwei * @since 2022/4/17 21:07 */ -public interface Computer extends Middleware, Database { +public abstract class Computer { /*** * 执行 脚本程序 * @param shell 执行脚本 * @return */ - default boolean runShell(String shell) { - Assert.notNull(shell, "未检测到要执行脚本!"); - System.out.printf("执行脚本:%s,但是未检测到实现应用调用此方法!%n", shell); - return false; - } + public abstract boolean runShell(String shell); } diff --git a/src/main/java/com/insigma/service/impl/CuWindows.java b/src/main/java/com/insigma/service/impl/CuWindows.java deleted file mode 100644 index a874d33..0000000 --- a/src/main/java/com/insigma/service/impl/CuWindows.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.insigma.service.impl; - -import com.insigma.entry.IndexObj; -import com.insigma.service.Computer; - -import java.util.List; - -/** - * (CuWindows 类) - * - * @author zhangxianwei - * @since 23:30 2022/4/17 - */ -public class CuWindows implements Computer { - - @Override - public boolean rebuildIndex(List index) { - return false; - } - - @Override - public boolean setDbSize(int size) { - System.out.printf("设置出参数:%d,但是未检测到实现应用调用此方法!", size); - return false; - } - - @Override - public boolean cleanDbCache() { - System.out.println("进行缓存清除,但是未检测到实现应用调用此方法!"); - return false; - } -} diff --git a/src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java b/src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java new file mode 100644 index 0000000..15e0c4b --- /dev/null +++ b/src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java @@ -0,0 +1,53 @@ +package com.insigma.service.impl; + +import com.insigma.entry.IndexObj; +import com.insigma.service.Computer; +import com.insigma.service.*; +import com.insigma.utils.WinCommandUtil; + +import java.util.List; + + +/** + * (CuWindows 类) windows + tomcat + mysql + * + * @author zhangxianwei + * @since 23:30 2022/4/17 + */ +public class WindowsTomcatMysql extends Computer implements Database, Middleware { + + @Override + public boolean runShell(String shell) { + try { + new WinCommandUtil(shell).run(); + }catch (Exception ignored){ + return false; + } + return true; + } + + @Override + public boolean rebuildIndex(List index) { + return Database.super.rebuildIndex(index); + } + + @Override + public boolean setDbSize(int size) { + return Database.super.setDbSize(size); + } + + @Override + public boolean cleanDbCache() { + return Database.super.cleanDbCache(); + } + + @Override + public boolean cleanMwCache() { + return Middleware.super.cleanMwCache(); + } + + @Override + public boolean setMwSize(int size) { + return Middleware.super.setMwSize(size); + } +} diff --git a/src/main/java/com/insigma/utils/WinCommandUtil.java b/src/main/java/com/insigma/utils/WinCommandUtil.java new file mode 100644 index 0000000..cdb8584 --- /dev/null +++ b/src/main/java/com/insigma/utils/WinCommandUtil.java @@ -0,0 +1,66 @@ +package com.insigma.utils; + +import lombok.extern.slf4j.Slf4j; +import java.io.*; + +/** + * CommandImpUtil + * + * @author admin + */ +@Slf4j +public class WinCommandUtil implements Runnable { + private String command; + + public WinCommandUtil(String command) { + this.command = command; + } + + @Override + public void run() { + Process process; + int exitVal = 0; + try { + log.debug("准备执行命令:{}",command); + process = Runtime.getRuntime().exec(command); + // Runtime.exec()创建的子进程公用父进程的流,不同平台上,父进程的stream buffer可能被打满导致子进程阻塞,从而永远无法返回。 + //针对这种情况,我们只需要将子进程的stream重定向出来即可。 + new RunCmdStreamThread(process.getInputStream(), "INFO").start(); + new RunCmdStreamThread(process.getErrorStream(), "ERR").start(); + + exitVal = process.waitFor(); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + + if (exitVal != 0) { + log.error("执行命令发生异常:{}", exitVal); + throw new RuntimeException("cmd任务执行失败"); + } + } + + static class RunCmdStreamThread extends Thread { + InputStream is; + String printType; + + RunCmdStreamThread(InputStream is, String printType) { + this.is = is; + this.printType = printType; + } + + @Override + public void run() { + try { + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + String line; + while ((line = br.readLine()) != null) { + log.debug("输出:{}>{}", printType, line); + } + + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 09e66ee..db7609b 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -8,13 +8,8 @@ spring: language: basename: language/swingset -mybatis: - type-aliases-package: classpath:com.wuzf.swing.dao - - logging: - level: - com.wuzf.swing.dao: debug + level: debug file: path: output/log name: D:/ouput/logs/SwingDemoLog.log diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f91daa1..02bd051 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,6 +2,4 @@ #设置激活配置文件 spring.profiles.active=dev -##自定义启动UI 1-swing原生UI 2-beauty美化UI 3-SwingSet3 -swing.ui.type=SwingSet2GUI -swing.ui.testCN=哈哈 +swing.ui.testCN=测试 diff --git a/src/test/java/com/insigma/service/impl/WindowsTomcatMysqlTest.java b/src/test/java/com/insigma/service/impl/WindowsTomcatMysqlTest.java new file mode 100644 index 0000000..e5b8a13 --- /dev/null +++ b/src/test/java/com/insigma/service/impl/WindowsTomcatMysqlTest.java @@ -0,0 +1,11 @@ +package com.insigma.service.impl; + +import org.junit.jupiter.api.Test; + +public class WindowsTomcatMysqlTest { + + @Test + public void runShellTest(){ + + } +} \ No newline at end of file