diff --git "a/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/README.md" "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/README.md" new file mode 100644 index 0000000000000000000000000000000000000000..8e4480a8f0eed9d008b1f4ab19de7c07f5fc29b3 --- /dev/null +++ "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/README.md" @@ -0,0 +1,53 @@ +# 一、需求概况 +现有某云主机服务器,用来做项目演示用,上面运行了docker应用,现希望有一总览页面,用来展示部署的应用。 +# 二、业务流程 + +```mermaid +graph LR +A(获取docker信息)--> B(模板生成页面)--> C(挂载到nginx) + +``` +/usr/share/nginx/html/index.html + +任务调度采用`crontab` + +演示地址:[http://124.71.129.204](http://124.71.129.204/) + + + + + + +# 三、Java工程打包 + +## 1. 一体化可执行包 + +配置文件:pom-deps.xml + +## 2. 带外部依赖lib的可执行包 + +配置文件:pom-lib.xml + + +## 3. 执行命令 +```shell +#完整打包 +mvn clean package + +#一体化可执行包 +mvn clean package -f pom-deps.xml + +#带外部依赖lib的可执行包 +mvn clean package -f pom-lib.xml +``` + +# 四、部署步骤 + +将`docker-show-jar-with-dependencies.jar`拷贝到服务器位置 `/work/gitcode/docker-run` + +输入`crontab -e`添加如下内容,实现每30分钟执行一次生成页面,并复制到nginx首页位置`/usr/share/nginx/html/index.html` + +```bash +*/10 * * * * java -jar /work/gitcode/docker-run/docker-show-jar-with-dependencies.jar --server.net.ip=124.71.129.204 +``` +这边的124.71.129.204为服务器ip。 \ No newline at end of file diff --git "a/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/pom-deps.xml" "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/pom-deps.xml" new file mode 100644 index 0000000000000000000000000000000000000000..dcb862c252131bc6deecb486de4c60c8940d590d --- /dev/null +++ "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/pom-deps.xml" @@ -0,0 +1,82 @@ + + + 4.0.0 + com.fly + docker-show + 0.0.1 + java-depend + http://maven.apache.org + jar + + + UTF-8 + UTF-8 + 1.8 + + + + org.freemarker + freemarker + 2.3.32 + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.12.1 + + + org.apache.commons + commons-lang3 + 3.5 + + + org.projectlombok + lombok + 1.18.12 + provided + + + + ${project.artifactId} + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + + maven-assembly-plugin + 3.5.0 + + false + + + com.fly.simple.TemplateRun + + + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + diff --git "a/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/pom-lib.xml" "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/pom-lib.xml" new file mode 100644 index 0000000000000000000000000000000000000000..4feb584c26eff66da86f22b66031b2007a78e3f5 --- /dev/null +++ "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/pom-lib.xml" @@ -0,0 +1,96 @@ + + + 4.0.0 + com.fly + docker-show + 0.0.1 + java-depend + http://maven.apache.org + jar + + + UTF-8 + UTF-8 + 1.8 + + + + org.freemarker + freemarker + 2.3.32 + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.12.1 + + + org.apache.commons + commons-lang3 + 3.5 + + + org.projectlombok + lombok + 1.18.12 + provided + + + + ${project.artifactId} + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.1.2 + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/lib + lombok + runtime + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.2.0 + + + + true + lib + com.fly.simple.MainRun + + + ./ + + + + + + + diff --git "a/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/pom.xml" "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/pom.xml" new file mode 100644 index 0000000000000000000000000000000000000000..65da68604a382413c3ec8c1f346206f99e7be262 --- /dev/null +++ "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/pom.xml" @@ -0,0 +1,124 @@ + + + 4.0.0 + com.fly + docker-show + 0.0.1 + java-depend + http://maven.apache.org + jar + + + UTF-8 + UTF-8 + 1.8 + + + + org.freemarker + freemarker + 2.3.32 + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.12.1 + + + org.apache.commons + commons-lang3 + 3.5 + + + org.projectlombok + lombok + 1.18.12 + provided + + + + ${project.artifactId} + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + + maven-assembly-plugin + 3.5.0 + + true + + + com.fly.simple.TemplateRun + + + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.1.2 + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/lib + lombok + runtime + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.2.0 + + + + true + lib + com.fly.simple.MainRun + + + ./ + + + + + + + diff --git "a/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/java/com/fly/simple/MainRun.java" "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/java/com/fly/simple/MainRun.java" new file mode 100644 index 0000000000000000000000000000000000000000..f22cf2755506ad563aba8cf5eb8c23ee5180e791 --- /dev/null +++ "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/java/com/fly/simple/MainRun.java" @@ -0,0 +1,35 @@ +package com.fly.simple; + +import java.io.IOException; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import com.fly.simple.utils.ShellExecutor; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class MainRun +{ + static ScheduledExecutorService service = new ScheduledThreadPoolExecutor(1); + + /** + * 线程池保证程序一直运行 + * + * @param args + */ + public static void main(String[] args) + { + service.scheduleAtFixedRate(() -> { + try + { + log.info("######## {}", ShellExecutor.getDockerInfo()); + } + catch (IOException e) + { + log.error(e.getMessage(), e); + } + }, 2, 10, TimeUnit.SECONDS); + } +} diff --git "a/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/java/com/fly/simple/TemplateRun.java" "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/java/com/fly/simple/TemplateRun.java" new file mode 100644 index 0000000000000000000000000000000000000000..34839fc0afce552c9930b685ba9409015ca2945c --- /dev/null +++ "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/java/com/fly/simple/TemplateRun.java" @@ -0,0 +1,83 @@ +package com.fly.simple; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.net.URL; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.SystemUtils; + +import com.fly.simple.utils.FreeMarkerUtil; +import com.fly.simple.utils.ShellExecutor; + +import freemarker.template.TemplateException; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class TemplateRun +{ + public static void main(String[] args) + throws IOException, TemplateException, InterruptedException + { + // Jar运行,必须提供参数server.net.ip + URL url = TemplateRun.class.getProtectionDomain().getCodeSource().getLocation(); + String ip = null; + if (url.getPath().endsWith(".jar")) + { + if (args.length > 0) + { + ip = Stream.of(args).filter(arg -> arg.contains("--server.net.ip")).map(arg -> StringUtils.substringAfter(arg, "=")).collect(Collectors.joining()); + log.info("JarPath: {}, ServerIp: {}", url.getPath(), ip); + } + if (StringUtils.isBlank(ip)) + { + log.error("please start jar like:\n java -jar docker-show-jar-with-dependencies.jar --server.net.ip=124.71.129.204"); + return; + } + } + + // 写入文件 + if (SystemUtils.IS_OS_WINDOWS) + { + File file = new File("index.html"); + creatPage(ip, file); + + // 打开页面10秒后删除文件 + Runtime.getRuntime().exec("cmd /c start /min " + file.getCanonicalPath()); + TimeUnit.SECONDS.sleep(10); + file.deleteOnExit(); + return; + } + if (SystemUtils.IS_OS_LINUX) + { + // crontab -e + // */30 * * * * java -jar /work/gitcode/docker-run/docker-show-jar-with-dependencies.jar --server.net.ip=124.71.129.204 + creatPage(ip, new File("/usr/share/nginx/html/index.html")); + } + } + + private static void creatPage(String ip, File file) + throws IOException, TemplateException + { + // 收集docker信息 + Map model = new HashMap<>(3); + model.put("date", new Date()); + model.put("map", ShellExecutor.getDockerInfo()); + model.put("ip", StringUtils.defaultIfBlank(ip, "127.0.0.1")); + + // {mysql5=[3306, 13306], mysql8=[23306], redis-server=[6379]} + String content = FreeMarkerUtil.renderTemplate("/templates/index.html.ftl", model); + try (FileWriter writer = new FileWriter(file)) + { + writer.write(content); + writer.flush(); + } + } +} diff --git "a/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/java/com/fly/simple/utils/FreeMarkerUtil.java" "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/java/com/fly/simple/utils/FreeMarkerUtil.java" new file mode 100644 index 0000000000000000000000000000000000000000..540f36fd5364682e487df3e2dea8adc9f3384cc4 --- /dev/null +++ "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/java/com/fly/simple/utils/FreeMarkerUtil.java" @@ -0,0 +1,66 @@ +package com.fly.simple.utils; + +import java.io.IOException; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.util.Map; + +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; + +/** + * + * FreeMarkers + * + * @author 00fly + * @version [版本号, 2017-4-4] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +public class FreeMarkerUtil +{ + private static Configuration config; + + static + { + config = new Configuration(Configuration.VERSION_2_3_32); + config.setDefaultEncoding(StandardCharsets.UTF_8.name()); + } + + /** + * 获取模板填充model解析后的内容 + * + * @param template + * @param model + * @return + * @throws IOException + * @throws TemplateException + * @see [类、类#方法、类#成员] + */ + private static String renderTemplate(Template template, Map model) + throws TemplateException, IOException + { + StringWriter result = new StringWriter(); + template.process(model, result); + return result.toString(); + } + + /** + * 获取模板填充model后的内容 + * + * @param templatePath + * @param model + * @return + * @throws IOException + * @throws TemplateException + * @see [类、类#方法、类#成员] + */ + public static String renderTemplate(String templatePath, Map model) + throws TemplateException, IOException + { + config.setClassForTemplateLoading(FreeMarkerUtil.class, "/"); + Template template = config.getTemplate(templatePath); + return renderTemplate(template, model); + } +} \ No newline at end of file diff --git "a/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/java/com/fly/simple/utils/ShellExecutor.java" "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/java/com/fly/simple/utils/ShellExecutor.java" new file mode 100644 index 0000000000000000000000000000000000000000..47742661f39285cc842c8d0514e1616525d76353 --- /dev/null +++ "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/java/com/fly/simple/utils/ShellExecutor.java" @@ -0,0 +1,60 @@ +package com.fly.simple.utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.SystemUtils; + +public class ShellExecutor +{ + /** + * execute命令 + * + * @param command + * @throws IOException + * @see [类、类#方法、类#成员] + */ + public static List execute(String command) + throws IOException + { + List resultList = new ArrayList<>(); + String[] cmd = SystemUtils.IS_OS_WINDOWS ? new String[] {"cmd", "/c", command} : new String[] {"/bin/sh", "-c", command}; + Process ps = Runtime.getRuntime().exec(cmd); + try (InputStream in = ps.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in))) + { + String line; + while ((line = br.readLine()) != null) + { + resultList.add(line); + } + } + return resultList; + } + + public static Map> getDockerInfo() + throws IOException + { + // ribbon-user-1 8081/tcp + // ribbon-movie 8082/tcp + // ribbon-gateway 0.0.0.0:8085->8080/tcp, :::8085->8080/tcp + String dockerCmd = "docker ps --format \"{{.Names}} {{.Ports}}\""; + Map> map = new TreeMap<>(); + execute(dockerCmd).stream() + .filter(line -> StringUtils.contains(line, "->"))// 保留带端口映射的应用 + .map(line -> Collections.singletonMap(StringUtils.substringBefore(line, " "), + Stream.of(StringUtils.substringAfter(line, " ").split(",")).map(p -> StringUtils.substringBetween(p, ":", "->")).filter(StringUtils::isNotBlank).map(p -> p.replace(":", "")).sorted().collect(Collectors.toSet()))) + .forEach(it -> map.putAll(it)); + return map; + } +} diff --git "a/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/resources/log4j2.xml" "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/resources/log4j2.xml" new file mode 100644 index 0000000000000000000000000000000000000000..0bb64bdebd9b53baff26563c2e2d6b5610ac701c --- /dev/null +++ "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/resources/log4j2.xml" @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git "a/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/resources/templates/index.html.ftl" "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/resources/templates/index.html.ftl" new file mode 100644 index 0000000000000000000000000000000000000000..9beeabd2f1976e75db7aedde82368f61fcdedec6 --- /dev/null +++ "b/\346\234\215\345\212\241\345\231\250docker Web\345\272\224\347\224\250\344\270\200\350\247\210/src/main/resources/templates/index.html.ftl" @@ -0,0 +1,73 @@ + + + + + + +Welcome to nginx! + + + + + No. + Application + Ports + + <#list map?keys as key> + + ${key_index+1} + ${key} + + <#list map[key] as port> + ${port} + #list> + + + #list> + + 更新时间:${date?string('yyyy-MM-dd HH:mm:ss')} + + + + \ No newline at end of file diff --git "a/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/.gitignore" "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/.gitignore" new file mode 100644 index 0000000000000000000000000000000000000000..9ac53673cbfcb8ac953665716cb63a60804df2de --- /dev/null +++ "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/.gitignore" @@ -0,0 +1,7 @@ +target/ +logs/ +.classpath +.project +.settings +.factorypath +upload/ \ No newline at end of file diff --git "a/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/README.md" "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/README.md" new file mode 100644 index 0000000000000000000000000000000000000000..9ac034260397657674683070a54aaec8146c428e --- /dev/null +++ "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/README.md" @@ -0,0 +1,31 @@ +# 神奇代码恢复工具 + + +## 一、完整版神奇代码备份恢复 + +**ProCodeToolSJ 使用swt+jface技术实现** + +下载:[完整版神奇代码备份恢复工具](https://00fly.online/upload/procode-0.0.1.jar) + + + + + + +## 二、神奇代码恢复工具 + +**ProCodeToolSimple 使用swing技术实现** + +下载:[神奇代码恢复工具](https://00fly.online/upload/procode-simple-0.0.1.jar) + + + +在输入框里面输入待恢复的代码,点击"开始恢复代码" 便生成原始项目结构的代码。 + + + +# 三、使用总结 +1. 下载jar +2. 拷贝代码 +3. 粘帖代码 +4. 一键恢复 \ No newline at end of file diff --git "a/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/images/all-1.png" "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/images/all-1.png" new file mode 100644 index 0000000000000000000000000000000000000000..9fc1565fdd8af490d5e9d3291c1714199916259f Binary files /dev/null and "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/images/all-1.png" differ diff --git "a/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/images/all-2.png" "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/images/all-2.png" new file mode 100644 index 0000000000000000000000000000000000000000..f837c5d3aee934a59db4306b31cf585038c8e121 Binary files /dev/null and "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/images/all-2.png" differ diff --git "a/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/images/simple-1.png" "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/images/simple-1.png" new file mode 100644 index 0000000000000000000000000000000000000000..9cc0d0d6452c513372758da0e508a8dd8cb9409c Binary files /dev/null and "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/images/simple-1.png" differ diff --git "a/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/images/simple-2.png" "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/images/simple-2.png" new file mode 100644 index 0000000000000000000000000000000000000000..b9614bda35dec477c6e2dc665a95c5af370ecb79 Binary files /dev/null and "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/images/simple-2.png" differ diff --git "a/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/pom-simple.xml" "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/pom-simple.xml" new file mode 100644 index 0000000000000000000000000000000000000000..659c667f86fd3d775ea3b0193dc5ad8851637f9f --- /dev/null +++ "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/pom-simple.xml" @@ -0,0 +1,92 @@ + + 4.0.0 + com.fly + procode-simple + 0.0.1 + jar + procode + http://maven.apache.org + + 1.8 + UTF-8 + + + + + org.eclipse.platform + org.eclipse.swt.win32.win32.x86_64 + 3.112.0 + + + org.eclipse.platform + org.eclipse.swt.gtk.linux.aarch64 + + + org.eclipse.platform + org.eclipse.swt.gtk.linux.arm + + + + + + org.eclipse.platform + org.eclipse.jface + 3.17.0 + + + org.eclipse.platform + org.eclipse.swt + + + + + org.eclipse.platform + org.eclipse.equinox.common + 3.11.0 + + + org.eclipse.platform + org.eclipse.core.commands + 3.9.800 + + + + + + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + maven-assembly-plugin + 3.5.0 + + false + + + com.fly.procode.ui.ProCodeToolSimple + + + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + \ No newline at end of file diff --git "a/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/pom.xml" "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/pom.xml" new file mode 100644 index 0000000000000000000000000000000000000000..62cd90e164ef895effaee9d3c341a9794387371c --- /dev/null +++ "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/pom.xml" @@ -0,0 +1,92 @@ + + 4.0.0 + com.fly + procode + 0.0.1 + jar + procode + http://maven.apache.org + + 1.8 + UTF-8 + + + + + org.eclipse.platform + org.eclipse.swt.win32.win32.x86_64 + 3.112.0 + + + org.eclipse.platform + org.eclipse.swt.gtk.linux.aarch64 + + + org.eclipse.platform + org.eclipse.swt.gtk.linux.arm + + + + + + org.eclipse.platform + org.eclipse.jface + 3.17.0 + + + org.eclipse.platform + org.eclipse.swt + + + + + org.eclipse.platform + org.eclipse.equinox.common + 3.11.0 + + + org.eclipse.platform + org.eclipse.core.commands + 3.9.800 + + + + + + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + maven-assembly-plugin + 3.5.0 + + false + + + com.fly.procode.ui.ProCodeToolSJ + + + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + diff --git "a/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/java/com/fly/procode/core/DateUtil.java" "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/java/com/fly/procode/core/DateUtil.java" new file mode 100644 index 0000000000000000000000000000000000000000..bd55040c61312afa4c4763fd674544671a0bbdfe --- /dev/null +++ "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/java/com/fly/procode/core/DateUtil.java" @@ -0,0 +1,19 @@ +package com.fly.procode.core; + +import java.text.SimpleDateFormat; + +public class DateUtil +{ + public final static String MMDDHHMM = "_MMddHHmm"; + + public static final String getCurrDateTimeStr(String formatStr) + { + SimpleDateFormat sdf = new SimpleDateFormat(formatStr); + return sdf.format(System.currentTimeMillis()); + } + + public static final String getCurrDateTimeStr() + { + return getCurrDateTimeStr(MMDDHHMM); + } +} diff --git "a/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/java/com/fly/procode/core/Service.java" "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/java/com/fly/procode/core/Service.java" new file mode 100644 index 0000000000000000000000000000000000000000..13ee0d33c1680b4561c7de7b1ddec1dd838703af --- /dev/null +++ "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/java/com/fly/procode/core/Service.java" @@ -0,0 +1,235 @@ +package com.fly.procode.core; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.Observable; + +import com.fly.procode.process.RunProgress; + +/** + * 核心业务逻辑类 + */ +public class Service extends Observable +{ + // 项目源代码目录 + private String sourcePath; + + private RunProgress runProcess; + + // 构造函数 + public Service() + { + super(); + } + + public RunProgress getRunProcess() + { + return runProcess; + } + + public void setRunProcess(RunProgress runProcess) + { + this.runProcess = runProcess; + } + + public String getSourcePath() + { + return sourcePath; + } + + public void setSourcePath(String sourcePath) + { + this.sourcePath = sourcePath; + } + + // 创建备份文件 + public void createBakFile(String bootPath, String bakFileName, List fileFilter, String pwdtext) + { + // InputStream,OutputStream 并不负责文件创建或删除 + // 这部分功能由File来实现 + File bakfile = new File(bakFileName); + if (bakfile.exists()) + { + bakfile.delete(); + } + if (!"".equals(pwdtext)) + { + // new FileOutputStream(File file,boolean append) + try (OutputStream fos = new FileOutputStream(bakFileName, false); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos, "ISO-8859-1"))) + { + writer.write("It is a encrypt backup File"); + writer.newLine(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + // 备份文件 + bakFile(bootPath, bakFileName, fileFilter, pwdtext); + } + + // 递归备份文件 + private void bakFile(String bootPath, String bakFileName, List fileFilter, String pwdtext) + { + File file = new File(sourcePath); + if (file.exists() && file.isDirectory() && !file.getName().startsWith(".")) + { + File[] files = file.listFiles(); + for (int i = 0; i < files.length; i++) + { + File f1 = files[i]; + if (f1.isDirectory()) + { + Service p = new Service(); + p.setRunProcess(runProcess); + p.addObserver(runProcess); + p.setSourcePath(f1.getPath()); + p.bakFile(bootPath, bakFileName, fileFilter, pwdtext); + } + else if (f1.isFile()) + { + if (f1.getPath().contains("\\target\\")) + { + return; + } + if (isExtraFile(f1.getName(), fileFilter)) + { + setChanged(); + notifyObservers("开始处理文件: " + f1.getName()); + List list = new ArrayList(); + String text = "//goto " + f1.getPath().substring(bootPath.length()); + list.add(text); + list.addAll(getFiletext(f1.getPath())); + writeFile(list, bakFileName, pwdtext); + } + } + } + } + } + + // 以append 方式将text 写入 bakFile + private void writeFile(List list, String bakFileName, String pwdtext) + { + // 设置缓冲区大小为8192 bytes + try (OutputStream os = new FileOutputStream(bakFileName, true); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "ISO-8859-1"), 8192)) + { + for (String text : list) + { + writer.write(text); + writer.newLine(); + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + // 获取文件内容 + private List getFiletext(String filePath) + { + // 设置缓冲区大小为8192 bytes + List list = new ArrayList(); + try (InputStream is = new FileInputStream(filePath); BufferedReader in = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"), 8192)) + { + String text; + while ((text = in.readLine()) != null) + { + list.add(text); + } + return list; + } + catch (IOException e) + { + e.printStackTrace(); + return null; + } + } + + // 是否为需要备份的文件类型 + private boolean isExtraFile(String fileName, List fileFilter) + { + for (String postfix : fileFilter) + { + if (fileName.endsWith(postfix)) + { + return true; + } + } + return false; + } + + // 从备份文件恢复文件至dir + public void createSourceFile(String bakFile, String dir) + { + File f = new File(bakFile); + int beginIndex = bakFile.lastIndexOf(File.separator) + 1; + int endIndex = bakFile.indexOf("_"); + String t; + if (endIndex > 0) + { + t = bakFile.substring(beginIndex, endIndex) + File.separator; + } + else + { + t = bakFile.substring(beginIndex, bakFile.indexOf(".")) + File.separator; + } + dir = dir + t; + List list = getFiletext(f.getPath()); + BufferedWriter writer = null; + for (String text : list) + { + try + { + if (text.trim().startsWith("//goto ")) + { + // close old file + if (writer != null) + { + writer.close(); + } + // creat new file + int pos = text.indexOf("//goto ") + 7; + File file = new File(dir + text.substring(pos).replace("\\", File.separator)); + file.getParentFile().mkdirs(); + OutputStream os = new FileOutputStream(file); + writer = new BufferedWriter(new OutputStreamWriter(os, "8859_1"), 8192); + } + else + { + if (writer != null) + { + writer.write(text); + writer.newLine(); + } + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } + try + { + if (writer != null) + { + writer.close(); + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } +} diff --git "a/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/java/com/fly/procode/process/RunProgress.java" "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/java/com/fly/procode/process/RunProgress.java" new file mode 100644 index 0000000000000000000000000000000000000000..501e9a2e65dd8f40b7f61d9d682fb8132b1f0a92 --- /dev/null +++ "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/java/com/fly/procode/process/RunProgress.java" @@ -0,0 +1,80 @@ +package com.fly.procode.process; + +import java.lang.reflect.InvocationTargetException; +import java.util.List; +import java.util.Observable; +import java.util.Observer; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.operation.IRunnableWithProgress; + +import com.fly.procode.core.Service; + +/** + * + * 创建代码进度条线程 + * + * @author 00fly + * @version [版本号, 2017年5月3日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +public class RunProgress implements IRunnableWithProgress, Observer +{ + private String sourcePath; + + private String bakFileName; + + private List fileFilter; + + private String pwdtext; + + private IProgressMonitor monitor; + + public RunProgress(String bootPath, String bakFileName, List fileFilter, String pwdtext) + { + super(); + this.sourcePath = bootPath; + this.bakFileName = bakFileName; + this.fileFilter = fileFilter; + this.pwdtext = pwdtext; + } + + @Override + public void run(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException + { + // 在当前目录,创建并运行脚本 + try + { + monitor.beginTask("代码备份", IProgressMonitor.UNKNOWN); + monitor.subTask("代码备份中......"); + creatAndRun(sourcePath, bakFileName, fileFilter, pwdtext, monitor); + monitor.done(); + } + catch (Exception e) + { + throw new InvocationTargetException(e.getCause(), e.getMessage()); + } + } + + // 运行代码创建程序 + private void creatAndRun(String sourcePath, String bakFileName, List fileFilter, String pwdtext, IProgressMonitor monitor) + { + this.monitor = monitor; + Service service = new Service(); + service.setRunProcess(this); + service.addObserver(this); + service.setSourcePath(sourcePath); + service.createBakFile(sourcePath, bakFileName, fileFilter, pwdtext); + } + + @Override + public void update(Observable observable, Object msg) + { + if (msg instanceof String) + { + monitor.subTask((String)msg); + } + } +} diff --git "a/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/java/com/fly/procode/ui/ProCodeToolSJ.java" "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/java/com/fly/procode/ui/ProCodeToolSJ.java" new file mode 100644 index 0000000000000000000000000000000000000000..e096ed73c523a913bf1cf7d3c0c96c1edaa328ae --- /dev/null +++ "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/java/com/fly/procode/ui/ProCodeToolSJ.java" @@ -0,0 +1,477 @@ +package com.fly.procode.ui; + +import java.awt.Desktop; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.IntStream; + +import org.eclipse.jface.dialogs.IInputValidator; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.TabItem; +import org.eclipse.swt.widgets.Text; + +import com.fly.procode.core.DateUtil; +import com.fly.procode.core.Service; +import com.fly.procode.process.RunProgress; + +/** + * + * swt jface版本 + * + * @author 00fly + * @version [版本号, 2020年4月24日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +public class ProCodeToolSJ +{ + Display display; + + Shell shell; + + org.eclipse.swt.widgets.List listJava; + + org.eclipse.swt.widgets.List listPage; + + public ProCodeToolSJ() + { + super(); + display = new Display(); + shell = new Shell(display, SWT.MIN | SWT.CLOSE | SWT.ON_TOP); + InputStream is = this.getClass().getResourceAsStream("/image/icon.gif"); + if (is != null) + { + shell.setImage(new Image(display, is)); + } + shell.setText("代码备份恢复工具 V1.1.0"); + shell.setSize(540, 383); + Rectangle screeRec = display.getBounds(); + Rectangle shellRec = shell.getBounds(); + if (shellRec.height > screeRec.height) + { + shellRec.height = screeRec.height; + } + if (shellRec.width > screeRec.width) + { + shellRec.width = screeRec.width; + } + shell.setLocation((screeRec.width - shellRec.width) / 2, (screeRec.height - shellRec.height) / 2); + addMenu(); + setContent(); + shell.open(); + while (!shell.isDisposed()) + { + if (!display.readAndDispatch()) + { + display.sleep(); + } + } + display.dispose(); + } + + // main + public static void main(String[] args) + { + new ProCodeToolSJ(); + } + + // Menu set + private void addMenu() + { + Menu m = new Menu(shell, SWT.BAR); + // create a file menu and add an exit item + MenuItem file = new MenuItem(m, SWT.CASCADE); + file.setText("文件(&F)"); + file.setAccelerator(SWT.CTRL + 'F'); + Menu filemenu = new Menu(shell, SWT.DROP_DOWN); + file.setMenu(filemenu); + MenuItem openMenuItem = new MenuItem(filemenu, SWT.CASCADE); + openMenuItem.setText("最近备份(&O)"); + openMenuItem.setAccelerator(SWT.CTRL + 'O'); + Menu submenu = new Menu(shell, SWT.DROP_DOWN); + openMenuItem.setMenu(submenu); + MenuItem childItem = new MenuItem(submenu, SWT.PUSH); + childItem.setText("Child"); + MenuItem saveMenuItem = new MenuItem(filemenu, SWT.CASCADE); + saveMenuItem.setText("最近恢复(&S)"); + saveMenuItem.setAccelerator(SWT.CTRL + 'S'); + Menu submenu2 = new Menu(shell, SWT.DROP_DOWN); + saveMenuItem.setMenu(submenu2); + MenuItem childItem2 = new MenuItem(submenu2, SWT.PUSH); + childItem2.setText("Child2"); + new MenuItem(filemenu, SWT.SEPARATOR); + MenuItem exitMenuItem = new MenuItem(filemenu, SWT.PUSH); + exitMenuItem.setText("退出(&X)"); + exitMenuItem.setAccelerator(SWT.CTRL + 'X'); + exitMenuItem.addSelectionListener(new SelectionAdapter() + { + @Override + public void widgetSelected(SelectionEvent e) + { + System.exit(0); + } + }); + // create a Help menu and add an about item + MenuItem help = new MenuItem(m, SWT.CASCADE); + help.setText("帮助(&H)"); + help.setAccelerator(SWT.CTRL + 'H'); + Menu helpmenu = new Menu(shell, SWT.DROP_DOWN); + help.setMenu(helpmenu); + MenuItem useMenuItem = new MenuItem(helpmenu, SWT.PUSH); + useMenuItem.setText("使用指南(&U)"); + new MenuItem(helpmenu, SWT.SEPARATOR); + MenuItem aboutMenuItem = new MenuItem(helpmenu, SWT.PUSH); + aboutMenuItem.setText("关于工具(&A)"); + useMenuItem.addSelectionListener(new SelectionAdapter() + { + @Override + public void widgetSelected(SelectionEvent event) + { + MessageDialog.openInformation(shell, + "使用指南", + "请按以下顺序操作:" + "\n 文件备份" + "\n 1. 选择项目源文件的目录。" + "\n 2. 选择需要备份的文件类型。" + "\n 3. 选择备份文件输出目录。" + "\n 4. 导出文件。" + "\n " + "\n 文件恢复 " + "\n 1. 到备份目录下选择备份文件。" + "\n 2. 选择备份文件的恢复目录。" + "\n 3. 恢复文件"); + } + }); + aboutMenuItem.addSelectionListener(new SelectionAdapter() + { + @Override + public void widgetSelected(SelectionEvent event) + { + MessageDialog.openInformation(shell, "关于本工具", "代码备份恢复工具。\n\n00fly 于2010年5月。"); + } + }); + shell.setMenuBar(m); + } + + public void setContent() + { + TabFolder tabFolder = new TabFolder(shell, SWT.NONE); + tabFolder.setBounds(5, 2, 525, 328); + TabItem item = new TabItem(tabFolder, SWT.NONE); + item.setText(" 代码备份 "); + item.setControl(new BakPanlTab(tabFolder, SWT.NONE)); + TabItem item2 = new TabItem(tabFolder, SWT.NONE); + item2.setText(" 代码恢复 "); + item2.setControl(new RestorePanlTab(tabFolder, SWT.NONE)); + } + + // 备份面板 + class BakPanlTab extends Composite + { + Button pwdButton; + + Text tpwd = new Text(this, SWT.NONE); + + public BakPanlTab(Composite c, int style) + { + super(c, style); + Label sourceLabel = new Label(this, SWT.NONE); + sourceLabel.setText("项目源文件目录:"); + sourceLabel.setBounds(20, 10, 100, 18); + final Text tsourcePath = new Text(this, SWT.BORDER); + tsourcePath.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); + tsourcePath.setEditable(false); + tsourcePath.setBounds(120, 10, 300, 20); + Button sourceBrowse = new Button(this, SWT.PUSH); + sourceBrowse.setText("选择"); + sourceBrowse.setBounds(430, 10, 70, 20); + sourceBrowse.addSelectionListener(new SelectionAdapter() + { + @Override + public void widgetSelected(SelectionEvent event) + { + DirectoryDialog dialog = new DirectoryDialog(shell); + dialog.setFilterPath(tsourcePath.getText()); + String fileName = dialog.open(); + if (fileName != null) + { + if (fileName.endsWith("\\")) + { + tsourcePath.setText(fileName); + } + else + { + tsourcePath.setText(fileName + "\\"); + } + // 新源文件目录被选中,清空密码 + tpwd.setText(""); + pwdButton.setEnabled(true); + } + } + }); + Label fileTypeLabel = new Label(this, SWT.NONE); + fileTypeLabel.setText("源文件类型:"); + fileTypeLabel.setBounds(20, 40, 100, 18); + + listJava = new org.eclipse.swt.widgets.List(this, SWT.BORDER | SWT.V_SCROLL | SWT.SIMPLE | SWT.MULTI); + listJava.setBounds(120, 40, 120, 128); + listJava.setToolTipText("选择需要备份的源文件类型,支持多选!"); + String[] fileTypes = {".java", ".xml", ".yml", ".yaml", ".properties", ".sql", "Dockerfile"}; + listJava.setItems(fileTypes); + IntStream.range(0, fileTypes.length).forEach(index -> listJava.select(index)); + + listPage = new org.eclipse.swt.widgets.List(this, SWT.BORDER | SWT.V_SCROLL | SWT.SIMPLE | SWT.MULTI); + listPage.setBounds(280, 40, 120, 128); + listPage.setToolTipText("选择需要备份的源文件类型,支持多选!"); + String[] fileTypes2 = {".htm", ".html", ".json", ".js", ".css", ".vue", ".jsp", ".sh"}; + listPage.setItems(fileTypes2); + IntStream.range(0, fileTypes2.length).forEach(index -> listPage.select(index)); + + Label pwdLabel = new Label(this, SWT.NONE); + pwdLabel.setText("可选项:"); + pwdLabel.setBounds(20, 180, 100, 18); + pwdButton = new Button(this, SWT.PUSH); + pwdButton.setText("设置密码"); + pwdButton.setBounds(120, 180, 100, 20); + pwdButton.setEnabled(false); + pwdButton.addSelectionListener(new SelectionAdapter() + { + @Override + public void widgetSelected(SelectionEvent event) + { + InputDialog dlg = new InputDialog(shell, "带密码备份", "请输入8位密码(包括字母,数字和字符):", "", new LengthValidator()); + if (dlg.open() == Window.OK) + { + tpwd.setText(dlg.getValue()); + MessageDialog.openInformation(shell, "恭喜你", "密码设置成功!"); + } + } + }); + Label bakeLabel = new Label(this, SWT.NONE); + bakeLabel.setText("备份至目录:"); + bakeLabel.setBounds(20, 210, 100, 18); + final Text tbakPath = new Text(this, SWT.BORDER); + tbakPath.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); + tbakPath.setEditable(false); + tbakPath.setText(new File(" ").getAbsolutePath().trim()); + tbakPath.setBounds(120, 210, 300, 20); + Button bakBrowse = new Button(this, SWT.PUSH); + bakBrowse.setText("选择"); + bakBrowse.setBounds(430, 210, 70, 20); + bakBrowse.addSelectionListener(new SelectionAdapter() + { + @Override + public void widgetSelected(SelectionEvent event) + { + DirectoryDialog dialog = new DirectoryDialog(shell); + dialog.setFilterPath(tbakPath.getText()); + String fileName = dialog.open(); + if (fileName != null) + { + if (fileName.endsWith("\\")) + { + tbakPath.setText(fileName); + } + else + { + tbakPath.setText(fileName + "\\"); + } + } + } + }); + Button bakButton = new Button(this, SWT.PUSH); + bakButton.setText("开始备份"); + bakButton.setBounds(220, 250, 100, 40); + bakButton.addSelectionListener(new SelectionAdapter() + { + @Override + public void widgetSelected(SelectionEvent event) + { + if ("".equals(tsourcePath.getText())) + { + MessageDialog.openWarning(shell, "警告", "项目源文件目录不可为空!"); + return; + } + if (listJava.getSelectionCount() + listPage.getSelectionCount() < 1) + { + MessageDialog.openError(shell, "警告", "请选择源文件类型,支持多选!"); + listJava.setFocus(); + return; + } + String sourcePath = tsourcePath.getText(); + String bakFileName = tbakPath.getText() + new File(sourcePath).getName() + DateUtil.getCurrDateTimeStr() + ".bak"; + try + { + List fileTypes = new ArrayList(); + for (String it : listJava.getSelection()) + { + fileTypes.add(it); + } + for (String it : listPage.getSelection()) + { + fileTypes.add(it); + } + String pwdtext = tpwd.getText(); + IRunnableWithProgress runnable = new RunProgress(sourcePath, bakFileName, fileTypes, pwdtext); + new ProgressMonitorDialog(shell).run(true, false, runnable); + String message = "创建明文备份文件 " + bakFileName + " 成功!"; + if (!"".equals(pwdtext)) + { + message = "创建加密备份文件 " + bakFileName + " 成功!"; + } + MessageDialog.openInformation(shell, "提示", message); + } + catch (InvocationTargetException e) + { + MessageDialog.openError(shell, "警告", e.getMessage()); + } + catch (InterruptedException e) + { + MessageDialog.openInformation(shell, "Cancelled", "刷新操作被用户取消!"); + } + catch (RuntimeException e) + { + MessageDialog.openError(shell, "错误", "创建备份文件 " + bakFileName + " 失败!"); + } + if (MessageDialog.openConfirm(shell, "查看备份文件", "处理完成,是否直接查看文件?")) + { + try + { + Desktop.getDesktop().open(new File(bakFileName).getParentFile()); + } + catch (IOException e) + { + } + } + } + }); + } + + // 密码长度验证 + class LengthValidator implements IInputValidator + { + @Override + public String isValid(String newText) + { + int len = newText.length(); + if (len < 8) + { + return "长度少于8位"; + } + if (len > 8) + { + return "长度大于8位"; + } + return null; + } + } + } + + // 恢复面板 + class RestorePanlTab extends Composite + { + public RestorePanlTab(Composite c, int style) + { + super(c, style); + Label bakeLabel = new Label(this, SWT.NONE); + bakeLabel.setText("选择备份文件:"); + bakeLabel.setBounds(20, 30, 100, 18); + final Text tbakPath = new Text(this, SWT.BORDER); + tbakPath.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); + tbakPath.setEditable(false); + tbakPath.setBounds(120, 30, 300, 20); + Button bakBrowse = new Button(this, SWT.PUSH); + bakBrowse.setText("选择"); + bakBrowse.setBounds(430, 30, 70, 20); + bakBrowse.addSelectionListener(new SelectionAdapter() + { + @Override + public void widgetSelected(SelectionEvent event) + { + FileDialog fileDialog = new FileDialog(shell, SWT.OPEN); + fileDialog.setText("选择文件"); + String[] filterExt = {"*.bak"}; + fileDialog.setFilterExtensions(filterExt); + String selected = fileDialog.open(); + if (selected == null) + { + return; + } + tbakPath.setText(selected); + } + }); + Label sourceLabel = new Label(this, SWT.NONE); + sourceLabel.setText("恢复至目录:"); + sourceLabel.setBounds(20, 100, 100, 18); + final Text tsourcePath = new Text(this, SWT.BORDER); + tsourcePath.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); + tsourcePath.setEditable(false); + tsourcePath.setText(new File(" ").getAbsolutePath().trim()); + tsourcePath.setBounds(120, 100, 300, 20); + Button sourceBrowse = new Button(this, SWT.PUSH); + sourceBrowse.setText("选择"); + sourceBrowse.setBounds(430, 100, 70, 20); + sourceBrowse.addSelectionListener(new SelectionAdapter() + { + @Override + public void widgetSelected(SelectionEvent event) + { + DirectoryDialog dialog = new DirectoryDialog(shell); + dialog.setFilterPath(tsourcePath.getText()); + String fileName = dialog.open(); + if (fileName != null) + { + if (fileName.endsWith("\\")) + { + tsourcePath.setText(fileName); + } + else + { + tsourcePath.setText(fileName + "\\"); + } + } + } + }); + Button resetButton = new Button(this, SWT.PUSH); + resetButton.setText("开始恢复"); + resetButton.setBounds(220, 170, 100, 40); + resetButton.addSelectionListener(new SelectionAdapter() + { + @Override + public void widgetSelected(SelectionEvent event) + { + if ("".equals(tbakPath.getText()) || "".equals(tsourcePath.getText())) + { + MessageDialog.openWarning(shell, "警告", "备份文件或恢复目录不可为空!"); + } + else + { + String dir = tsourcePath.getText(); + try + { + new Service().createSourceFile(tbakPath.getText(), dir); + MessageDialog.openInformation(shell, "提示", "恢复文件到目录: " + dir + " 成功!"); + } + catch (RuntimeException e) + { + MessageDialog.openError(shell, "错误", "恢复文件失败,请重新检查备份文件!"); + } + } + } + }); + } + } +} diff --git "a/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/java/com/fly/procode/ui/ProCodeToolSimple.java" "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/java/com/fly/procode/ui/ProCodeToolSimple.java" new file mode 100644 index 0000000000000000000000000000000000000000..243b29c9614af26f388ced4258f9f6469f7c1b5b --- /dev/null +++ "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/java/com/fly/procode/ui/ProCodeToolSimple.java" @@ -0,0 +1,165 @@ +package com.fly.procode.ui; + +import java.awt.BorderLayout; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.URL; +import java.nio.charset.StandardCharsets; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; + +/** + * + * 工具UI简化版本,Swing技术实现 + * + * @author 00fly + * @version [版本号, 2023年3月3日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +public class ProCodeToolSimple extends JFrame +{ + private static final long serialVersionUID = -2145267777297657212L; + + JFrame frame = this; + + public ProCodeToolSimple() + { + initComponent(); + this.setVisible(true); + this.setResizable(true); + this.setAlwaysOnTop(true); + this.setTitle("代码恢复工具 V1.0"); + this.setBounds(400, 200, 1200, 550); + this.setDefaultCloseOperation(EXIT_ON_CLOSE); + try + { + // 设定用户界面的外观 + UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); + SwingUtilities.updateComponentTreeUI(this); + } + catch (Exception e) + { + } + } + + /** + * 组件初始化 + * + * @see [类、类#方法、类#成员] + */ + private void initComponent() + { + // 加载图标 + URL url = getClass().getResource("/image/icon.gif"); + if (url != null) + { + this.setIconImage(getToolkit().createImage(url)); + } + + JTextArea textArea = new JTextArea(); + textArea.setToolTipText("请输入全部待恢复代码"); + + // JTextArea不自带滚动条,因此就需要把文本区放到一个滚动窗格中 + JScrollPane scroll = new JScrollPane(textArea); + scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); + + JButton button = new JButton("开始恢复代码"); + this.add(scroll, BorderLayout.CENTER); + this.add(button, BorderLayout.SOUTH); + button.addMouseListener(new MouseAdapter() + { + @Override + public void mouseClicked(MouseEvent event) + { + try + { + String dir = new File("" + System.currentTimeMillis()).getCanonicalPath() + File.separator; + createSourceFile(textArea.getText(), dir); + JOptionPane.showMessageDialog(frame, "恢复文件到目录: " + dir + " 成功!", "提示", JOptionPane.INFORMATION_MESSAGE); + } + catch (Exception e) + { + JOptionPane.showMessageDialog(frame, e.getMessage(), "系統异常", JOptionPane.ERROR_MESSAGE); + } + } + }); + } + + /** + * 恢复文件至dir + * + * @param text + * @param dir + */ + private void createSourceFile(String text, String dir) + { + if (text == null || text.trim().length() == 0) + { + throw new RuntimeException("输入代码不能为空"); + } + String[] textArr = text.split("\n"); + BufferedWriter writer = null; + for (String line : textArr) + { + try + { + if (line.trim().startsWith("//goto ")) + { + // close old file + if (writer != null) + { + writer.close(); + } + // creat new file + int pos = line.indexOf("//goto ") + 7; + File file = new File(dir + line.substring(pos).replace("\\", File.separator)); + file.getParentFile().mkdirs(); + OutputStream os = new FileOutputStream(file); + writer = new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8), 8192); + } + else + { + if (writer != null) + { + writer.write(line); + writer.newLine(); + } + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } + try + { + if (writer != null) + { + writer.close(); + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + public static void main(String[] args) + { + SwingUtilities.invokeLater(() -> new ProCodeToolSimple()); + } +} diff --git "a/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/resources/image/icon.gif" "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/resources/image/icon.gif" new file mode 100644 index 0000000000000000000000000000000000000000..b1a689d7272f228f122f6ac7f3628ecc74516a17 Binary files /dev/null and "b/\347\245\236\345\245\207\344\273\243\347\240\201\346\201\242\345\244\215\345\267\245\345\205\267/src/main/resources/image/icon.gif" differ diff --git "a/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/pom.xml" "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/pom.xml" new file mode 100644 index 0000000000000000000000000000000000000000..7fadd08639fdd5ba8ef1517dff616daa37730509 --- /dev/null +++ "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/pom.xml" @@ -0,0 +1,134 @@ + + + 4.0.0 + com.fly + offline-work + 1.0.0 + jar + + UTF-8 + 1.8 + true + + + + + org.springframework + spring-core + 5.3.18 + + + + com.konghq + unirest-java + 3.14.1 + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.12.1 + + + org.apache.commons + commons-lang3 + 3.5 + + + commons-io + commons-io + 2.5 + + + org.projectlombok + lombok + 1.18.12 + provided + + + junit + junit + 4.12 + test + + + + ${project.artifactId}-${project.version} + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.1.2 + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/lib + lombok + runtime + + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.5.0 + + false + + + com.fly.demo.ui.ImageDispose + + + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + + src/main/java + + **/*.java + + + + src/main/resources + + **/** + + false + + + + diff --git "a/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/ImageDispose.java" "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/ImageDispose.java" new file mode 100644 index 0000000000000000000000000000000000000000..0fa48ce2f5f173d2b12ac21888a40ff798dd9222 --- /dev/null +++ "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/ImageDispose.java" @@ -0,0 +1,58 @@ +package com.fly.demo.ui; + +import java.awt.AWTException; +import java.awt.Robot; +import java.awt.event.KeyEvent; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.lang3.RandomUtils; + +import com.fly.demo.ui.base.ImageDialog; +import com.fly.demo.ui.base.ImageUtils; + +import lombok.extern.slf4j.Slf4j; + +/** + * + * 时隐时现的图片 + * + * @author 00fly + * @version [版本号, 2023年3月3日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +@Slf4j +public class ImageDispose +{ + /** + * 打开图片后延时销毁 + * + */ + private static void openImage() + { + try + { + ImageDialog dialog = new ImageDialog(ImageUtils.getRandomImage()); + + // 移动鼠标 + Robot myRobot = new Robot(); + myRobot.mouseMove(dialog.getX() + RandomUtils.nextInt(0, dialog.getWidth()), dialog.getY() + RandomUtils.nextInt(0, dialog.getHeight())); + + // 模拟按下鼠标左键后释放 + myRobot.mousePress(KeyEvent.BUTTON1_DOWN_MASK); + myRobot.mouseRelease(KeyEvent.BUTTON1_DOWN_MASK); + TimeUnit.SECONDS.sleep(8); + dialog.dispose(); + } + catch (AWTException | InterruptedException e) + { + log.error(e.getMessage(), e); + } + } + + public static void main(String[] args) + { + Executors.newScheduledThreadPool(2).scheduleAtFixedRate(ImageDispose::openImage, 2, 10, TimeUnit.SECONDS); + } +} diff --git "a/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/ImageMove.java" "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/ImageMove.java" new file mode 100644 index 0000000000000000000000000000000000000000..d2126aa86cd0b54ed6b8953433162d2ee7e8feff --- /dev/null +++ "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/ImageMove.java" @@ -0,0 +1,81 @@ +package com.fly.demo.ui; + +import java.awt.AWTException; +import java.awt.Dimension; +import java.awt.Robot; +import java.awt.event.KeyEvent; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import javax.swing.WindowConstants; + +import org.apache.commons.lang3.RandomUtils; + +import com.fly.demo.ui.base.ImageDialog; +import com.fly.demo.ui.base.ImageUtils; + +import lombok.extern.slf4j.Slf4j; + +/** + * + * 不断移动的图片 + * + * @author 00fly + * @version [版本号, 2023年3月3日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +@Slf4j +public class ImageMove +{ + private static ImageDialog dialog; + + private static Robot myRobot; + + static + { + openImage(); + } + + /** + * 打开图片 + * + */ + private static void openImage() + { + try + { + dialog = new ImageDialog(ImageUtils.getRandomImage()); + dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); + myRobot = new Robot(); + } + catch (AWTException e) + { + log.error(e.getMessage(), e); + } + } + + /** + * 位置移动,鼠标移动、点击 + */ + private static void move() + { + Dimension screenSize = dialog.getToolkit().getScreenSize(); + Dimension dialogSize = dialog.getSize(); + dialogSize.height = Math.min(screenSize.height, dialogSize.height); + dialogSize.width = Math.min(screenSize.width, dialogSize.width); + dialog.setLocation(RandomUtils.nextInt(0, screenSize.width - dialogSize.height), RandomUtils.nextInt(0, screenSize.height - dialogSize.width)); + dialog.setVisible(true); // 重新显示 + + // 移动鼠标 + myRobot.mouseMove(dialog.getX() + RandomUtils.nextInt(0, dialog.getWidth()), dialog.getY() + RandomUtils.nextInt(0, dialog.getHeight())); + // 模拟按下鼠标左键后释放 + myRobot.mousePress(KeyEvent.BUTTON1_DOWN_MASK); + myRobot.mouseRelease(KeyEvent.BUTTON1_DOWN_MASK); + } + + public static void main(String[] args) + { + Executors.newScheduledThreadPool(2).scheduleAtFixedRate(ImageMove::move, 2, 10, TimeUnit.SECONDS); + } +} diff --git "a/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/MouseRun.java" "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/MouseRun.java" new file mode 100644 index 0000000000000000000000000000000000000000..55ff6e53e22d89cceef7981f54034363498f1a5f --- /dev/null +++ "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/MouseRun.java" @@ -0,0 +1,57 @@ +package com.fly.demo.ui; + +import java.awt.AWTException; +import java.awt.Dimension; +import java.awt.MouseInfo; +import java.awt.Point; +import java.awt.Robot; +import java.awt.Toolkit; +import java.awt.event.KeyEvent; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.lang3.RandomUtils; + +import lombok.extern.slf4j.Slf4j; + +/** + * 随机游走的鼠标 + */ +@Slf4j +public class MouseRun +{ + private static Robot robot; + + static + { + try + { + robot = new Robot(); + } + catch (AWTException e) + { + log.error(e.getMessage(), e); + } + } + + /** + * 位置移动,鼠标移动、点击 + */ + private static void move() + { + // 模拟按下鼠标左键后释放 + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + robot.mouseMove(RandomUtils.nextInt(0, screenSize.width), RandomUtils.nextInt(0, screenSize.height)); + robot.mousePress(KeyEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(KeyEvent.BUTTON1_DOWN_MASK); + + // 打印坐标 + Point point = MouseInfo.getPointerInfo().getLocation(); + log.info("position: {},{}", point.getX(), point.getY()); + } + + public static void main(String[] args) + { + Executors.newScheduledThreadPool(2).scheduleAtFixedRate(MouseRun::move, 2, 10, TimeUnit.SECONDS); + } +} diff --git "a/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/OpenBrowse.java" "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/OpenBrowse.java" new file mode 100644 index 0000000000000000000000000000000000000000..44f16d8468eea51b7ec4957a2ea354417616554c --- /dev/null +++ "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/OpenBrowse.java" @@ -0,0 +1,83 @@ +package com.fly.demo.ui; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.Charset; +import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.RandomUtils; +import org.apache.commons.lang3.SystemUtils; +import org.springframework.core.io.ClassPathResource; + +import lombok.extern.slf4j.Slf4j; + +/** + * 随机打开网址延时关闭的浏览器 + */ +@Slf4j +public class OpenBrowse +{ + private static List urls; + + /** + * 初始化 + */ + static + { + try (InputStream is = new ClassPathResource("urls").getInputStream()) + { + urls = IOUtils.readLines(is, Charset.defaultCharset()); + } + catch (IOException e) + { + log.error(e.getMessage(), e); + } + } + + /** + * 随机打开网址延时关闭 + */ + public static void openThenClose() + { + if (SystemUtils.IS_OS_WINDOWS) + { + urls.stream().filter(url -> RandomUtils.nextBoolean()).forEach(OpenBrowse::open); + try + { + TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 20)); + Runtime.getRuntime().exec("taskkill /F /IM chrome.exe"); + Runtime.getRuntime().exec("taskkill /F /IM msedge.exe"); + Runtime.getRuntime().exec("taskkill /F /IM iexplorer.exe"); + } + catch (InterruptedException | IOException e) + { + log.error(e.getMessage(), e); + } + } + } + + /** + * 打开网址 + * + * @param url + */ + private static void open(String url) + { + try + { + Runtime.getRuntime().exec("cmd /c start /min " + url); + } + catch (IOException e) + { + log.error(e.getMessage(), e); + } + } + + public static void main(String[] args) + { + Executors.newScheduledThreadPool(2).scheduleAtFixedRate(() -> openThenClose(), 2, 10, TimeUnit.SECONDS); + } +} diff --git "a/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/base/ImageDialog.java" "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/base/ImageDialog.java" new file mode 100644 index 0000000000000000000000000000000000000000..67fe0236bdccd623a5bc02eb61056188abae040e --- /dev/null +++ "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/base/ImageDialog.java" @@ -0,0 +1,46 @@ +package com.fly.demo.ui.base; + +import java.awt.Dimension; +import java.awt.image.BufferedImage; + +import javax.swing.ImageIcon; +import javax.swing.JDialog; +import javax.swing.JLabel; + +import org.apache.commons.lang3.RandomUtils; + +public class ImageDialog extends JDialog +{ + private static final long serialVersionUID = -4922215816711409008L; + + private boolean hidden = true; + + public ImageDialog(BufferedImage image) + { + super(); + if (hidden) // 隐藏标题 + { + setUndecorated(true); + setSize(image.getWidth(), image.getHeight()); + } + else + { + setTitle("图片"); + setSize(image.getWidth(), image.getHeight() + 30); + } + Dimension screenSize = getToolkit().getScreenSize(); + Dimension dialogSize = getSize(); + dialogSize.height = Math.min(screenSize.height, dialogSize.height); + dialogSize.width = Math.min(screenSize.width, dialogSize.width); + + // 居中显示或随机 + // setLocation((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2); + setLocation(RandomUtils.nextInt(0, screenSize.width - dialogSize.height), RandomUtils.nextInt(0, screenSize.height - dialogSize.width)); + add(new JLabel(new ImageIcon(image))); + setVisible(true); + setResizable(false); + setAlwaysOnTop(true); + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + } + +} diff --git "a/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/base/ImageUtils.java" "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/base/ImageUtils.java" new file mode 100644 index 0000000000000000000000000000000000000000..d0c6d62258ef1df483233bd2afeda28ac408ea03 --- /dev/null +++ "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/java/com/fly/demo/ui/base/ImageUtils.java" @@ -0,0 +1,91 @@ +package com.fly.demo.ui.base; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.nio.charset.Charset; +import java.util.List; +import java.util.stream.Collectors; + +import javax.imageio.ImageIO; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.RandomUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.core.io.UrlResource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class ImageUtils +{ + private static Resource[] resources; + + static + { + try + { + resources = getResources(); + log.info("resources.length: {}", resources.length); + } + catch (IOException e) + { + log.error(e.getMessage(), e); + } + } + + /** + * 获取全部图片资源 + * + * @return + * @throws IOException + * @see [类、类#方法、类#成员] + */ + private static Resource[] getResources() + throws IOException + { + try (InputStream is = new ClassPathResource("images/urls.txt").getInputStream()) + { + List urlResources = IOUtils.readLines(is, Charset.defaultCharset()).stream().filter(StringUtils::isNotBlank).map(url -> { + try + { + return new UrlResource(url); + } + catch (MalformedURLException e) + { + log.error(e.getMessage(), e); + return null; + } + }).filter(r -> r != null).collect(Collectors.toList()); + Resource[] jpegs = new PathMatchingResourcePatternResolver().getResources("classpath:images/*.jpeg"); + Resource[] pngs = new PathMatchingResourcePatternResolver().getResources("classpath:images/*.png"); + + // 本地与Url图片资源合并 + return ArrayUtils.addAll(ArrayUtils.addAll(jpegs, pngs), urlResources.toArray(new Resource[0])); + } + } + + /** + * 返回随机图片 + * + * @return + */ + public static BufferedImage getRandomImage() + { + int index = RandomUtils.nextInt(0, resources.length); + try (InputStream is = resources[index].getInputStream()) + { + return ImageIO.read(is); + } + catch (IOException e) + { + log.error(e.getMessage(), e); + return null; + } + } +} \ No newline at end of file diff --git "a/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/resources/images/002.jpeg" "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/resources/images/002.jpeg" new file mode 100644 index 0000000000000000000000000000000000000000..a419123f71147f55ec134fc77c55954f016d6ab3 Binary files /dev/null and "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/resources/images/002.jpeg" differ diff --git "a/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/resources/images/160951.png" "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/resources/images/160951.png" new file mode 100644 index 0000000000000000000000000000000000000000..f66fa45e5ebfe97215b96a032b0c5a017b1f85c1 Binary files /dev/null and "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/resources/images/160951.png" differ diff --git "a/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/resources/images/urls.txt" "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/resources/images/urls.txt" new file mode 100644 index 0000000000000000000000000000000000000000..bc6953c775e25ca6262b8c12a67e11015c88eb72 --- /dev/null +++ "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/resources/images/urls.txt" @@ -0,0 +1,3 @@ +https://00fly.online/upload/2019/02/201902272038150239qlgjm.jpg +https://00fly.online/upload/2019/02/201902262129360274AKuFZcUfip.jpg +https://i-blog.csdnimg.cn/blog_migrate/69bdffecb31079249c66affe553b6f4a.jpeg \ No newline at end of file diff --git "a/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/resources/log4j2.xml" "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/resources/log4j2.xml" new file mode 100644 index 0000000000000000000000000000000000000000..11f0020a5fbd8ca32c18b90f4f221426a3061ade --- /dev/null +++ "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/resources/log4j2.xml" @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git "a/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/resources/urls" "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/resources/urls" new file mode 100644 index 0000000000000000000000000000000000000000..6109d54aa527ab511bfa470ff5ade84be8c9b593 --- /dev/null +++ "b/\360\237\220\237\357\270\217\346\212\200\346\234\257\346\221\270\351\261\274\357\274\210\346\227\266\351\232\220\346\227\266\347\216\260\347\232\204\345\233\276\347\211\207+\344\270\215\346\226\255\347\247\273\345\212\250\347\232\204\345\233\276\347\211\207+\351\232\217\346\234\272\346\270\270\350\265\260\347\232\204\351\274\240\346\240\207+\351\232\217\346\234\272\346\211\223\345\274\200\346\265\217\350\247\210\345\231\250\357\274\211/src/main/resources/urls" @@ -0,0 +1,6 @@ +https://00fly.online/upload/2019/02/201902272038150239qlgjm.jpg +https://00fly.online/upload/2019/02/201902262129360274AKuFZcUfip.jpg +https://i-blog.csdnimg.cn/blog_migrate/69bdffecb31079249c66affe553b6f4a.jpeg +https://www.so.com +https://www.baidu.com +https://gitee.com/00fly/ \ No newline at end of file